Exemplo n.º 1
0
 def discover_st(self, data):
     """Discover iSCSI targets."""
     target_portal = data['target_portal']
     target_iqn = data['target_iqn']
     LOG.debug(
         _("Discovering iSCSI target %(target_iqn)s from "
           "%(target_portal)s.") % locals())
     device_name, uuid = volume_util.find_st(self._session, data,
                                             self._cluster)
     if device_name:
         LOG.debug(_("Storage target found. No need to discover"))
         return (device_name, uuid)
     # Rescan iSCSI HBA
     volume_util.rescan_iscsi_hba(self._session, self._cluster)
     # Find iSCSI Target again
     device_name, uuid = volume_util.find_st(self._session, data,
                                             self._cluster)
     if device_name:
         LOG.debug(
             _("Discovered iSCSI target %(target_iqn)s from "
               "%(target_portal)s.") % locals())
     else:
         LOG.debug(
             _("Unable to discovered iSCSI target %(target_iqn)s "
               "from %(target_portal)s.") % locals())
     return (device_name, uuid)
Exemplo n.º 2
0
 def discover_st(self, data):
     """Discover iSCSI targets."""
     target_portal = data['target_portal']
     target_iqn = data['target_iqn']
     LOG.debug(_("Discovering iSCSI target %(target_iqn)s from "
                 "%(target_portal)s."),
               {'target_iqn': target_iqn, 'target_portal': target_portal})
     device_name, uuid = volume_util.find_st(self._session, data,
                                             self._cluster)
     if device_name:
         LOG.debug(_("Storage target found. No need to discover"))
         return (device_name, uuid)
     # Rescan iSCSI HBA
     volume_util.rescan_iscsi_hba(self._session, self._cluster)
     # Find iSCSI Target again
     device_name, uuid = volume_util.find_st(self._session, data,
                                             self._cluster)
     if device_name:
         LOG.debug(_("Discovered iSCSI target %(target_iqn)s from "
                     "%(target_portal)s."),
                   {'target_iqn': target_iqn,
                    'target_portal': target_portal})
     else:
         LOG.debug(_("Unable to discovered iSCSI target %(target_iqn)s "
                     "from %(target_portal)s."),
                   {'target_iqn': target_iqn,
                    'target_portal': target_portal})
     return (device_name, uuid)
Exemplo n.º 3
0
    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})
        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})
Exemplo n.º 4
0
 def test_find_st(self):
     data = {'target_portal': 'fake_target_host:port',
             'target_iqn': 'fake_target_iqn'}
     host = vmwareapi_fake._get_objects('HostSystem').objects[0]
     host._add_iscsi_target(data)
     result = volume_util.find_st(self.conn._session, data)
     self.assertEquals(('fake-device', 'fake-uuid'), result)
Exemplo n.º 5
0
    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())
Exemplo n.º 6
0
 def test_detach_iscsi_disk_from_vm(self):
     self._create_vm()
     connection_info = self._test_vmdk_connection_info("iscsi")
     connection_info["data"]["target_portal"] = "fake_target_portal"
     connection_info["data"]["target_iqn"] = "fake_target_iqn"
     mount_point = "/dev/vdc"
     find = ("fake_name", "fake_uuid")
     self.mox.StubOutWithMock(volume_util, "find_st")
     volume_util.find_st(mox.IgnoreArg(), connection_info["data"], mox.IgnoreArg()).AndReturn(find)
     self.mox.StubOutWithMock(vm_util, "get_rdm_disk")
     device = "fake_device"
     vm_util.get_rdm_disk(mox.IgnoreArg(), "fake_uuid").AndReturn(device)
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "detach_disk_from_vm")
     volumeops.VMwareVolumeOps.detach_disk_from_vm(mox.IgnoreArg(), self.instance, device)
     self.mox.ReplayAll()
     self.conn.detach_volume(connection_info, self.instance, mount_point)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
 def test_detach_iscsi_disk_from_vm(self):
     self._create_vm()
     connection_info = self._test_vmdk_connection_info('iscsi')
     connection_info['data']['target_portal'] = 'fake_target_portal'
     connection_info['data']['target_iqn'] = 'fake_target_iqn'
     mount_point = '/dev/vdc'
     find = ('fake_name', 'fake_uuid')
     self.mox.StubOutWithMock(volume_util, 'find_st')
     volume_util.find_st(mox.IgnoreArg(), connection_info['data'],
             mox.IgnoreArg()).AndReturn(find)
     self.mox.StubOutWithMock(vm_util, 'get_rdm_disk')
     device = 'fake_device'
     vm_util.get_rdm_disk(mox.IgnoreArg(), 'fake_uuid').AndReturn(device)
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
                              'detach_disk_from_vm')
     volumeops.VMwareVolumeOps.detach_disk_from_vm(mox.IgnoreArg(),
             self.instance, device)
     self.mox.ReplayAll()
     self.conn.detach_volume(connection_info, self.instance, mount_point)
Exemplo n.º 9
0
 def test_detach_iscsi_disk_from_vm(self):
     self._create_vm()
     connection_info = self._test_vmdk_connection_info('iscsi')
     connection_info['data']['target_portal'] = 'fake_target_portal'
     connection_info['data']['target_iqn'] = 'fake_target_iqn'
     mount_point = '/dev/vdc'
     find = ('fake_name', 'fake_uuid')
     self.mox.StubOutWithMock(volume_util, 'find_st')
     volume_util.find_st(mox.IgnoreArg(), connection_info['data'],
                         mox.IgnoreArg()).AndReturn(find)
     self.mox.StubOutWithMock(vm_util, 'get_rdm_disk')
     device = 'fake_device'
     vm_util.get_rdm_disk(mox.IgnoreArg(), 'fake_uuid').AndReturn(device)
     self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
                              'detach_disk_from_vm')
     volumeops.VMwareVolumeOps.detach_disk_from_vm(mox.IgnoreArg(),
                                                   self.instance, device)
     self.mox.ReplayAll()
     self.conn.detach_volume(connection_info, self.instance, mount_point)