def unplug(self, instance, vif): vif_type = vif['type'] # instance.display_name could be unicode instance_repr = utils.get_obj_repr_unicode(instance) LOG.debug('vif_type=%(vif_type)s instance=%(instance)s ' 'vif=%(vif)s', {'vif_type': vif_type, 'instance': instance_repr, 'vif': vif}) if vif_type is None: msg = _("vif_type parameter must be present for this vif_driver " "implementation") raise exception.InternalError(msg) # Try os-vif codepath first vif_obj = os_vif_util.nova_to_osvif_vif(vif) if vif_obj is not None: self._unplug_os_vif(instance, vif_obj) return # Legacy non-os-vif codepath vif_slug = self._normalize_vif_type(vif_type) func = getattr(self, 'unplug_%s' % vif_slug, None) if not func: msg = _("Unexpected vif_type=%s") % vif_type raise exception.InternalError(msg) func(instance, vif)
def get_config(self, connection_info, disk_info): """Returns xml for libvirt.""" conf = super(LibvirtNetVolumeDriver, self).get_config(connection_info, disk_info) netdisk_properties = connection_info['data'] conf.source_type = "network" conf.source_protocol = connection_info['driver_volume_type'] conf.source_name = netdisk_properties.get('name') conf.source_hosts = netdisk_properties.get('hosts', []) conf.source_ports = netdisk_properties.get('ports', []) if conf.source_protocol == 'rbd': self._set_auth_config_rbd(conf, netdisk_properties) elif conf.source_protocol == 'iscsi': try: conf.source_name = ("%(target_iqn)s/%(target_lun)s" % netdisk_properties) target_portal = netdisk_properties['target_portal'] except KeyError: raise exception.InternalError(_("Invalid volume source data")) ip, port = utils.parse_server_string(target_portal) if ip == '' or port == '': raise exception.InternalError(_("Invalid target_lun")) conf.source_hosts = [ip] conf.source_ports = [port] self._set_auth_config_iscsi(conf, netdisk_properties) return conf
def get_config(self, instance, vif, image_meta, inst_type, virt_type, host): vif_type = vif['type'] vnic_type = vif['vnic_type'] # instance.display_name could be unicode instance_repr = utils.get_obj_repr_unicode(instance) LOG.debug( 'vif_type=%(vif_type)s instance=%(instance)s ' 'vif=%(vif)s virt_type=%(virt_type)s', { 'vif_type': vif_type, 'instance': instance_repr, 'vif': vif, 'virt_type': virt_type }) if vif_type is None: raise exception.InternalError( _("vif_type parameter must be present " "for this vif_driver implementation")) # Try os-vif codepath first vif_obj = os_vif_util.nova_to_osvif_vif(vif) if vif_obj is not None: return self._get_config_os_vif(instance, vif_obj, image_meta, inst_type, virt_type, host, vnic_type) # Legacy non-os-vif codepath vif_slug = self._normalize_vif_type(vif_type) func = getattr(self, 'get_config_%s' % vif_slug, None) if not func: raise exception.InternalError( _("Unexpected vif_type=%s") % vif_type) return func(instance, vif, image_meta, inst_type, virt_type, host)
def get_config(self, instance, vif, image_meta, inst_type, virt_type, host): vif_type = vif['type'] vnic_type = vif['vnic_type'] # instance.display_name could be unicode instance_repr = utils.get_obj_repr_unicode(instance) LOG.debug( 'vif_type=%(vif_type)s instance=%(instance)s ' 'vif=%(vif)s virt_type=%(virt_type)s', { 'vif_type': vif_type, 'instance': instance_repr, 'vif': vif, 'virt_type': virt_type }) if vif_type is None: raise exception.InternalError( _("vif_type parameter must be present " "for this vif_driver implementation")) # Try os-vif codepath first vif_obj = os_vif_util.nova_to_osvif_vif(vif) if vif_obj is not None: return self._get_config_os_vif(instance, vif_obj, image_meta, inst_type, virt_type, host, vnic_type) # Legacy non-os-vif codepath args = (instance, vif, image_meta, inst_type, virt_type, host) if vif_type == network_model.VIF_TYPE_IOVISOR: return self.get_config_iovisor(*args) elif vif_type == network_model.VIF_TYPE_BRIDGE: return self.get_config_bridge(*args) elif vif_type == network_model.VIF_TYPE_802_QBG: return self.get_config_802qbg(*args) elif vif_type == network_model.VIF_TYPE_802_QBH: return self.get_config_802qbh(*args) elif vif_type == network_model.VIF_TYPE_HW_VEB: return self.get_config_hw_veb(*args) elif vif_type == network_model.VIF_TYPE_HOSTDEV: return self.get_config_hostdev_physical(*args) elif vif_type == network_model.VIF_TYPE_MACVTAP: return self.get_config_macvtap(*args) elif vif_type == network_model.VIF_TYPE_MIDONET: return self.get_config_midonet(*args) elif vif_type == network_model.VIF_TYPE_TAP: return self.get_config_tap(*args) elif vif_type == network_model.VIF_TYPE_IB_HOSTDEV: return self.get_config_ib_hostdev(*args) raise exception.InternalError(_('Unexpected vif_type=%s') % vif_type)
def validate_volume(mnt_base): """Wraps execute calls for checking validity of a Quobyte volume""" command = ['getfattr', "-n", "quobyte.info", mnt_base] try: utils.execute(*command) except processutils.ProcessExecutionError as exc: msg = (_("The mount %(mount_path)s is not a valid" " Quobyte volume. Error: %(exc)s") % {'mount_path': mnt_base, 'exc': exc}) raise nova_exception.InternalError(msg) if not os.access(mnt_base, os.W_OK | os.X_OK): msg = (_LE("Volume is not writable. Please broaden the file" " permissions. Mount: %s") % mnt_base) raise nova_exception.InternalError(msg)
def get_info(self, host): """Retrieve information from libvirt for a specific instance name. If a libvirt error is encountered during lookup, we might raise a NotFound exception or Error exception depending on how severe the libvirt error is. :returns hardware.InstanceInfo: """ try: dom_info = self._get_domain_info() except libvirt.libvirtError as ex: error_code = ex.get_error_code() if error_code == libvirt.VIR_ERR_NO_DOMAIN: raise exception.InstanceNotFound(instance_id=self.uuid) msg = (_('Error from libvirt while getting domain info for ' '%(instance_name)s: [Error Code %(error_code)s] %(ex)s') % { 'instance_name': self.name, 'error_code': error_code, 'ex': ex }) raise exception.InternalError(msg) return hardware.InstanceInfo(state=LIBVIRT_POWER_STATE[dom_info[0]], internal_id=self.id)
def _get_config_os_vif(self, instance, vif, image_meta, inst_type, virt_type, host, vnic_type): """Get the domain config for a VIF :param instance: nova.objects.Instance :param vif: os_vif.objects.vif.VIFBase subclass :param image_meta: nova.objects.ImageMeta :param inst_type: nova.objects.Flavor :param virt_type: virtualization type :param host: nova.virt.libvirt.host.Host :param vnic_type: vnic type :returns: nova.virt.libvirt.config.LibvirtConfigGuestInterface """ # Do the config that's common to all vif types conf = self.get_base_config(instance, vif.address, image_meta, inst_type, virt_type, vnic_type) # Do the VIF type specific config viffunc = "_set_config_" + vif.obj_name() func = getattr(self, viffunc, None) if not func: raise exception.InternalError( _("Unsupported VIF type %(obj)s func %(func)s") % { 'obj': vif.obj_name(), 'func': viffunc }) func(instance, vif, conf, host) designer.set_vif_bandwidth_config(conf, inst_type) return conf
def get_domain(self, instance): """Retrieve libvirt domain object for an instance. All libvirt error handling should be handled in this method and relevant nova exceptions should be raised in response. :param instance: a nova.objects.Instance object :returns: a libvirt.Domain object :raises exception.InstanceNotFound: The domain was not found :raises exception.InternalError: A libvirt error occurred """ try: conn = self.get_connection() return conn.lookupByUUIDString(instance.uuid) except libvirt.libvirtError as ex: error_code = ex.get_error_code() if error_code == libvirt.VIR_ERR_NO_DOMAIN: raise exception.InstanceNotFound(instance_id=instance.uuid) msg = (_('Error from libvirt while looking up %(instance_name)s: ' '[Error Code %(error_code)s] %(ex)s') % { 'instance_name': instance.name, 'error_code': error_code, 'ex': ex }) raise exception.InternalError(msg)
def __init__(self, path, source_type, driver_format, is_block_dev=False): """Image initialization. :param path: libvirt's representation of the path of this disk. :param source_type: block or file :param driver_format: raw or qcow2 :param is_block_dev: """ if (CONF.ephemeral_storage_encryption.enabled and not self._supports_encryption()): msg = _('Incompatible settings: ephemeral storage encryption is ' 'supported only for LVM images.') raise exception.InternalError(msg) self.path = path self.source_type = source_type self.driver_format = driver_format self.driver_io = None self.discard_mode = CONF.libvirt.hw_disk_discard self.is_block_dev = is_block_dev self.preallocate = False # NOTE(dripton): We store lines of json (path, disk_format) in this # file, for some image types, to prevent attacks based on changing the # disk_format. self.disk_info_path = None # NOTE(mikal): We need a lock directory which is shared along with # instance files, to cover the scenario where multiple compute nodes # are trying to create a base file at the same time self.lock_path = os.path.join(CONF.instances_path, 'locks')
def __init__(self, connection): super(LibvirtVZStorageVolumeDriver, self).__init__(connection) # Check for duplicate options: # -c - cluster name # -l - log file, includes %(cluster_name)s, so it's handled as a # separate config parameter # -C - SSD cache file, the same thing with %(cluster_name)s # -u, -g, -m - there are default values for these options, so # they're separate config parameters cfg_opts_set = set(CONF.libvirt.vzstorage_mount_opts) invalid_opts_set = set(( '-c', '-l', '-C', '-u', '-g', '-m', )) invalid_cfg_opts = cfg_opts_set.intersection(invalid_opts_set) if invalid_cfg_opts: msg = (_("You can't use %s options in vzstorage_mount_opts " "configuration parameter.") % ', '.join(invalid_cfg_opts)) raise exception.InternalError(msg) # Call the factory here so we can support # more than x86 architectures. self.connector = connector.InitiatorConnector.factory( initiator.VZSTORAGE, utils.get_root_helper(), vzstorage_mount_point_base=CONF.libvirt.vzstorage_mount_point_base)
def create_secret(self, usage_type, usage_id, password=None): """Create a secret. :param usage_type: one of 'iscsi', 'ceph', 'rbd' or 'volume' 'rbd' will be converted to 'ceph'. :param usage_id: name of resource in secret :param password: optional secret value to set """ secret_conf = vconfig.LibvirtConfigSecret() secret_conf.ephemeral = False secret_conf.private = False secret_conf.usage_id = usage_id if usage_type in ('rbd', 'ceph'): secret_conf.usage_type = 'ceph' elif usage_type == 'iscsi': secret_conf.usage_type = 'iscsi' elif usage_type == 'volume': secret_conf.usage_type = 'volume' else: msg = _("Invalid usage_type: %s") raise exception.InternalError(msg % usage_type) xml = secret_conf.to_xml() try: LOG.debug('Secret XML: %s', xml) conn = self.get_connection() secret = conn.secretDefineXML(xml) if password is not None: secret.setValue(password) return secret except libvirt.libvirtError: with excutils.save_and_reraise_exception(): LOG.error('Error defining a secret with XML: %s', xml)
def get_disk_bus_for_disk_dev(virt_type, disk_dev): """Determine the disk bus for a disk device. Given a disk device like 'hda', 'sdf', 'xvdb', etc guess what the most appropriate disk bus is for the currently configured virtualization technology Returns the disk bus, or raises an Exception if the disk device prefix is unknown. """ if disk_dev.startswith('hd'): return "ide" elif disk_dev.startswith('sd'): # Reverse mapping 'sd' is not reliable # there are many possible mappings. So # this picks the most likely mappings if virt_type == "xen": return "xen" else: return "scsi" elif disk_dev.startswith('vd'): return "virtio" elif disk_dev.startswith('fd'): return "fdc" elif disk_dev.startswith('xvd'): return "xen" elif disk_dev.startswith('ubd'): return "uml" else: msg = _("Unable to determine disk bus for '%s'") % disk_dev[:1] raise exception.InternalError(msg)
def find_disk_dev_for_disk_bus(mapping, bus, assigned_devices=None): """Identify a free disk dev name for a bus. Determines the possible disk dev names for the bus, and then checks them in order until it identifies one that is not yet used in the disk mapping. Returns the chosen disk_dev name, or raises an exception if none is available. """ dev_prefix = get_dev_prefix_for_disk_bus(bus) if dev_prefix is None: return None if assigned_devices is None: assigned_devices = [] max_dev = get_dev_count_for_disk_bus(bus) devs = range(max_dev) for idx in devs: disk_dev = dev_prefix + chr(ord('a') + idx) if not has_disk_dev(mapping, disk_dev): if disk_dev not in assigned_devices: return disk_dev msg = _("No free disk device names for prefix '%s'") % dev_prefix raise exception.InternalError(msg)
def get_dev_prefix_for_disk_bus(disk_bus): """Determine the dev prefix for a disk bus. Determine the dev prefix to be combined with a disk number to fix a disk_dev. eg 'hd' for 'ide' bus can be used to form a disk dev 'hda' Returns the dev prefix or raises an exception if the disk bus is unknown. """ if CONF.libvirt.disk_prefix: return CONF.libvirt.disk_prefix if disk_bus == "ide": return "hd" elif disk_bus == "virtio": return "vd" elif disk_bus == "xen": return "xvd" elif disk_bus == "scsi": return "sd" elif disk_bus == "usb": return "sd" elif disk_bus == "fdc": return "fd" elif disk_bus == "uml": return "ubd" elif disk_bus == "lxc": return None elif disk_bus == "sata": return "sd" else: raise exception.InternalError( _("Unable to determine disk prefix for %s") % disk_bus)
def _set_config_VIFPortProfile(self, instance, vif, conf): # Set any port profile that may be required profile_name = vif.port_profile.obj_name() if profile_name == 'VIFPortProfileOpenVSwitch': self._set_config_VIFPortProfileOpenVSwitch(vif.port_profile, conf) else: raise exception.InternalError( _('Unsupported VIF port profile type %s') % profile_name)
def unplug(self, instance, vif): vif_type = vif['type'] # instance.display_name could be unicode instance_repr = utils.get_obj_repr_unicode(instance) LOG.debug('vif_type=%(vif_type)s instance=%(instance)s ' 'vif=%(vif)s', { 'vif_type': vif_type, 'instance': instance_repr, 'vif': vif }) if vif_type is None: msg = _("vif_type parameter must be present for this vif_driver " "implementation") raise exception.InternalError(msg) # Try os-vif codepath first vif_obj = os_vif_util.nova_to_osvif_vif(vif) if vif_obj is not None: self._unplug_os_vif(instance, vif_obj) return # Legacy non-os-vif codepath if vif_type == network_model.VIF_TYPE_IB_HOSTDEV: self.unplug_ib_hostdev(instance, vif) elif vif_type == network_model.VIF_TYPE_HW_VEB: self.unplug_hw_veb(instance, vif) elif vif_type == network_model.VIF_TYPE_MIDONET: self.unplug_midonet(instance, vif) elif vif_type == network_model.VIF_TYPE_IOVISOR: self.unplug_iovisor(instance, vif) elif vif_type == network_model.VIF_TYPE_TAP: self.unplug_tap(instance, vif) elif vif_type in { network_model.VIF_TYPE_802_QBG, network_model.VIF_TYPE_802_QBH, network_model.VIF_TYPE_HOSTDEV, network_model.VIF_TYPE_MACVTAP }: # These are no-ops pass else: # TODO(stephenfin): This should probably raise # VirtualInterfaceUnplugException raise exception.InternalError( _("Unplug VIF failed because of unexpected " "vif_type=%s") % vif_type)
def cpu_policy(self): cpu_policy = set(cell.cpu_policy for cell in self.cells) if len(cpu_policy) > 1: # NOTE(stephenfin): This should never happen in real life; it's to # prevent programmer error. raise exception.InternalError( 'Instance NUMA cells must have the same CPU policy.') return cpu_policy.pop()
def _unplug_os_vif(self, instance, vif): instance_info = os_vif_util.nova_to_osvif_instance(instance) try: os_vif.unplug(vif, instance_info) except osv_exception.ExceptionBase as ex: msg = (_("Failure running os_vif plugin unplug method: %(ex)s") % {'ex': ex}) raise exception.InternalError(msg)
def _set_config_VIFPortProfile(self, instance, vif, conf): # Set any port profile that may be required profilefunc = "_set_config_" + vif.port_profile.obj_name() func = getattr(self, profilefunc, None) if not func: raise exception.InternalError( _("Unsupported VIF port profile type %(obj)s func %(func)s") % {'obj': vif.port_profile.obj_name(), 'func': profilefunc}) func(vif.port_profile, conf)
def _get_config_os_vif( self, instance, vif, image_meta, flavor, virt_type, vnic_type, ): """Get the domain config for a VIF :param instance: nova.objects.Instance :param vif: os_vif.objects.vif.VIFBase subclass :param image_meta: nova.objects.ImageMeta :param flavor: nova.objects.Flavor :param virt_type: virtualization type :param vnic_type: vnic type :returns: nova.virt.libvirt.config.LibvirtConfigGuestInterface """ # Do the config that's common to all vif types conf = self.get_base_config(instance, vif.address, image_meta, flavor, virt_type, vnic_type) # Do the VIF type specific config if isinstance(vif, osv_vifs.VIFGeneric): self._set_config_VIFGeneric(instance, vif, conf) elif isinstance(vif, osv_vifs.VIFBridge): self._set_config_VIFBridge(instance, vif, conf) elif isinstance(vif, osv_vifs.VIFOpenVSwitch): self._set_config_VIFOpenVSwitch(instance, vif, conf) elif isinstance(vif, osv_vifs.VIFVHostUser): self._set_config_VIFVHostUser(instance, vif, conf) elif isinstance(vif, osv_vifs.VIFHostDevice): if vnic_type != network_model.VNIC_TYPE_VDPA: self._set_config_VIFHostDevice(instance, vif, conf) else: dev_path = self._get_vdpa_dev_path(vif.dev_address) designer.set_vif_host_backend_vdpa_config( conf, dev_path, CONF.libvirt.rx_queue_size, CONF.libvirt.tx_queue_size) else: raise exception.InternalError( _("Unsupported VIF type %s") % vif.obj_name()) # not all VIF types support bandwidth configuration # https://github.com/libvirt/libvirt/blob/568a41722/src/conf/netdev_bandwidth_conf.h#L38 if vif.obj_name() not in ('VIFVHostUser', 'VIFHostDevice'): designer.set_vif_bandwidth_config(conf, flavor) if 'network' in vif and 'mtu' in vif.network: designer.set_vif_mtu_config(conf, vif.network.mtu) return conf
def _mount_sofs(self): config = CONF.libvirt.scality_sofs_config mount_path = CONF.libvirt.scality_sofs_mount_point if not os.path.isdir(mount_path): utils.execute('mkdir', '-p', mount_path) if not self._sofs_is_mounted(): utils.execute('mount', '-t', 'sofs', config, mount_path, run_as_root=True) if not self._sofs_is_mounted(): msg = _("Cannot mount Scality SOFS, check syslog for errors") LOG.warning(msg) raise exception.InternalError(msg)
def unplug(self, instance, vif): vif_type = vif['type'] instance_info = os_vif_util.nova_to_osvif_instance(instance) # Try os-vif codepath first vif_obj = os_vif_util.nova_to_osvif_vif(vif) if vif_obj is not None: os_vif.unplug(vif_obj, instance_info) return # Legacy non-os-vif codepath func = getattr(self, 'unplug_%s' % vif_type, None) if not func: raise exception.InternalError("Unexpected vif_type=%s" % vif_type) func(instance, vif)
def _set_config_VIFHostDevice(self, instance, vif, conf): if vif.dev_type == osv_fields.VIFHostDeviceDevType.ETHERNET: # This sets the required fields for an <interface type='hostdev'> # section in a libvirt domain (by using a subset of hw_veb's # options). designer.set_vif_host_backend_hw_veb(conf, 'hostdev', vif.dev_address, None) else: # TODO(jangutter): dev_type == VIFHostDeviceDevType.GENERIC # is currently unsupported under os-vif. The corresponding conf # class would be: LibvirtConfigGuestHostdevPCI # but os-vif only returns a LibvirtConfigGuestInterface object raise exception.InternalError( _("Unsupported os-vif VIFHostDevice dev_type %(type)s") % {'type': vif.dev_type})
def _get_config_os_vif(self, instance, vif, image_meta, inst_type, virt_type, host, vnic_type): """Get the domain config for a VIF :param instance: nova.objects.Instance :param vif: os_vif.objects.vif.VIFBase subclass :param image_meta: nova.objects.ImageMeta :param inst_type: nova.objects.Flavor :param virt_type: virtualization type :param host: nova.virt.libvirt.host.Host :param vnic_type: vnic type :returns: nova.virt.libvirt.config.LibvirtConfigGuestInterface """ # Do the config that's common to all vif types conf = self.get_base_config(instance, vif.address, image_meta, inst_type, virt_type, vnic_type, host) # Do the VIF type specific config if isinstance(vif, osv_vifs.VIFGeneric): self._set_config_VIFGeneric(instance, vif, conf, host) elif isinstance(vif, osv_vifs.VIFBridge): self._set_config_VIFBridge(instance, vif, conf, host) elif isinstance(vif, osv_vifs.VIFOpenVSwitch): self._set_config_VIFOpenVSwitch(instance, vif, conf, host) elif isinstance(vif, osv_vifs.VIFVHostUser): self._set_config_VIFVHostUser(instance, vif, conf, host) elif isinstance(vif, osv_vifs.VIFHostDevice): self._set_config_VIFHostDevice(instance, vif, conf, host) else: raise exception.InternalError( _("Unsupported VIF type %s") % vif.obj_name()) # not all VIF types support bandwidth configuration # https://github.com/libvirt/libvirt/blob/568a41722/src/conf/netdev_bandwidth_conf.h#L38 if vif.obj_name() not in ('VIFVHostUser', 'VIFHostDevice'): designer.set_vif_bandwidth_config(conf, inst_type) if ('network' in vif and 'mtu' in vif.network and self._has_min_version_for_mtu(host)): designer.set_vif_mtu_config(conf, vif.network.mtu) return conf
def _wait_for_instance_pending_task(self, context, vm_uuid): instance = objects.Instance.get_by_uuid(context, vm_uuid) task_state_timeout = CONF.hyperv.evacuate_task_state_timeout while instance.task_state: LOG.debug("Waiting to evacuate instance %(instance_id)s. Current " "task state: '%(task_state)s', Time remaining: " "%(timeout)s.", {'instance_id': instance.id, 'task_state': instance.task_state, 'timeout': task_state_timeout}) time.sleep(1) instance.refresh() task_state_timeout -= 1 if task_state_timeout <= 0: err = (_("Timeout error. Instance %(instance)s hasn't changed " "task_state %(task_state)s within %(timeout)s " "seconds.") % {'instance': instance.name, 'task_state': instance.task_state, 'timeout': CONF.hyperv.evacuate_task_state_timeout}) raise exception.InternalError(message=err)
def find_secret(self, usage_type, usage_id): """Find a secret. usage_type: one of 'iscsi', 'ceph', 'rbd' or 'volume' usage_id: name of resource in secret """ if usage_type == 'iscsi': usage_type_const = libvirt.VIR_SECRET_USAGE_TYPE_ISCSI elif usage_type in ('rbd', 'ceph'): usage_type_const = libvirt.VIR_SECRET_USAGE_TYPE_CEPH elif usage_type == 'volume': usage_type_const = libvirt.VIR_SECRET_USAGE_TYPE_VOLUME else: msg = _("Invalid usage_type: %s") raise exception.InternalError(msg % usage_type) try: conn = self.get_connection() return conn.secretLookupByUsage(usage_type_const, usage_id) except libvirt.libvirtError as e: if e.get_error_code() == libvirt.VIR_ERR_NO_SECRET: return None
def get_disk_bus_for_disk_dev(virt_type, disk_dev): """Determine the disk bus for a disk device. Given a disk device like 'hda' or 'sdf', guess what the most appropriate disk bus is for the currently configured virtualization technology :return: The preferred disk bus for the given disk prefix. :raises: InternalError if the disk device prefix is unknown. """ if disk_dev.startswith('hd'): return "ide" elif disk_dev.startswith('sd'): # Reverse mapping 'sd' is not reliable # there are many possible mappings. So # this picks the most likely mappings return "scsi" elif disk_dev.startswith('vd'): return "virtio" elif disk_dev.startswith('fd'): return "fdc" else: msg = _("Unable to determine disk bus for '%s'") % disk_dev[:1] raise exception.InternalError(msg)
def _connect_auth_cb(creds, opaque): if len(creds) == 0: return 0 raise exception.InternalError( _("Can not handle authentication request for %d credentials") % len(creds))
def create_image(self, prepare_template, base, size, *args, **kwargs): def encrypt_lvm_image(): dmcrypt.create_volume(self.path.rpartition('/')[2], self.lv_path, CONF.ephemeral_storage_encryption.cipher, CONF.ephemeral_storage_encryption.key_size, key) filename = self._get_lock_name(base) @utils.synchronized(filename, external=True, lock_path=self.lock_path) def create_lvm_image(base, size): base_size = disk.get_disk_size(base) self.verify_base_size(base, size, base_size=base_size) resize = size > base_size if size else False size = size if resize else base_size lvm.create_volume(self.vg, self.lv, size, sparse=self.sparse) if self.ephemeral_key_uuid is not None: encrypt_lvm_image() # NOTE: by calling convert_image_unsafe here we're # telling qemu-img convert to do format detection on the input, # because we don't know what the format is. For example, # we might have downloaded a qcow2 image, or created an # ephemeral filesystem locally, we just don't know here. Having # audited this, all current sources have been sanity checked, # either because they're locally generated, or because they have # come from images.fetch_to_raw. However, this is major code smell. images.convert_image_unsafe(base, self.path, self.driver_format, run_as_root=True) if resize: disk.resize2fs(self.path, run_as_root=True) generated = 'ephemeral_size' in kwargs if self.ephemeral_key_uuid is not None: if 'context' in kwargs: try: # NOTE(dgenin): Key manager corresponding to the # specific backend catches and reraises an # an exception if key retrieval fails. key = self.key_manager.get(kwargs['context'], self.ephemeral_key_uuid).get_encoded() except Exception: with excutils.save_and_reraise_exception(): LOG.error("Failed to retrieve ephemeral " "encryption key") else: raise exception.InternalError( _("Instance disk to be encrypted but no context provided")) # Generate images with specified size right on volume if generated and size: lvm.create_volume(self.vg, self.lv, size, sparse=self.sparse) with self.remove_volume_on_error(self.path): if self.ephemeral_key_uuid is not None: encrypt_lvm_image() prepare_template(target=self.path, *args, **kwargs) else: if not os.path.exists(base): prepare_template(target=base, *args, **kwargs) with self.remove_volume_on_error(self.path): create_lvm_image(base, size)