def builder_did_create_target_image(self, builder, target, image_id, template, parameters): self.log.info( 'builder_did_create_target_image() called in RHEVM plugin') self.status = "BUILDING" # TODO: This is a convenience variable for refactoring - rename self.new_image_id = builder.target_image.identifier # TODO: More convenience vars - revisit self.template = template self.target = target self.builder = builder # This lets our logging helper know what image is being operated on self.active_image = self.builder.target_image self.tdlobj = oz.TDL.TDL( xmlstring=self.template.xml, rootpw_required=self.app_config["tdl_require_root_pw"]) # Add in target specific content #TODO-URGENT: Work out how to do this in the new framework #self.add_target_content() # Oz assumes unique names - TDL built for multiple backends guarantees # they are not unique. We don't really care about the name so just # force uniqueness # Oz now uses the tdlobject name property directly in several places # so we must change it self.tdlobj.name = "factory-build-" + self.new_image_id # In contrast to our original builders, we enter the cloud plugins with a KVM file already # created as the base_image. As a result, all the Oz building steps are gone (and can be found # in the OS plugin(s) # OS plugin has already provided the initial file for us to work with # which we can currently assume is a raw KVM compatible image self.image = builder.target_image.data # Add the cloud-info file self.modify_oz_filesystem() # Finally, if our format is qcow2, do the transformation here if needed if ("rhevm_image_format" in self.app_config) and (self.app_config["rhevm_image_format"] == "qcow2") \ and not check_qcow_size(self.image): self.log.debug("Converting RAW image to qcow2 format") # TODO: When RHEV adds support, use the -c option to compress these images to save space # (at that point, remove the qcow check as we always want to compress) qemu_img_cmd = qemu_convert_cmd(self.image, self.image + ".tmp.qcow2") (stdout, stderr, retcode) = subprocess_check_output(qemu_img_cmd) os.unlink(self.image) os.rename(self.image + ".tmp.qcow2", self.image) self.percent_complete = 100 self.status = "COMPLETED"
def push_image_to_provider(self, builder, provider, credentials, target, target_image, parameters): # Our target_image is already a raw KVM image. All we need to do is upload to glance self.builder = builder self.active_image = self.builder.provider_image self.openstack_decode_credentials(credentials) provider_data = self.get_dynamic_provider_data(provider) if provider_data is None: raise ImageFactoryException("OpenStack KVM instance not found in XML or JSON provided") # Image is always here and it is the target_image datafile input_image = self.builder.target_image.data # If the template species a name, use that, otherwise create a name # using provider_image.identifier. template = Template(self.builder.provider_image.template) if template.name: image_name = template.name else: image_name = "ImageFactory created image - %s" % (self.builder.provider_image.identifier) if check_qcow_size(input_image): self.log.debug("Uploading image to glance, detected qcow format") disk_format = "qcow2" else: self.log.debug("Uploading image to glance, assuming raw format") disk_format = "raw" # Support openstack grizzly keystone authentication and glance upload if self.version == 2: if self.credentials_token is None: self.credentials_token = self.keystone_authenticate(**self.credentials_dict) provider_data["name"] = image_name provider_data["disk_format"] = disk_format image_id = self.glance_upload_v2(input_image, self.credentials_token, **provider_data) else: # Also support backward compatible for folsom image_id = self.glance_upload( input_image, creds=self.credentials_dict, token=self.credentials_token, host=provider_data["glance-host"], port=provider_data["glance-port"], name=image_name, disk_format=disk_format, ) self.builder.provider_image.identifier_on_provider = image_id if "username" in self.credentials_dict: self.builder.provider_image.provider_account_identifier = self.credentials_dict["username"] self.percent_complete = 100
def builder_did_create_target_image(self, builder, target, image_id, template, parameters): self.log.info('builder_did_create_target_image() called in RHEVM plugin') self.status="BUILDING" # TODO: This is a convenience variable for refactoring - rename self.new_image_id = builder.target_image.identifier # TODO: More convenience vars - revisit self.template = template self.target = target self.builder = builder # This lets our logging helper know what image is being operated on self.active_image = self.builder.target_image self.tdlobj = oz.TDL.TDL(xmlstring=self.template.xml, rootpw_required=self.app_config["tdl_require_root_pw"]) # Add in target specific content #TODO-URGENT: Work out how to do this in the new framework #self.add_target_content() # Oz assumes unique names - TDL built for multiple backends guarantees # they are not unique. We don't really care about the name so just # force uniqueness # Oz now uses the tdlobject name property directly in several places # so we must change it self.tdlobj.name = "factory-build-" + self.new_image_id # In contrast to our original builders, we enter the cloud plugins with a KVM file already # created as the base_image. As a result, all the Oz building steps are gone (and can be found # in the OS plugin(s) # OS plugin has already provided the initial file for us to work with # which we can currently assume is a raw KVM compatible image self.image = builder.target_image.data # Add the cloud-info file self.modify_oz_filesystem() # Finally, if our format is qcow2, do the transformation here if needed if ("rhevm_image_format" in self.app_config) and (self.app_config["rhevm_image_format"] == "qcow2") \ and not check_qcow_size(self.image): self.log.debug("Converting RAW image to qcow2 format") # TODO: When RHEV adds support, use the -c option to compress these images to save space # (at that point, remove the qcow check as we always want to compress) qemu_img_cmd = qemu_convert_cmd( self.image, self.image + ".tmp.qcow2" ) (stdout, stderr, retcode) = subprocess_check_output(qemu_img_cmd) os.unlink(self.image) os.rename(self.image + ".tmp.qcow2", self.image) self.percent_complete=100 self.status="COMPLETED"
def push_image_to_provider(self, builder, provider, credentials, target, target_image, parameters): # Our target_image is already a raw KVM image. All we need to do is upload to glance self.builder = builder self.active_image = self.builder.provider_image self.openstack_decode_credentials(credentials) provider_data = self.get_dynamic_provider_data(provider) if provider_data is None: raise ImageFactoryException("OpenStack KVM instance not found in XML or JSON provided") # Image is always here and it is the target_image datafile input_image = self.builder.target_image.data # If the template species a name, use that, otherwise create a name # using provider_image.identifier. template = Template(self.builder.provider_image.template) if template.name: image_name = template.name else: image_name = 'ImageFactory created image - %s' % (self.builder.provider_image.identifier) if check_qcow_size(input_image): self.log.debug("Uploading image to glance, detected qcow format") disk_format='qcow2' else: self.log.debug("Uploading image to glance, assuming raw format") disk_format='raw' # Support openstack grizzly keystone authentication and glance upload if self.version == 2: if self.credentials_token is None: self.credentials_token = self.keystone_authenticate(**self.credentials_dict) provider_data['name'] = image_name provider_data['disk_format'] = disk_format image_id = self.glance_upload_v2(input_image, self.credentials_token, **provider_data) else: # Also support backward compatible for folsom image_id = self.glance_upload(input_image, creds = self.credentials_dict, token = self.credentials_token, host=provider_data['glance-host'], port=provider_data['glance-port'], name=image_name, disk_format=disk_format) self.builder.provider_image.identifier_on_provider = image_id if 'username' in self.credentials_dict: self.builder.provider_image.provider_account_identifier = self.credentials_dict['username'] self.percent_complete=100
def vmware_transform_image_stream_vmdk(self): if (check_qcow_size(self.image)) is not None: import subprocess self.log.debug("Input image is qcow; converting to raw") raw_output_fname = "{0}.raw".format(self.image) qemucmd = ['qemu-img', 'convert', '-f', 'qcow2', '-O', 'raw', self.image, raw_output_fname] subprocess.check_call(qemucmd) os.unlink(self.image) os.rename(raw_output_fname, self.image) # On entry the image points to our generic KVM raw image # Convert to stream-optimized VMDK and then update the image property target_image = self.image + ".tmp.vmdk" self.log.debug("Converting raw kvm image (%s) to vmware stream-optimized image (%s)" % (self.image, target_image)) convert_to_stream(self.image, target_image) self.log.debug("VMWare stream conversion complete") os.unlink(self.image) os.rename(self.image + ".tmp.vmdk", self.image)