def detach_volume(self, connection_info, instance, mountpoint): """Detach volume storage to VM instance.""" instance_name = instance['name'] vm_ref = vm_util.get_vm_ref_from_name(self._session, instance_name) if vm_ref is None: raise exception.InstanceNotFound(instance_id=instance_name) # Detach Volume from VM LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals()) driver_type = connection_info['driver_volume_type'] if driver_type not in ['iscsi']: raise exception.VolumeDriverNotFound(driver_type=driver_type) data = connection_info['data'] # Discover iSCSI Target device_name, uuid = volume_util.find_st(self._session, data, self._cluster) if device_name is None: raise volume_util.StorageError(_("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 volume_util.StorageError(_("Unable to find volume")) self.detach_disk_from_vm(vm_ref, instance_name, device) LOG.info(_("Mountpoint %(mountpoint)s detached from " "instance %(instance_name)s") % locals())
def _detach_volume_iscsi(self, connection_info, instance, mountpoint): """Detach volume storage to VM instance.""" instance_name = instance['name'] vm_ref = vm_util.get_vm_ref(self._session, instance) # Detach Volume from VM LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s"), { 'mountpoint': mountpoint, 'instance_name': instance_name }, instance=instance) data = connection_info['data'] # Discover iSCSI Target device_name, uuid = volume_util.find_st(self._session, data, self._cluster) if device_name is None: raise volume_util.StorageError(_("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 volume_util.StorageError(_("Unable to find volume")) self.detach_disk_from_vm(vm_ref, instance, device, destroy_disk=True) LOG.info(_("Mountpoint %(mountpoint)s detached from " "instance %(instance_name)s"), { 'mountpoint': mountpoint, 'instance_name': instance_name }, instance=instance)
def _attach_volume_iscsi(self, connection_info, instance, mountpoint): """Attach iscsi volume storage to VM instance.""" instance_name = instance['name'] vm_ref = vm_util.get_vm_ref(self._session, instance) # Attach Volume to VM LOG.debug(_("Attach_volume: %(connection_info)s, %(instance_name)s, " "%(mountpoint)s"), {'connection_info': connection_info, 'instance_name': instance_name, 'mountpoint': mountpoint}, instance=instance) data = connection_info['data'] # Discover iSCSI Target device_name, uuid = self.discover_st(data) if device_name is None: raise volume_util.StorageError(_("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") (vmdk_file_path, adapter_type, disk_type) = vm_util.get_vmdk_path_and_adapter_type(hardware_devices) self.attach_disk_to_vm(vm_ref, instance, adapter_type, 'rdmp', device_name=device_name) LOG.info(_("Mountpoint %(mountpoint)s attached to " "instance %(instance_name)s"), {'mountpoint': mountpoint, 'instance_name': instance_name}, instance=instance)
def _get_vmdk_backed_disk_device(self, vm_ref, connection_info_data): # 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") # Get disk uuid disk_uuid = self._get_volume_uuid(vm_ref, connection_info_data['volume_id']) device = vm_util.get_vmdk_backed_disk_device(hardware_devices, disk_uuid) if not device: raise volume_util.StorageError(_("Unable to find volume")) return device
def attach_volume(self, connection_info, instance, mountpoint): """Attach volume storage to VM instance.""" instance_name = instance['name'] vm_ref = vm_util.get_vm_ref_from_name(self._session, instance_name) if vm_ref is None: raise exception.InstanceNotFound(instance_id=instance_name) # Attach Volume to VM LOG.debug( _("Attach_volume: %(connection_info)s, %(instance_name)s, " "%(mountpoint)s"), { 'connection_info': connection_info, 'instance_name': instance_name, 'mountpoint': mountpoint }) driver_type = connection_info['driver_volume_type'] if driver_type not in ['iscsi']: raise exception.VolumeDriverNotFound(driver_type=driver_type) data = connection_info['data'] mount_unit = volume_util.mountpoint_to_number(mountpoint) # Discover iSCSI Target device_name, uuid = self.discover_st(data) if device_name is None: raise volume_util.StorageError(_("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") vmdk_file_path, controller_key, adapter_type, disk_type, unit_number \ = vm_util.get_vmdk_path_and_adapter_type(hardware_devices) # Figure out the correct unit number if unit_number < mount_unit: unit_number = mount_unit else: unit_number = unit_number + 1 self.attach_disk_to_vm(vm_ref, instance_name, adapter_type, disk_type="rdmp", controller_key=controller_key, unit_number=unit_number, device_name=device_name) LOG.info( _("Mountpoint %(mountpoint)s attached to " "instance %(instance_name)s"), { 'mountpoint': mountpoint, 'instance_name': instance_name })