예제 #1
0
    def _connect_volume(self, connection_data, dev_number, instance_name, vm_ref, hotplug=True):
        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
            vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref, dev_number, bootable=False, osvol=True)

            if hotplug:
                self._session.call_xenapi("VBD.plug", vbd_ref)
        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)
예제 #2
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)
예제 #3
0
    def _connect_hypervisor_to_volume(self, sr_ref, connection_data):
        LOG.debug("Connect volume to hypervisor: %s", connection_data)
        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)

        return vdi_ref
예제 #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:
                    self._session.VBD.plug(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)
예제 #5
0
    def _connect_volume(self,
                        connection_data,
                        dev_number,
                        instance_name,
                        vm_ref,
                        hotplug=True):
        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
            vbd_ref = vm_utils.create_vbd(self._session,
                                          vm_ref,
                                          vdi_ref,
                                          dev_number,
                                          bootable=False,
                                          osvol=True)

            if hotplug:
                self._session.call_xenapi("VBD.plug", vbd_ref)
        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)
예제 #6
0
    def _connect_hypervisor_to_volume(self, sr_ref, connection_data):
        LOG.debug("Connect volume to hypervisor: %s", connection_data)
        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)

        return vdi_ref
예제 #7
0
    def _connect_hypervisor_to_volume(self, sr_ref, connection_data):
        # connection_data can have credentials in it so make sure to scrub
        # those before logging.
        LOG.debug("Connect volume to hypervisor: %s",
                  strutils.mask_password(connection_data))
        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)

        return vdi_ref
예제 #8
0
    def _connect_hypervisor_to_volume(self, sr_ref, connection_data):
        # connection_data can have credentials in it so make sure to scrub
        # those before logging.
        LOG.debug("Connect volume to hypervisor: %s",
                  strutils.mask_password(connection_data))
        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)

        return vdi_ref
예제 #9
0
    def test_introduce_vdi_retry(self, mock_sleep, mock_get_vdi_ref):
        def fake_get_vdi_ref(session, sr_ref, vdi_uuid, target_lun):
            fake_get_vdi_ref.call_count += 1
            if fake_get_vdi_ref.call_count == 2:
                return "vdi_ref"

        def fake_call_xenapi(method, *args):
            if method == "SR.scan":
                return
            elif method == "VDI.get_record":
                return {"managed": "true"}

        session = mock.Mock()
        session.call_xenapi.side_effect = fake_call_xenapi

        mock_get_vdi_ref.side_effect = fake_get_vdi_ref
        fake_get_vdi_ref.call_count = 0

        self.assertEqual(volume_utils.introduce_vdi(session, "sr_ref"), "vdi_ref")
        mock_sleep.assert_called_once_with(20)
예제 #10
0
    def test_introduce_vdi_retry(self, mock_sleep, mock_get_vdi_ref):
        def fake_get_vdi_ref(session, sr_ref, vdi_uuid, target_lun):
            fake_get_vdi_ref.call_count += 1
            if fake_get_vdi_ref.call_count == 2:
                return 'vdi_ref'

        def fake_call_xenapi(method, *args):
            if method == 'SR.scan':
                return
            elif method == 'VDI.get_record':
                return {'managed': 'true'}

        session = mock.Mock()
        session.call_xenapi.side_effect = fake_call_xenapi

        mock_get_vdi_ref.side_effect = fake_get_vdi_ref
        fake_get_vdi_ref.call_count = 0

        self.assertEqual(volume_utils.introduce_vdi(session, 'sr_ref'),
                         'vdi_ref')
        mock_sleep.assert_called_once_with(20)
예제 #11
0
    def test_introduce_vdi_retry(self, mock_sleep, mock_get_vdi_ref):
        def fake_get_vdi_ref(session, sr_ref, vdi_uuid, target_lun):
            fake_get_vdi_ref.call_count += 1
            if fake_get_vdi_ref.call_count == 2:
                return 'vdi_ref'

        def fake_call_xenapi(method, *args):
            if method == 'SR.scan':
                return
            elif method == 'VDI.get_record':
                return {'managed': 'true'}

        session = mock.Mock()
        session.call_xenapi.side_effect = fake_call_xenapi

        mock_get_vdi_ref.side_effect = fake_get_vdi_ref
        fake_get_vdi_ref.call_count = 0

        self.assertEqual(volume_utils.introduce_vdi(session, 'sr_ref'),
                         'vdi_ref')
        mock_sleep.assert_called_once_with(20)
예제 #12
0
            LOG.exception(exc)
            raise volume_utils.StorageError(
                _('Unable to introduce Storage Repository'))

        vdi_uuid = None
        target_lun = None
        if 'vdi_uuid' in connection_data:
            vdi_uuid = connection_data['vdi_uuid']
        elif 'target_lun' in connection_data:
            target_lun = connection_data['target_lun']
        else:
            vdi_uuid = None

        # Introduce VDI  and attach VBD to VM
        try:
            vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref,
                                                 vdi_uuid, target_lun)
        except volume_utils.StorageError, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(
                _('Unable to create VDI on SR %(sr_ref)s for'
                  ' instance %(instance_name)s') % locals())

        try:
            vbd_ref = vm_utils.create_vbd(self._session,
                                          vm_ref,
                                          vdi_ref,
                                          dev_number,
                                          bootable=False,
                                          osvol=True)
        except self._session.XenAPI.Failure, exc:
예제 #13
0
파일: volumeops.py 프로젝트: A7Zulu/nova
            LOG.exception(exc)
            raise volume_utils.StorageError(
                                _('Unable to introduce Storage Repository'))

        vdi_uuid = None
        target_lun = None
        if 'vdi_uuid' in data:
            vdi_uuid = data['vdi_uuid']
        elif 'target_lun' in data:
            target_lun = data['target_lun']
        else:
            vdi_uuid = None

        # Introduce VDI  and attach VBD to VM
        try:
            vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref,
                                                 vdi_uuid, target_lun)
        except volume_utils.StorageError, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(_('Unable to create VDI on SR %(sr_ref)s for'
                    ' instance %(instance_name)s') % locals())

        dev_number = volume_utils.mountpoint_to_number(mountpoint)
        try:
            vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref,
                                          dev_number, bootable=False)
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(_('Unable to use SR %(sr_ref)s for'
                              ' instance %(instance_name)s') % locals())
예제 #14
0
class VolumeOps(object):
    """
    Management class for Volume-related tasks
    """
    def __init__(self, session):
        self._session = session

    def attach_volume(self,
                      connection_info,
                      instance_name,
                      mountpoint,
                      hotplug=True):
        """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,
                             hotplug=hotplug)

        LOG.info(
            _('Mountpoint %(mountpoint)s attached to'
              ' instance %(instance_name)s') % locals())

    def _connect_volume(self,
                        connection_data,
                        dev_number,
                        instance_name,
                        vm_ref,
                        hotplug=True):

        description = 'Disk-for:%s' % instance_name
        uuid, label, sr_params = volume_utils.parse_sr_info(
            connection_data, description)

        # Introduce SR
        try:
            sr_ref = volume_utils.introduce_sr_unless_present(
                self._session, 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'))

        vdi_uuid = None
        target_lun = None
        if 'vdi_uuid' in connection_data:
            vdi_uuid = connection_data['vdi_uuid']
        elif 'target_lun' in connection_data:
            target_lun = connection_data['target_lun']
        else:
            vdi_uuid = None

        # Introduce VDI  and attach VBD to VM
        try:
            vdi_ref = volume_utils.introduce_vdi(self._session, sr_ref,
                                                 vdi_uuid, target_lun)
        except volume_utils.StorageError, exc:
            LOG.exception(exc)
            volume_utils.forget_sr_if_present(self._session, uuid)
            raise Exception(
                _('Unable to create VDI on SR %(sr_ref)s for'
                  ' instance %(instance_name)s') % locals())