예제 #1
0
    def test_no_admin_pass(self):
        # This is here to avoid masking errors, it shouldn't be used normally
        self.useFixture(fixtures.MonkeyPatch("nova.virt.xenapi.vm_utils.destroy_vdi", _fake_noop))

        # Mocks
        instance = {}

        self.mox.StubOutWithMock(vm_utils, "safe_find_sr")
        vm_utils.safe_find_sr("session").AndReturn("sr_ref")

        self.mox.StubOutWithMock(vm_utils, "create_vdi")
        vm_utils.create_vdi("session", "sr_ref", instance, "config-2", "configdrive", 64 * 1024 * 1024).AndReturn(
            "vdi_ref"
        )

        self.mox.StubOutWithMock(vm_utils, "vdi_attached_here")
        vm_utils.vdi_attached_here("session", "vdi_ref", read_only=False).AndReturn(contextified("mounted_dev"))

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch("nova.api.metadata.base.InstanceMetadata", FakeInstanceMetadata))

        self.mox.StubOutWithMock(utils, "execute")
        utils.execute(
            "genisoimage",
            "-o",
            mox.IgnoreArg(),
            "-ldots",
            "-allow-lowercase",
            "-allow-multidot",
            "-l",
            "-publisher",
            mox.IgnoreArg(),
            "-quiet",
            "-J",
            "-r",
            "-V",
            "config-2",
            mox.IgnoreArg(),
            attempts=1,
            run_as_root=False,
        ).AndReturn(None)
        utils.execute("dd", mox.IgnoreArg(), mox.IgnoreArg(), run_as_root=True).AndReturn(None)

        self.mox.StubOutWithMock(vm_utils, "create_vbd")
        vm_utils.create_vbd("session", "vm_ref", "vdi_ref", mox.IgnoreArg(), bootable=False, read_only=True).AndReturn(
            None
        )

        self.mox.ReplayAll()

        # And the actual call we're testing
        vm_utils.generate_configdrive("session", instance, "vm_ref", "userdevice")
예제 #2
0
    def test_attach_cd(self):
        self.mock.StubOutWithMock(vm_utils, 'create_vbd')

        vm_utils.create_vbd(self.session, "vm_ref", None, 1,
                vbd_type='cd', read_only=True, bootable=True,
                empty=True, unpluggable=False).AndReturn("vbd_ref")
        self.session.call_xenapi('VBD.insert', "vbd_ref", "vdi_ref")
        self.mock.ReplayAll()

        result = vm_utils.attach_cd(self.session, "vm_ref", "vdi_ref", 1)
        self.assertEquals(result, "vbd_ref")
        self.mock.VerifyAll()
예제 #3
0
    def test_attach_cd(self):
        self.mock.StubOutWithMock(vm_utils, 'create_vbd')

        vm_utils.create_vbd(self.session, "vm_ref", None, 1,
                vbd_type='cd', read_only=True, bootable=True,
                empty=True, unpluggable=False).AndReturn("vbd_ref")
        self.session.call_xenapi('VBD.insert', "vbd_ref", "vdi_ref")
        self.mock.ReplayAll()

        result = vm_utils.attach_cd(self.session, "vm_ref", "vdi_ref", 1)
        self.assertEquals(result, "vbd_ref")
        self.mock.VerifyAll()
예제 #4
0
    def test_attach_orig_disk_for_rescue(self):
        instance = {"name": "dummy"}
        vm_ref = "vm_ref"

        self.mox.StubOutWithMock(vm_utils, "lookup")
        self.mox.StubOutWithMock(self.vmops, "_find_root_vdi_ref")
        self.mox.StubOutWithMock(vm_utils, "create_vbd")

        vm_utils.lookup(self.vmops._session, "dummy").AndReturn("ref")
        self.vmops._find_root_vdi_ref("ref").AndReturn("vdi_ref")
        vm_utils.create_vbd(self.vmops._session, vm_ref, "vdi_ref", vmops.DEVICE_RESCUE, bootable=False)

        self.mox.ReplayAll()
        self.vmops._attach_orig_disk_for_rescue(instance, vm_ref)
예제 #5
0
    def test_no_admin_pass(self):
        # This is here to avoid masking errors, it shouldn't be used normally
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.xenapi.vm_utils.destroy_vdi', _fake_noop))

        # Mocks
        instance = {}

        self.mox.StubOutWithMock(vm_utils, 'safe_find_sr')
        vm_utils.safe_find_sr('session').AndReturn('sr_ref')

        self.mox.StubOutWithMock(vm_utils, 'create_vdi')
        vm_utils.create_vdi('session', 'sr_ref', instance, 'config-2',
                            'configdrive',
                            64 * 1024 * 1024).AndReturn('vdi_ref')

        self.mox.StubOutWithMock(vm_utils, 'vdi_attached_here')
        vm_utils.vdi_attached_here(
            'session', 'vdi_ref', read_only=False).AndReturn(
                contextified('mounted_dev'))

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch(
                'nova.api.metadata.base.InstanceMetadata',
                FakeInstanceMetadata))

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('genisoimage', '-o', mox.IgnoreArg(), '-ldots',
                      '-allow-lowercase', '-allow-multidot', '-l',
                      '-publisher', mox.IgnoreArg(), '-quiet',
                      '-J', '-r', '-V', 'config-2', mox.IgnoreArg(),
                      attempts=1, run_as_root=False).AndReturn(None)
        utils.execute('dd', mox.IgnoreArg(), mox.IgnoreArg(),
                      run_as_root=True).AndReturn(None)

        self.mox.StubOutWithMock(vm_utils, 'create_vbd')
        vm_utils.create_vbd('session', 'vm_ref', 'vdi_ref', mox.IgnoreArg(),
                            bootable=False, read_only=True).AndReturn(None)

        self.mox.ReplayAll()

        # And the actual call we're testing
        vm_utils.generate_configdrive('session', instance, 'vm_ref',
                                      'userdevice')
예제 #6
0
    def test_no_admin_pass(self):
        # This is here to avoid masking errors, it shouldn't be used normally
        self.useFixture(fixtures.MonkeyPatch(
                'nova.virt.xenapi.vm_utils.destroy_vdi', _fake_noop))

        # Mocks
        instance = {}

        self.mox.StubOutWithMock(vm_utils, 'safe_find_sr')
        vm_utils.safe_find_sr('session').AndReturn('sr_ref')

        self.mox.StubOutWithMock(vm_utils, 'create_vdi')
        vm_utils.create_vdi('session', 'sr_ref', instance, 'config-2',
                            'configdrive',
                            64 * 1024 * 1024).AndReturn('vdi_ref')

        self.mox.StubOutWithMock(vm_utils, 'vdi_attached_here')
        vm_utils.vdi_attached_here(
            'session', 'vdi_ref', read_only=False).AndReturn(
                contextified('mounted_dev'))

        class FakeInstanceMetadata(object):
            def __init__(self, instance, content=None, extra_md=None):
                pass

            def metadata_for_config_drive(self):
                return []

        self.useFixture(fixtures.MonkeyPatch(
                'nova.api.metadata.base.InstanceMetadata',
                FakeInstanceMetadata))

        self.mox.StubOutWithMock(utils, 'execute')
        utils.execute('genisoimage', '-o', mox.IgnoreArg(), '-ldots',
                      '-allow-lowercase', '-allow-multidot', '-l',
                      '-publisher', mox.IgnoreArg(), '-quiet',
                      '-J', '-r', '-V', 'config-2', mox.IgnoreArg(),
                      attempts=1, run_as_root=False).AndReturn(None)
        utils.execute('dd', mox.IgnoreArg(), mox.IgnoreArg(),
                      run_as_root=True).AndReturn(None)

        self.mox.StubOutWithMock(vm_utils, 'create_vbd')
        vm_utils.create_vbd('session', 'vm_ref', 'vdi_ref', mox.IgnoreArg(),
                            bootable=False, read_only=True).AndReturn(None)

        self.mox.ReplayAll()

        # And the actual call we're testing
        vm_utils.generate_configdrive('session', instance, 'vm_ref',
                                      'userdevice')
예제 #7
0
    def test_attach_orig_disk_for_rescue(self):
        instance = {"name": "dummy"}
        vm_ref = "vm_ref"

        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self.vmops, '_find_root_vdi_ref')
        self.mox.StubOutWithMock(vm_utils, 'create_vbd')

        vm_utils.lookup(self.vmops._session, "dummy").AndReturn("ref")
        self.vmops._find_root_vdi_ref("ref").AndReturn("vdi_ref")
        vm_utils.create_vbd(self.vmops._session, vm_ref, "vdi_ref",
                            vmops.DEVICE_RESCUE, bootable=False)

        self.mox.ReplayAll()
        self.vmops._attach_orig_disk_for_rescue(instance, vm_ref)
예제 #8
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)
예제 #9
0
 def test_create_vbd_osvol(self):
     self.session.call_xenapi("VBD.create", self.vbd_rec).AndReturn("vbd_ref")
     self.session.call_xenapi("VBD.add_to_other_config", "vbd_ref", "osvol", "True")
     self.mock.ReplayAll()
     result = vm_utils.create_vbd(self.session, "vm_ref", "vdi_ref", 0, osvol=True)
     self.assertEquals(result, "vbd_ref")
     self.mock.VerifyAll()
예제 #10
0
    def test_create_vbd_default_args(self):
        self.session.call_xenapi("VBD.create", self.vbd_rec).AndReturn("vbd_ref")
        self.mock.ReplayAll()

        result = vm_utils.create_vbd(self.session, "vm_ref", "vdi_ref", 0)
        self.assertEquals(result, "vbd_ref")
        self.mock.VerifyAll()
예제 #11
0
    def _attach_volume_to_vm(self, vdi_ref, vm_ref, instance_name, mountpoint,
                             hotplug):
        LOG.debug('Attach_volume vdi: %(vdi_ref)s vm: %(vm_ref)s', {
            'vdi_ref': vdi_ref,
            'vm_ref': vm_ref
        })

        dev_number = volume_utils.get_device_number(mountpoint)

        # osvol is added to the vbd so we can spot which vbds are volumes
        vbd_ref = vm_utils.create_vbd(self._session,
                                      vm_ref,
                                      vdi_ref,
                                      dev_number,
                                      bootable=False,
                                      osvol=True)
        if hotplug:
            # NOTE(johngarbutt) can only call VBD.plug on a running vm
            running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
            if running:
                LOG.debug("Plugging VBD: %s", vbd_ref)
                self._session.VBD.plug(vbd_ref, vm_ref)

        LOG.info(
            _LI('Dev %(dev_number)s attached to'
                ' instance %(instance_name)s'), {
                    'instance_name': instance_name,
                    'dev_number': dev_number
                })
예제 #12
0
    def test_attach_orig_disks(self):
        instance = {"name": "dummy"}
        vm_ref = "vm_ref"
        vbd_refs = {vmops.DEVICE_ROOT: "vdi_ref"}

        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self.vmops, '_find_vdi_refs')
        self.mox.StubOutWithMock(vm_utils, 'create_vbd')

        vm_utils.lookup(self.vmops._session, "dummy").AndReturn("ref")
        self.vmops._find_vdi_refs("ref", exclude_volumes=True).AndReturn(
                vbd_refs)
        vm_utils.create_vbd(self.vmops._session, vm_ref, "vdi_ref",
                            vmops.DEVICE_RESCUE, bootable=False)

        self.mox.ReplayAll()
        self.vmops._attach_orig_disks(instance, vm_ref)
예제 #13
0
    def test_create_vbd_default_args(self):
        self.session.call_xenapi('VBD.create',
                self.vbd_rec).AndReturn("vbd_ref")
        self.mock.ReplayAll()

        result = vm_utils.create_vbd(self.session, "vm_ref", "vdi_ref", 0)
        self.assertEquals(result, "vbd_ref")
        self.mock.VerifyAll()
예제 #14
0
    def test_attach_orig_disks(self):
        instance = {"name": "dummy"}
        vm_ref = "vm_ref"
        vbd_refs = {vmops.DEVICE_ROOT: "vdi_ref"}

        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self.vmops, '_find_vdi_refs')
        self.mox.StubOutWithMock(vm_utils, 'create_vbd')

        vm_utils.lookup(self.vmops._session, "dummy").AndReturn("ref")
        self.vmops._find_vdi_refs("ref", exclude_volumes=True).AndReturn(
                vbd_refs)
        vm_utils.create_vbd(self.vmops._session, vm_ref, "vdi_ref",
                            vmops.DEVICE_RESCUE, bootable=False)

        self.mox.ReplayAll()
        self.vmops._attach_orig_disks(instance, vm_ref)
예제 #15
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)
예제 #16
0
 def test_create_vbd_osvol(self):
     self.session.call_xenapi('VBD.create',
             self.vbd_rec).AndReturn("vbd_ref")
     self.session.call_xenapi('VBD.add_to_other_config', "vbd_ref",
                              "osvol", "True")
     self.mock.ReplayAll()
     result = vm_utils.create_vbd(self.session, "vm_ref", "vdi_ref", 0,
                                  osvol=True)
     self.assertEquals(result, "vbd_ref")
     self.mock.VerifyAll()
예제 #17
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)
예제 #18
0
    def test_create_vbd_extra_args(self):
        self.vbd_rec["VDI"] = "OpaqueRef:NULL"
        self.vbd_rec["type"] = "a"
        self.vbd_rec["mode"] = "RO"
        self.vbd_rec["bootable"] = True
        self.vbd_rec["empty"] = True
        self.vbd_rec["unpluggable"] = False
        self.session.call_xenapi("VBD.create", self.vbd_rec).AndReturn("vbd_ref")
        self.mock.ReplayAll()

        result = vm_utils.create_vbd(
            self.session, "vm_ref", None, 0, vbd_type="a", read_only=True, bootable=True, empty=True, unpluggable=False
        )
        self.assertEquals(result, "vbd_ref")
        self.mock.VerifyAll()
예제 #19
0
    def test_create_vbd_extra_args(self):
        self.vbd_rec['VDI'] = 'OpaqueRef:NULL'
        self.vbd_rec['type'] = 'a'
        self.vbd_rec['mode'] = 'RO'
        self.vbd_rec['bootable'] = True
        self.vbd_rec['empty'] = True
        self.vbd_rec['unpluggable'] = False
        self.session.call_xenapi('VBD.create',
                self.vbd_rec).AndReturn("vbd_ref")
        self.mock.ReplayAll()

        result = vm_utils.create_vbd(self.session, "vm_ref", None, 0,
                vbd_type="a", read_only=True, bootable=True,
                empty=True, unpluggable=False)
        self.assertEquals(result, "vbd_ref")
        self.mock.VerifyAll()
예제 #20
0
    def test_create_vbd_extra_args(self):
        self.vbd_rec['VDI'] = 'OpaqueRef:NULL'
        self.vbd_rec['type'] = 'a'
        self.vbd_rec['mode'] = 'RO'
        self.vbd_rec['bootable'] = True
        self.vbd_rec['empty'] = True
        self.vbd_rec['unpluggable'] = False
        self.session.call_xenapi('VBD.create',
                self.vbd_rec).AndReturn("vbd_ref")
        self.mock.ReplayAll()

        result = vm_utils.create_vbd(self.session, "vm_ref", None, 0,
                vbd_type="a", read_only=True, bootable=True,
                empty=True, unpluggable=False)
        self.assertEquals(result, "vbd_ref")
        self.mock.VerifyAll()
예제 #21
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)
예제 #22
0
    def _attach_volume_to_vm(self, vdi_ref, vm_ref, instance_name, dev_number, hotplug):
        msg = _("Attach_volume vdi: %(vdi_ref)s vm: %(vm_ref)s")
        LOG.debug(msg, {"vdi_ref": vdi_ref, "vm_ref": vm_ref})

        # osvol is added to the vbd so we can spot which vbds are volumes
        vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref, dev_number, bootable=False, osvol=True)
        if hotplug:
            # NOTE(johngarbutt) can only call VBD.plug on a running vm
            running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
            if running:
                LOG.debug("Plugging VBD: %s", vbd_ref)
                self._session.VBD.plug(vbd_ref, vm_ref)

        LOG.info(
            _("Dev %(dev_number)s attached to" " instance %(instance_name)s"),
            {"instance_name": instance_name, "dev_number": dev_number},
        )
예제 #23
0
    def _attach_volume_to_vm(self, vdi_ref, vm_ref, instance_name, dev_number,
                             hotplug):
        LOG.debug('Attach_volume vdi: %(vdi_ref)s vm: %(vm_ref)s',
                  {'vdi_ref': vdi_ref, 'vm_ref': vm_ref})

        # osvol is added to the vbd so we can spot which vbds are volumes
        vbd_ref = vm_utils.create_vbd(self._session, vm_ref, vdi_ref,
                                      dev_number, bootable=False,
                                      osvol=True)
        if hotplug:
            # NOTE(johngarbutt) can only call VBD.plug on a running vm
            running = not vm_utils.is_vm_shutdown(self._session, vm_ref)
            if running:
                LOG.debug("Plugging VBD: %s", vbd_ref)
                self._session.VBD.plug(vbd_ref, vm_ref)

        LOG.info(_LI('Dev %(dev_number)s attached to'
                     ' instance %(instance_name)s'),
                 {'instance_name': instance_name, 'dev_number': dev_number})
예제 #24
0
파일: volumeops.py 프로젝트: A7Zulu/nova
        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())

        try:
            self._session.call_xenapi("VBD.plug", vbd_ref)
        except self.XenAPI.Failure, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(_('Unable to attach volume to instance %s')
                            % instance_name)

        LOG.info(_('Mountpoint %(mountpoint)s attached to'
예제 #25
0
        # 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:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(
                _('Unable to use SR %(sr_ref)s for'
                  ' instance %(instance_name)s') % locals())

        try:
            self._session.call_xenapi("VBD.plug", vbd_ref)
        except self._session.XenAPI.Failure, exc:
            LOG.exception(exc)
            self.forget_sr(uuid)
            raise Exception(