def _check_and_update_root_device(self, vm_gen, image_meta, block_device_info, slot_map): # either booting from volume, or booting from image/iso root_disk = {} root_device = (driver.block_device_info_get_root(block_device_info) or self._DEFAULT_ROOT_DEVICE) if self.is_boot_from_volume(block_device_info): root_volume = self._get_root_device_bdm(block_device_info, root_device) root_disk['type'] = constants.VOLUME root_disk['path'] = None root_disk['connection_info'] = root_volume['connection_info'] else: root_disk['type'] = self._TYPE_FOR_DISK_FORMAT.get( image_meta['disk_format']) if root_disk['type'] is None: raise exception.InvalidDiskFormat( disk_format=image_meta['disk_format']) root_disk['path'] = None root_disk['connection_info'] = None root_disk['disk_bus'] = (constants.CTRL_TYPE_IDE if vm_gen == constants.VM_GEN_1 else constants.CTRL_TYPE_SCSI) (root_disk['drive_addr'], root_disk['ctrl_disk_addr']) = self._get_available_controller_slot( root_disk['disk_bus'], slot_map) root_disk['boot_index'] = 0 root_disk['mount_device'] = root_device block_device_info['root_disk'] = root_disk
def attach_config_drive(self, instance, configdrive_path): configdrive_ext = configdrive_path[(configdrive_path.rfind('.') + 1):] # Do the attach here and if there is a certain file format that isn't # supported in constants.DISK_FORMAT_MAP then bomb out. try: self._vmutils.attach_ide_drive(instance.name, configdrive_path, 1, 0, constants.DISK_FORMAT_MAP[configdrive_ext]) except KeyError: raise exception.InvalidDiskFormat(disk_format=configdrive_ext)
def create_hd(cls, filename, size=None, disk_format=constants.DISK_FORMAT_VDI, variant=constants.VARIANT_STANDARD, parent=None): """Creates a new virtual hard disk image. :param filename: the file name for the hard disk image :param size: the image capacity, in MiB units :param disk_format: file format for the output file (default: DISK_FORMAT_VDI) :param variant: file format variant for the output file (default: VARIANT_STANDARD) :param parent: :return: UUID for the disk image created """ if disk_format not in constants.ALL_DISK_FORMATS: raise exception.InvalidDiskFormat(disk_format=disk_format) if variant not in constants.ALL_VARIANTS: raise vbox_exc.VBoxValueNotAllowed( argument="variant", value=variant, method=cls.CREATE_HD, allowed_values=constants.ALL_VARIANTS) if size and size < 1: raise exception.InvalidDiskInfo( reason="Disk size should be bigger than 0.") command = [cls.CREATE_HD, "--filename", filename, "--format", disk_format, "--variant", variant] if size: command.extend(["--size", size]) if parent: command.extend(["--diffparent", parent]) output, error = cls._execute(*command) if error and constants.DONE not in error: if constants.VBOX_E_FILE_ERROR in error: raise exception.DestinationDiskExists(path=filename) raise vbox_exc.VBoxManageError(method=cls.CREATE_HD, reason=error) # The ouput should look like: # Disk image created. UUID: 6917a94b-ecb0-4996-8ab8-5e4ef8f9539a for line in output.splitlines(): if "UUID:" not in line: continue hd_uuid = line.split("UUID:")[1].strip() break else: # TODO(alexandrucoman): Fail to get UUID (Something went wrong) return return hd_uuid
def __init__( self, image_id, file_size=0, os_type=constants.DEFAULT_OS_TYPE, adapter_type=constants.DEFAULT_ADAPTER_TYPE, disk_type=constants.DEFAULT_DISK_TYPE, container_format=constants.CONTAINER_FORMAT_BARE, file_type=constants.DEFAULT_DISK_FORMAT, linked_clone=None, # Start Pf9 addition name=None, is_vsphere_template=None, vsphere_template_name=None, vsphere_template_moref=None, # End Pf9 addition vif_model=constants.DEFAULT_VIF_MODEL): """VMwareImage holds values for use in building VMs. image_id (str): uuid of the image file_size (int): size of file in bytes os_type (str): name of guest os (use vSphere names only) adapter_type (str): name of the adapter's type disk_type (str): type of disk in thin, thick, etc container_format (str): container format (bare or ova) file_type (str): vmdk or iso linked_clone (bool): use linked clone, or don't vif_model (str): virtual machine network interface """ self.image_id = image_id self.file_size = file_size self.os_type = os_type self.adapter_type = adapter_type self.container_format = container_format self.disk_type = disk_type self.file_type = file_type # Start Pf9 addition self.name = name self.is_vsphere_template = is_vsphere_template self.vsphere_template_name = vsphere_template_name self.vsphere_template_moref = vsphere_template_moref # End Pf9 addition # NOTE(vui): This should be removed when we restore the # descriptor-based validation. if (self.file_type is not None and self.file_type not in constants.DISK_FORMATS_ALL): raise exception.InvalidDiskFormat(disk_format=self.file_type) if linked_clone is not None: self.linked_clone = linked_clone else: self.linked_clone = CONF.vmware.use_linked_clone self.vif_model = vif_model
def attach_config_drive(self, instance, configdrive_path, vm_gen): configdrive_ext = configdrive_path[(configdrive_path.rfind('.') + 1):] # Do the attach here and if there is a certain file format that isn't # supported in constants.DISK_FORMAT_MAP then bomb out. try: drive_type = constants.DISK_FORMAT_MAP[configdrive_ext] controller_type = VM_GENERATIONS_CONTROLLER_TYPES[vm_gen] self._attach_drive(instance.name, configdrive_path, 1, 0, controller_type, drive_type) except KeyError: raise exception.InvalidDiskFormat(disk_format=configdrive_ext)
def determine_from_glance(): glance_disk_format2nova_type = { 'ami': ImageType.DISK, 'aki': ImageType.KERNEL, 'ari': ImageType.RAMDISK, 'raw': ImageType.DISK_RAW, 'vhd': ImageType.DISK_VHD} image_ref = instance.image_ref glance_client, image_id = nova.image.get_glance_client(image_ref) meta = glance_client.get_image_meta(image_id) disk_format = meta['disk_format'] try: return glance_disk_format2nova_type[disk_format] except KeyError: raise exception.InvalidDiskFormat(disk_format=disk_format)
def __init__(self, image_id, file_size=0, os_type=constants.DEFAULT_OS_TYPE, adapter_type=constants.DEFAULT_ADAPTER_TYPE, disk_type=constants.DEFAULT_DISK_TYPE, file_type=constants.DEFAULT_DISK_FORMAT, linked_clone=None, vif_model=constants.DEFAULT_VIF_MODEL): """VMwareImage holds values for use in building VMs. image_id (str): uuid of the image file_size (int): size of file in bytes os_type (str): name of guest os (use vSphere names only) adapter_type (str): name of the adapter's type disk_type (str): type of disk in thin, thick, etc file_type (str): vmdk or iso linked_clone(bool): use linked clone, or don't """ self.image_id = image_id self.file_size = file_size self.os_type = os_type self.adapter_type = adapter_type self.disk_type = disk_type self.file_type = file_type # NOTE(vui): This should be removed when we restore the # descriptor-based validation. if (self.file_type is not None and self.file_type not in constants.DISK_FORMATS_ALL): raise exception.InvalidDiskFormat(disk_format=self.file_type) if linked_clone is not None: self.linked_clone = linked_clone else: self.linked_clone = CONF.vmware.use_linked_clone self.vif_model = vif_model