예제 #1
0
    def test_sr_info_two_luns(self):
        data1 = {"target_portal": "host:port", "target_iqn": "iqn", "volume_id": "vol_id_1", "target_lun": 1}
        data2 = {"target_portal": "host:port", "target_iqn": "iqn", "volume_id": "vol_id_2", "target_lun": 2}
        (sr_uuid1, label1, params1) = volume_utils.parse_sr_info(data1)
        (sr_uuid2, label2, params2) = volume_utils.parse_sr_info(data2)

        self.assertEqual(sr_uuid1, sr_uuid2)
        self.assertEqual(label1, label2)
    def test_sr_info_two_luns(self):
        data1 = {'target_portal': 'host:port',
                 'target_iqn': 'iqn',
                 'volume_id': 'vol_id_1',
                 'target_lun': 1}
        data2 = {'target_portal': 'host:port',
                 'target_iqn': 'iqn',
                 'volume_id': 'vol_id_2',
                 'target_lun': 2}
        (sr_uuid1, label1, params1) = volume_utils.parse_sr_info(data1)
        (sr_uuid2, label2, params2) = volume_utils.parse_sr_info(data2)

        self.assertEqual(sr_uuid1, sr_uuid2)
        self.assertEqual(label1, label2)
예제 #3
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)
예제 #4
0
 def _connect_to_volume_provider(self, connection_data, instance_name):
     sr_uuid, sr_label, sr_params = volume_utils.parse_sr_info(connection_data, "Disk-for:%s" % instance_name)
     sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid)
     if not sr_ref:
         # introduce SR because not already present
         sr_ref = volume_utils.introduce_sr(self._session, sr_uuid, sr_label, sr_params)
     return (sr_ref, sr_uuid)
예제 #5
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)
예제 #6
0
 def _connect_to_volume_provider(self, connection_data, instance_name):
     sr_uuid, sr_label, sr_params = volume_utils.parse_sr_info(
             connection_data, 'Disk-for:%s' % instance_name)
     sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid)
     if not sr_ref:
         # introduce SR because not already present
         sr_ref = volume_utils.introduce_sr(
                 self._session, sr_uuid, sr_label, sr_params)
     return (sr_ref, sr_uuid)
예제 #7
0
파일: volumeops.py 프로젝트: ameade/nova
    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 = 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"))
예제 #8
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)
예제 #9
0
    def connect_volume(self, connection_data, dev_number, instance_name,
                       vm_ref):

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

        # 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'))
예제 #10
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)