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 _attach_volume_iscsi(self, connection_info, instance, adapter_type=None): """Attach iscsi volume storage to VM instance.""" vm_ref = vm_util.get_vm_ref(self._session, instance) # Attach Volume to VM LOG.debug("_attach_volume_iscsi: %s", connection_info, instance=instance) data = connection_info['data'] # Discover iSCSI Target device_name = self._iscsi_discover_target(data)[0] if device_name is None: raise exception.StorageError( reason=_("Unable to find iSCSI Target")) if adapter_type is None: # Get the vmdk file name that the VM is pointing to hardware_devices = self._session._call_method( vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device") adapter_type = vm_util.get_scsi_adapter_type(hardware_devices) self.attach_disk_to_vm(vm_ref, instance, adapter_type, 'rdmp', device_name=device_name) LOG.debug("Attached ISCSI: %s", connection_info, instance=instance)
def get_volume_connector(self, instance): """Return volume connector information.""" try: vm_ref = vm_util.get_vm_ref(self._session, instance) except exception.InstanceNotFound: vm_ref = None iqn = self._iscsi_get_host_iqn() connector = {'ip': CONF.vmware.host_ip, 'initiator': iqn, 'host': CONF.vmware.host_ip} if vm_ref: connector['instance'] = vm_ref.value return connector
def get_volume_connector(self, instance): """Return volume connector information.""" try: vm_ref = vm_util.get_vm_ref(self._session, instance) except exception.InstanceNotFound: vm_ref = None iqn = self._iscsi_get_host_iqn() connector = { 'ip': CONF.vmware.host_ip, 'initiator': iqn, 'host': CONF.vmware.host_ip } if vm_ref: connector['instance'] = vm_ref.value return connector
def attach_root_volume(self, connection_info, instance, datastore, adapter_type=None): """Attach a root volume to the VM instance.""" driver_type = connection_info['driver_volume_type'] LOG.debug("Root volume attach. Driver type: %s", driver_type, instance=instance) if driver_type == 'vmdk': vm_ref = vm_util.get_vm_ref(self._session, instance) data = connection_info['data'] # Get the volume ref volume_ref = self._get_volume_ref(data['volume']) # Pick the resource pool on which the instance resides. Move the # volume to the datastore of the instance. res_pool = self._get_res_pool_of_vm(vm_ref) self._relocate_vmdk_volume(volume_ref, res_pool, datastore) self.attach_volume(connection_info, instance, adapter_type)
def _detach_volume_iscsi(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_iscsi: %s", connection_info, instance=instance) data = connection_info['data'] # Discover iSCSI Target device_name, uuid = self._iscsi_get_target(data) if device_name is None: raise exception.StorageError( reason=_("Unable to find iSCSI Target")) # Get the vmdk file name that the VM is pointing to hardware_devices = self._session._call_method(vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device") device = vm_util.get_rdm_disk(hardware_devices, uuid) if device is None: raise exception.StorageError(reason=_("Unable to find volume")) self.detach_disk_from_vm(vm_ref, instance, device, destroy_disk=True) LOG.debug("Detached ISCSI: %s", connection_info, instance=instance)
def _detach_volume_iscsi(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_iscsi: %s", connection_info, instance=instance) data = connection_info['data'] # Discover iSCSI Target device_name, uuid = self._iscsi_get_target(data) if device_name is None: raise exception.StorageError( reason=_("Unable to find iSCSI Target")) # Get the vmdk file name that the VM is pointing to hardware_devices = self._session._call_method( vim_util, "get_dynamic_property", vm_ref, "VirtualMachine", "config.hardware.device") device = vm_util.get_rdm_disk(hardware_devices, uuid) if device is None: raise exception.StorageError(reason=_("Unable to find volume")) self.detach_disk_from_vm(vm_ref, instance, device, destroy_disk=True) LOG.debug("Detached ISCSI: %s", connection_info, instance=instance)