Ejemplo n.º 1
0
 def attach_volume(self, connection_info, instance, adapter_type=None):
     """Attach volume storage to VM instance."""
     driver_type = connection_info['driver_volume_type']
     LOG.debug("Volume attach. Driver type: %s",
               driver_type,
               instance=instance)
     if driver_type == constants.DISK_FORMAT_VMDK:
         self._attach_volume_vmdk(connection_info, instance, adapter_type)
     elif driver_type == 'iscsi':
         self._attach_volume_iscsi(connection_info, instance, adapter_type)
     else:
         raise exception.VolumeDriverNotFound(driver_type=driver_type)
Ejemplo n.º 2
0
 def detach_volume(self, connection_info, instance, mountpoint):
     """Detach volume storage to VM instance."""
     driver_type = connection_info['driver_volume_type']
     LOG.debug("Volume detach. Driver type: %s",
               driver_type,
               instance=instance)
     if driver_type == 'vmdk':
         self._detach_volume_vmdk(connection_info, instance, mountpoint)
     elif driver_type == 'iscsi':
         self._detach_volume_iscsi(connection_info, instance, mountpoint)
     else:
         raise exception.VolumeDriverNotFound(driver_type=driver_type)
Ejemplo n.º 3
0
 def detach_volume(self, connection_info, instance):
     """Detach volume storage to VM instance."""
     driver_type = connection_info['driver_volume_type']
     LOG.debug("Volume detach. Driver type: %s", driver_type,
               instance=instance)
     if driver_type == constants.DISK_FORMAT_VMDK:
         self._detach_volume_vmdk(connection_info, instance)
     elif driver_type == constants.DISK_FORMAT_ISCSI:
         self._detach_volume_iscsi(connection_info, instance)
     elif driver_type == constants.DISK_FORMAT_FCD:
         self._detach_volume_fcd(connection_info, instance)
     else:
         raise exception.VolumeDriverNotFound(driver_type=driver_type)
Ejemplo n.º 4
0
    def _connect_volume(self, connection_info, dev_number=None,
                        instance_name=None, vm_ref=None, hotplug=True):
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        connection_data = connection_info['data']

        sr_uuid, sr_label, sr_params = volume_utils.parse_sr_info(
                connection_data, 'Disk-for:%s' % instance_name)

        # Introduce SR if not already present
        sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid)
        if not sr_ref:
            sr_ref = volume_utils.introduce_sr(
                    self._session, sr_uuid, sr_label, sr_params)

        try:
            # Introduce VDI
            if 'vdi_uuid' in connection_data:
                vdi_ref = volume_utils.introduce_vdi(
                        self._session, sr_ref,
                        vdi_uuid=connection_data['vdi_uuid'])
            elif 'target_lun' in connection_data:
                vdi_ref = volume_utils.introduce_vdi(
                        self._session, sr_ref,
                        target_lun=connection_data['target_lun'])
            else:
                # NOTE(sirp): This will introduce the first VDI in the SR
                vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref)

            # Attach
            if vm_ref:
                vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref,
                                              dev_number, bootable=False,
                                              osvol=True)

                running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
                if hotplug and running:
                    volume_utils.vbd_plug(self._session, vbd_ref, vm_ref)

            vdi_uuid = self._session.call_xenapi("VDI.get_uuid", vdi_ref)
            return (sr_uuid, vdi_uuid)
        except Exception:
            with excutils.save_and_reraise_exception():
                # NOTE(sirp): Forgetting the SR will have the effect of
                # cleaning up the VDI and VBD records, so no need to handle
                # that explicitly.
                volume_utils.forget_sr(self._session, sr_ref)
Ejemplo n.º 5
0
    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
              })
Ejemplo n.º 6
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""
        # Before we start, check that the VM exists
        vm_ref = vm_utils.lookup(self._session, instance_name)
        if vm_ref is None:
            raise exception.InstanceNotFound(instance_id=instance_name)
        # NOTE: No Resource Pool concept so far
        LOG.debug(
            _("Attach_volume: %(connection_info)s, %(instance_name)s,"
              " %(mountpoint)s") % locals())
        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        data = connection_info['data']
        if 'name_label' not in data:
            label = 'tempSR-%s' % data['volume_id']
        else:
            label = data['name_label']
            del data['name_label']

        if 'name_description' not in data:
            desc = 'Disk-for:%s' % instance_name
        else:
            desc = data['name_description']

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in data:
            sr_params = volume_utils.parse_volume_info(connection_info,
                                                       mountpoint)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = data['sr_uuid']
            for k in data['introduce_sr_keys']:
                sr_params[k] = data[k]

        sr_params['name_description'] = desc

        # Introduce SR
        try:
            sr_ref = self.introduce_sr(uuid, label, sr_params)
            LOG.debug(_('Introduced %(label)s as %(sr_ref)s.') % locals())
        except self._session.XenAPI.Failure, exc:
            LOG.exception(exc)
            raise volume_utils.StorageError(
                _('Unable to introduce Storage Repository'))
Ejemplo n.º 7
0
    def attach_volume(self, connection_info, instance_name, mountpoint):
        """Attach volume storage to VM instance"""

        vm_ref = vm_utils.vm_ref_or_raise(self._session, instance_name)

        # NOTE: No Resource Pool concept so far
        LOG.debug(
            _("Attach_volume: %(connection_info)s, %(instance_name)s,"
              " %(mountpoint)s") % locals())

        driver_type = connection_info['driver_volume_type']
        if driver_type not in ['iscsi', 'xensm']:
            raise exception.VolumeDriverNotFound(driver_type=driver_type)

        connection_data = connection_info['data']
        dev_number = volume_utils.get_device_number(mountpoint)

        self.connect_volume(connection_data, dev_number, instance_name, vm_ref)

        LOG.info(
            _('Mountpoint %(mountpoint)s attached to'
              ' instance %(instance_name)s') % locals())
Ejemplo n.º 8
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"), {
            'mountpoint': mountpoint,
            'instance_name': instance_name
        })
        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"), {
                  'mountpoint': mountpoint,
                  'instance_name': instance_name
              })
Ejemplo n.º 9
0
 def _get_volume_driver(self, driver_type=None, connection_info=None):
     if connection_info:
         driver_type = connection_info.get('driver_volume_type')
     if driver_type not in self.volume_drivers:
         raise exception.VolumeDriverNotFound(driver_type=driver_type)
     return self.volume_drivers[driver_type]
Ejemplo n.º 10
0
 def _check_is_supported_driver_type(self, connection_info):
     driver_type = connection_info['driver_volume_type']
     if driver_type not in ['iscsi', 'xensm']:
         raise exception.VolumeDriverNotFound(driver_type=driver_type)
Ejemplo n.º 11
0
 def _disconnect_volume(self, connection_info, disk_dev):
     driver_type = connection_info.get('driver_volume_type')
     if driver_type not in self.volume_drivers:
         raise exception.VolumeDriverNotFound(driver_type=driver_type)
     driver = self.volume_drivers[driver_type]
     return driver.connect_volume(connection_info, disk_dev)