示例#1
0
    def test_backend_kind_upstream_fix(self, create_pbd):
        session = mock.Mock()
        session.product_version = (7, 0, 0)
        session.call_xenapi.return_value = "sr_ref"
        params = {"sr_type": "iscsi"}
        sr_uuid = "sr_uuid"
        label = "label"
        expected_params = {}

        volume_utils.introduce_sr(session, sr_uuid, label, params)
        session.call_xenapi.assert_any_call("SR.introduce", sr_uuid, label, "", "iscsi", "", False, expected_params)
示例#2
0
    def test_backend_kind_upstream_fix(self, create_pbd):
        session = mock.Mock()
        session.product_version = (7, 0, 0)
        session.call_xenapi.return_value = 'sr_ref'
        params = {'sr_type': 'iscsi'}
        sr_uuid = 'sr_uuid'
        label = 'label'
        expected_params = {}

        volume_utils.introduce_sr(session, sr_uuid, label, params)
        session.call_xenapi.assert_any_call('SR.introduce', sr_uuid,
                                            label, '', 'iscsi',
                                            '', False, expected_params)
示例#3
0
    def test_backend_kind_upstream_fix(self, create_pbd):
        session = mock.Mock()
        session.product_version = (7, 0, 0)
        session.call_xenapi.return_value = 'sr_ref'
        params = {'sr_type': 'iscsi'}
        sr_uuid = 'sr_uuid'
        label = 'label'
        expected_params = {}

        volume_utils.introduce_sr(session, sr_uuid, label, params)
        session.call_xenapi.assert_any_call('SR.introduce', sr_uuid,
                                            label, '', 'iscsi',
                                            '', False, expected_params)
示例#4
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)
示例#5
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)
示例#6
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)
示例#7
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)
示例#8
0
文件: volumeops.py 项目: ameade/nova
 def introduce_sr(self, sr_uuid, label, params):
     LOG.debug(_("Introducing SR %s") % label)
     sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid)
     if sr_ref:
         LOG.debug(_("SR found in xapi database. No need to introduce"))
         return sr_ref
     sr_ref = volume_utils.introduce_sr(self._session, sr_uuid, label, params)
     if sr_ref is None:
         raise exception.NovaException(_("Could not introduce SR"))
     return sr_ref
示例#9
0
 def introduce_sr(self, sr_uuid, label, params):
     LOG.debug(_("Introducing SR %s") % label)
     sr_ref = volume_utils.find_sr_by_uuid(self._session, sr_uuid)
     if sr_ref:
         LOG.debug(_('SR found in xapi database. No need to introduce'))
         return sr_ref
     sr_ref = volume_utils.introduce_sr(self._session, sr_uuid, label,
                                        params)
     if sr_ref is None:
         raise exception.NovaException(_('Could not introduce SR'))
     return sr_ref
示例#10
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)
示例#11
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)