def _detach_volume_vmdk(self, connection_info, instance): """Detach volume storage to VM instance.""" vm_ref = vm_util.get_vm_ref(self._session, instance) # Detach Volume from VM LOG.debug("_detach_volume_vmdk: %s", connection_info, instance=instance) data = connection_info['data'] volume_ref = self._get_volume_ref(data['volume']) device = self._get_vmdk_backed_disk_device(vm_ref, data) # Get details required for adding disk device such as # adapter_type, disk_type vmdk = vm_util.get_vmdk_info(self._session, volume_ref) # IDE does not support disk hotplug if (instance.vm_state == vm_states.ACTIVE and vmdk.adapter_type == constants.ADAPTER_TYPE_IDE): msg = _('%s does not support disk hotplug.') % vmdk.adapter_type raise exception.Invalid(msg) self._consolidate_vmdk_volume(instance, vm_ref, device, volume_ref, adapter_type=vmdk.adapter_type, disk_type=vmdk.disk_type) self.detach_disk_from_vm(vm_ref, instance, device) LOG.debug("Detached VMDK: %s", connection_info, instance=instance)
def _attach_volume_vmdk(self, connection_info, instance, adapter_type=None): """Attach vmdk volume storage to VM instance.""" vm_ref = vm_util.get_vm_ref(self._session, instance) LOG.debug("_attach_volume_vmdk: %s", connection_info, instance=instance) data = connection_info['data'] volume_ref = self._get_volume_ref(data['volume']) # Get details required for adding disk device such as # adapter_type, disk_type vmdk = vm_util.get_vmdk_info(self._session, volume_ref) adapter_type = adapter_type or vmdk.adapter_type # IDE does not support disk hotplug if (instance.vm_state == vm_states.ACTIVE and adapter_type == constants.ADAPTER_TYPE_IDE): msg = _('%s does not support disk hotplug.') % adapter_type raise exception.Invalid(msg) # Attach the disk to virtual machine instance self.attach_disk_to_vm(vm_ref, instance, adapter_type, vmdk.disk_type, vmdk_path=vmdk.path) # Store the uuid of the volume_device self._update_volume_details(vm_ref, data['volume_id'], vmdk.device.backing.uuid) LOG.debug("Attached VMDK: %s", connection_info, instance=instance)
def _translate_plain_exception(exc_value): if isinstance(exc_value, (glanceclient.exc.Forbidden, glanceclient.exc.Unauthorized)): return exception.Forbidden(six.text_type(exc_value)) if isinstance(exc_value, glanceclient.exc.NotFound): return exception.NotFound(six.text_type(exc_value)) if isinstance(exc_value, glanceclient.exc.BadRequest): return exception.Invalid(six.text_type(exc_value)) return exc_value
def _translate_image_exception(image_id, exc_value): if isinstance(exc_value, (glanceclient.exc.Forbidden, glanceclient.exc.Unauthorized)): return exception.ImageNotAuthorized(image_id=image_id) if isinstance(exc_value, glanceclient.exc.NotFound): return exception.ImageNotFound(image_id=image_id) if isinstance(exc_value, glanceclient.exc.BadRequest): return exception.Invalid(six.text_type(exc_value)) return exc_value
def _canonical_path(self, path): canonpath, _err = utils.execute('readlink', '-nm', os.path.join(self.imgdir, path.lstrip("/")), run_as_root=True) if not canonpath.startswith(os.path.realpath(self.imgdir) + '/'): raise exception.Invalid(_('File path %s not valid') % path) return canonpath
def test_create_client_failure(self, trans_to_mock, trans_from_mock, reraise_mock): translated = {} trans_to_mock.return_value = translated image_mock = mock.MagicMock(spec=dict) raised = exception.Invalid() client = mock.MagicMock() client.call.side_effect = glanceclient.exc.BadRequest ctx = mock.sentinel.ctx reraise_mock.side_effect = raised service = glance.GlanceImageService(client) self.assertRaises(exception.Invalid, service.create, ctx, image_mock) trans_to_mock.assert_called_once_with(image_mock) self.assertFalse(trans_from_mock.called)
def status_to_ec2_attach_status(volume): """Get the corresponding EC2 attachment state. According to EC2 API, the valid attachment status in response is: attaching | attached | detaching | detached """ volume_status = volume.get('status') attach_status = volume.get('attach_status') if volume_status in ('attaching', 'detaching'): ec2_attach_status = volume_status elif attach_status in ('attached', 'detached'): ec2_attach_status = attach_status else: msg = _("Unacceptable attach status:%s for ec2 API.") % attach_status raise exception.Invalid(msg) return ec2_attach_status
def clear_volume(path): """Obfuscate the logical volume. :param path: logical volume path """ volume_clear = CONF.libvirt.volume_clear if volume_clear not in ('none', 'shred', 'zero'): LOG.error(_LE("ignoring unrecognized volume_clear='%s' value"), volume_clear) volume_clear = 'zero' if volume_clear == 'none': return volume_clear_size = int(CONF.libvirt.volume_clear_size) * units.Mi try: volume_size = get_volume_size(path) except exception.VolumeBDMPathNotFound: LOG.warn(_LW('ignoring missing logical volume %(path)s'), {'path': path}) return if volume_clear_size != 0 and volume_clear_size < volume_size: volume_size = volume_clear_size if volume_clear == 'zero': # NOTE(p-draigbrady): we could use shred to do the zeroing # with -n0 -z, however only versions >= 8.22 perform as well as dd _zero_volume(path, volume_size) elif volume_clear == 'shred': utils.execute('shred', '-n3', '-s%d' % volume_size, path, run_as_root=True) else: raise exception.Invalid( _("volume_clear='%s' is not handled") % volume_clear)
def raise_invalid_group(msg): raise exception.Invalid(msg)
def raise_group_already_exists(msg): raise exception.Invalid(msg)
def raise_invalid_property(msg): raise exception.Invalid(msg)
def test_get_image_meta_bad_request(self): error = exception.Invalid() self._test_get_image_meta_exception(error)