示例#1
0
    def _test_finish_revert_migration_after_crash(self, backup_made, new_made,
                                                  vm_shutdown=True):
        instance = {'name': 'foo',
                    'task_state': task_states.RESIZE_MIGRATING}
        context = 'fake_context'

        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self._vmops, '_destroy')
        self.mox.StubOutWithMock(vm_utils, 'set_vm_name_label')
        self.mox.StubOutWithMock(self._vmops, '_attach_mapped_block_devices')
        self.mox.StubOutWithMock(self._vmops, '_start')
        self.mox.StubOutWithMock(vm_utils, 'is_vm_shutdown')

        vm_utils.lookup(self._session, 'foo-orig').AndReturn(
            backup_made and 'foo' or None)
        vm_utils.lookup(self._session, 'foo').AndReturn(
            (not backup_made or new_made) and 'foo' or None)
        if backup_made:
            if new_made:
                self._vmops._destroy(instance, 'foo')
            vm_utils.set_vm_name_label(self._session, 'foo', 'foo')
            self._vmops._attach_mapped_block_devices(instance, [])

        vm_utils.is_vm_shutdown(self._session, 'foo').AndReturn(vm_shutdown)
        if vm_shutdown:
            self._vmops._start(instance, 'foo')

        self.mox.ReplayAll()

        self._vmops.finish_revert_migration(context, instance, [])
示例#2
0
    def _test_finish_revert_migration_after_crash(self, backup_made, new_made,
                                                  vm_shutdown=True):
        instance = {'name': 'foo',
                    'task_state': task_states.RESIZE_MIGRATING}
        context = 'fake_context'

        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self._vmops, '_destroy')
        self.mox.StubOutWithMock(vm_utils, 'set_vm_name_label')
        self.mox.StubOutWithMock(self._vmops, '_attach_mapped_block_devices')
        self.mox.StubOutWithMock(self._vmops, '_start')
        self.mox.StubOutWithMock(vm_utils, 'is_vm_shutdown')

        vm_utils.lookup(self._session, 'foo-orig').AndReturn(
            backup_made and 'foo' or None)
        vm_utils.lookup(self._session, 'foo').AndReturn(
            (not backup_made or new_made) and 'foo' or None)
        if backup_made:
            if new_made:
                self._vmops._destroy(instance, 'foo')
            vm_utils.set_vm_name_label(self._session, 'foo', 'foo')
            self._vmops._attach_mapped_block_devices(instance, [])

        vm_utils.is_vm_shutdown(self._session, 'foo').AndReturn(vm_shutdown)
        if vm_shutdown:
            self._vmops._start(instance, 'foo')

        self.mox.ReplayAll()

        self._vmops.finish_revert_migration(context, instance, [])
示例#3
0
    def _test_finish_revert_migration_after_crash(self, backup_made, new_made, vm_shutdown=True):
        instance = {"name": "foo", "task_state": task_states.RESIZE_MIGRATING}

        self.mox.StubOutWithMock(vm_utils, "lookup")
        self.mox.StubOutWithMock(self._vmops, "_destroy")
        self.mox.StubOutWithMock(vm_utils, "set_vm_name_label")
        self.mox.StubOutWithMock(self._vmops, "_attach_mapped_block_devices")
        self.mox.StubOutWithMock(self._vmops, "_start")
        self.mox.StubOutWithMock(vm_utils, "is_vm_shutdown")

        vm_utils.lookup(self._session, "foo-orig").AndReturn(backup_made and "foo" or None)
        vm_utils.lookup(self._session, "foo").AndReturn((not backup_made or new_made) and "foo" or None)
        if backup_made:
            if new_made:
                self._vmops._destroy(instance, "foo")
            vm_utils.set_vm_name_label(self._session, "foo", "foo")
            self._vmops._attach_mapped_block_devices(instance, [])

        vm_utils.is_vm_shutdown(self._session, "foo").AndReturn(vm_shutdown)
        if vm_shutdown:
            self._vmops._start(instance, "foo")

        self.mox.ReplayAll()

        self._vmops.finish_revert_migration(instance, [])
示例#4
0
    def test_get_vm_opaque_ref_raises_instance_not_found(self):
        instance = {"name": "dummy"}
        self.mox.StubOutWithMock(vm_utils, "lookup")
        vm_utils.lookup(self._session, instance["name"], False).AndReturn(None)
        self.mox.ReplayAll()

        self.assertRaises(exception.InstanceNotFound, self._vmops._get_vm_opaque_ref, instance)
示例#5
0
    def test_get_vm_opaque_ref_raises_instance_not_found(self):
        instance = {"name": "dummy"}
        self.mox.StubOutWithMock(vm_utils, 'lookup')
        vm_utils.lookup(self._session, instance['name'], False).AndReturn(None)
        self.mox.ReplayAll()

        self.assertRaises(exception.InstanceNotFound,
                          self._vmops._get_vm_opaque_ref, instance)
示例#6
0
    def test_return_value(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn("vmref")

        mock.ReplayAll()
        self.assertEquals("vmref", vm_utils.vm_ref_or_raise("session", "somename"))
        mock.VerifyAll()
示例#7
0
    def test_lookup_call(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup("session", "somename").AndReturn("ignored")

        mock.ReplayAll()
        vm_utils.vm_ref_or_raise("session", "somename")
        mock.VerifyAll()
示例#8
0
    def test_lookup_call(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn('ignored')

        mock.ReplayAll()
        vm_utils.vm_ref_or_raise('session', 'somename')
        mock.VerifyAll()
示例#9
0
    def test_lookup_call(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn('ignored')

        mock.ReplayAll()
        vm_utils.vm_ref_or_raise('session', 'somename')
        mock.VerifyAll()
示例#10
0
    def test_exception_raised(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup("session", "somename").AndReturn(None)

        mock.ReplayAll()
        self.assertRaises(exception.InstanceNotFound, lambda: vm_utils.vm_ref_or_raise("session", "somename"))
        mock.VerifyAll()
示例#11
0
    def test_return_value(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn('vmref')

        mock.ReplayAll()
        self.assertEquals(
            'vmref', vm_utils.vm_ref_or_raise('session', 'somename'))
        mock.VerifyAll()
示例#12
0
    def test_return_value(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn('vmref')

        mock.ReplayAll()
        self.assertEquals(
            'vmref', vm_utils.vm_ref_or_raise('session', 'somename'))
        mock.VerifyAll()
示例#13
0
    def test_exception_raised(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn(None)

        mock.ReplayAll()
        self.assertRaises(
            exception.InstanceNotFound,
            lambda: vm_utils.vm_ref_or_raise('session', 'somename'))
        mock.VerifyAll()
示例#14
0
    def test_exception_msg_contains_vm_name(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, "lookup")

        vm_utils.lookup("session", "somename").AndReturn(None)

        mock.ReplayAll()
        try:
            vm_utils.vm_ref_or_raise("session", "somename")
        except exception.InstanceNotFound as e:
            self.assertTrue("somename" in str(e))
        mock.VerifyAll()
示例#15
0
    def test_exception_msg_contains_vm_name(self):
        mock = mox.Mox()
        mock.StubOutWithMock(vm_utils, 'lookup')

        vm_utils.lookup('session', 'somename').AndReturn(None)

        mock.ReplayAll()
        try:
            vm_utils.vm_ref_or_raise('session', 'somename')
        except exception.InstanceNotFound as e:
            self.assertTrue('somename' in str(e))
        mock.VerifyAll()
示例#16
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)
示例#17
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)
示例#18
0
文件: vif.py 项目: wingo1990/nova
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])
        if not device:
            device = 0

        if vif['network'].get_meta('should_create_vlan'):
            network_ref = self._ensure_vlan_bridge(vif['network'])
        else:
            network_ref = network_utils.find_network_with_bridge(
                self._session, vif['network']['bridge'])
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['other_config'] = {}
        if vif.get_meta('rxtx_cap'):
            vif_rec['qos_algorithm_type'] = 'ratelimit'
            vif_rec['qos_algorithm_params'] = {
                'kbps': str(int(vif.get_meta('rxtx_cap')) * 1024)
            }
        else:
            vif_rec['qos_algorithm_type'] = ''
            vif_rec['qos_algorithm_params'] = {}
        return vif_rec
示例#19
0
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref,
                      instance=instance)
            return vif_ref

        if not device:
            device = 0

        # with OVS model, always plug into an OVS integration bridge
        # that is already created
        network_ref = network_utils.find_network_with_bridge(
            self._session, CONF.xenserver.ovs_integration_bridge)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        # OVS on the hypervisor monitors this key and uses it to
        # set the iface-id attribute
        vif_rec['other_config'] = {'nicira-iface-id': vif['id']}
        return self._create_vif(vif, vif_rec, vm_ref)
示例#20
0
    def plug(self, instance, vif, vm_ref=None, device=None):
        """create an interim network for this vif; and build
        the vif_rec which will be used by xapi to create VM vif
        """
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref,
                      instance=instance)
            return vif_ref

        if not device:
            device = 0

        # Create an interim network for each VIF, so dom0 has a single
        # bridge for each device (the emulated and PV ethernet devices
        # will both be on this bridge.
        network_ref = self.create_vif_interim_network(vif)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        # OVS on the hypervisor monitors this key and uses it to
        # set the iface-id attribute
        vif_rec['other_config'] = {'nicira-iface-id': vif['id']}
        return self._create_vif(vif, vif_rec, vm_ref)
示例#21
0
 def test_rescue_none(self):
     self.session.call_xenapi(
         "VM.get_by_name_label", self.name_label + '-rescue').AndReturn([])
     self._do_mock(['x'])
     result = vm_utils.lookup(self.session, self.name_label,
                              check_rescue=True)
     self.assertEqual('x', result)
示例#22
0
文件: vif.py 项目: runt18/nova
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref, instance=instance)
            return vif_ref

        if not device:
            device = 0

        # with OVS model, always plug into an OVS integration bridge
        # that is already created
        network_ref = network_utils.find_network_with_bridge(
                self._session, CONF.xenserver.ovs_integration_bridge)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        # OVS on the hypervisor monitors this key and uses it to
        # set the iface-id attribute
        vif_rec['other_config'] = {'nicira-iface-id': vif['id']}
        return self._create_vif(vif, vif_rec, vm_ref)
示例#23
0
 def test_rescue_none(self):
     self.session.call_xenapi(
         "VM.get_by_name_label", self.name_label + '-rescue').AndReturn([])
     self._do_mock(['x'])
     result = vm_utils.lookup(self.session, self.name_label,
                              check_rescue=True)
     self.assertEqual('x', result)
示例#24
0
文件: vif.py 项目: CHOIHEESEOK/nova
    def plug(self, instance, vif, vm_ref=None, device=None):
        """create an interim network for this vif; and build
        the vif_rec which will be used by xapi to create VM vif
        """
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref, instance=instance)
            return vif_ref

        if not device:
            device = 0

        # Create an interim network for each VIF, so dom0 has a single
        # bridge for each device (the emulated and PV ethernet devices
        # will both be on this bridge.
        network_ref = self.create_vif_interim_network(vif)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        # OVS on the hypervisor monitors this key and uses it to
        # set the iface-id attribute
        vif_rec['other_config'] = {'nicira-iface-id': vif['id']}
        return self._create_vif(vif, vif_rec, vm_ref)
示例#25
0
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])
        if not device:
            device = 0

        if vif['network'].get_meta('should_create_vlan'):
            network_ref = self._ensure_vlan_bridge(vif['network'])
        else:
            network_ref = network_utils.find_network_with_bridge(
                    self._session, vif['network']['bridge'])
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['other_config'] = {}
        if vif.get_meta('rxtx_cap'):
            vif_rec['qos_algorithm_type'] = 'ratelimit'
            vif_rec['qos_algorithm_params'] = {'kbps':
                         str(int(vif.get_meta('rxtx_cap')) * 1024)}
        else:
            vif_rec['qos_algorithm_type'] = ''
            vif_rec['qos_algorithm_params'] = {}
        return vif_rec
示例#26
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)
示例#27
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)
示例#28
0
 def test_rescue_found(self):
     self.session.call_xenapi(
         "VM.get_by_name_label",
         self.name_label + '-rescue').AndReturn(['y'])
     self.mox.ReplayAll()
     result = vm_utils.lookup(self.session, self.name_label,
                              check_rescue=True)
     self.assertEqual('y', result)
示例#29
0
 def test_rescue_found(self):
     self.session.call_xenapi(
         "VM.get_by_name_label",
         self.name_label + '-rescue').AndReturn(['y'])
     self.mox.ReplayAll()
     result = vm_utils.lookup(self.session, self.name_label,
                              check_rescue=True)
     self.assertEqual('y', result)
示例#30
0
    def test_sync_power_states_instance_not_found(self):
        db_instance = fake_instance.fake_db_instance()
        ctxt = context.get_admin_context()
        instance_list = instance_obj._make_instance_list(ctxt, instance_obj.InstanceList(), [db_instance], None)
        instance = instance_list[0]

        self.mox.StubOutWithMock(instance_obj.InstanceList, "get_by_host")
        self.mox.StubOutWithMock(self.compute.driver, "get_num_instances")
        self.mox.StubOutWithMock(vm_utils, "lookup")
        self.mox.StubOutWithMock(self.compute, "_sync_instance_power_state")

        instance_obj.InstanceList.get_by_host(ctxt, self.compute.host, use_slave=True).AndReturn(instance_list)
        self.compute.driver.get_num_instances().AndReturn(1)
        vm_utils.lookup(self.compute.driver._session, instance["name"], False).AndReturn(None)
        self.compute._sync_instance_power_state(ctxt, instance, power_state.NOSTATE)

        self.mox.ReplayAll()

        self.compute._sync_power_states(ctxt)
示例#31
0
    def test_sync_power_states_instance_not_found(self):
        db_instance = fake_instance.fake_db_instance()
        ctxt = context.get_admin_context()
        instance_list = instance_obj._make_instance_list(
            ctxt, instance_obj.InstanceList(), [db_instance], None)
        instance = instance_list[0]

        self.mox.StubOutWithMock(instance_obj.InstanceList, 'get_by_host')
        self.mox.StubOutWithMock(self.compute.driver, 'get_num_instances')
        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self.compute, '_sync_instance_power_state')

        instance_obj.InstanceList.get_by_host(
            ctxt, self.compute.host, use_slave=True).AndReturn(instance_list)
        self.compute.driver.get_num_instances().AndReturn(1)
        vm_utils.lookup(self.compute.driver._session, instance['name'],
                        False).AndReturn(None)
        self.compute._sync_instance_power_state(ctxt, instance,
                                                power_state.NOSTATE)

        self.mox.ReplayAll()

        self.compute._sync_power_states(ctxt)
示例#32
0
    def test_sync_power_states_instance_not_found(self):
        db_instance = fake_instance.fake_db_instance()
        ctxt = context.get_admin_context()
        instance_list = instance_obj._make_instance_list(ctxt,
                objects.InstanceList(), [db_instance], None)
        instance = instance_list[0]

        self.mox.StubOutWithMock(objects.InstanceList, 'get_by_host')
        self.mox.StubOutWithMock(self.compute.driver, 'get_num_instances')
        self.mox.StubOutWithMock(vm_utils, 'lookup')
        self.mox.StubOutWithMock(self.compute, '_sync_instance_power_state')

        objects.InstanceList.get_by_host(ctxt,
                self.compute.host, expected_attrs=[],
                use_slave=True).AndReturn(instance_list)
        self.compute.driver.get_num_instances().AndReturn(1)
        vm_utils.lookup(self.compute.driver._session, instance['name'],
                False).AndReturn(None)
        self.compute._sync_instance_power_state(ctxt, instance,
                power_state.NOSTATE)

        self.mox.ReplayAll()

        self.compute._sync_power_states(ctxt)
示例#33
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)

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

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

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

        LOG.debug(connection_info)
        sr_params = {}
        if u'sr_uuid' not in connection_data:
            sr_params = volume_utils.parse_volume_info(connection_data)
            uuid = "FA15E-D15C-" + str(sr_params['id'])
            sr_params['sr_type'] = 'iscsi'
        else:
            uuid = connection_data['sr_uuid']
            for k in connection_data['introduce_sr_keys']:
                sr_params[k] = connection_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'))
示例#34
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'))
示例#35
0
文件: volumeops.py 项目: A7Zulu/nova
 def detach_volume(self, connection_info, instance_name, mountpoint):
     """Detach 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)
     # Detach VBD from VM
     LOG.debug(_("Detach_volume: %(instance_name)s, %(mountpoint)s")
             % locals())
     device_number = volume_utils.mountpoint_to_number(mountpoint)
     try:
         vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref,
                                               device_number)
     except volume_utils.StorageError, exc:
         LOG.exception(exc)
         raise Exception(_('Unable to locate volume %s') % mountpoint)
示例#36
0
 def detach_volume(self, connection_info, instance_name, mountpoint):
     """Detach 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)
     # Detach VBD from VM
     LOG.debug(
         _("Detach_volume: %(instance_name)s, %(mountpoint)s") % locals())
     device_number = volume_utils.mountpoint_to_number(mountpoint)
     try:
         vbd_ref = vm_utils.find_vbd_by_number(self._session, vm_ref,
                                               device_number)
     except volume_utils.StorageError, exc:
         LOG.exception(exc)
         raise Exception(_('Unable to locate volume %s') % mountpoint)
示例#37
0
    def plug(self, instance, vif, vm_ref=None, device=None):
        """create an interim network for this vif; and build
        the vif_rec which will be used by xapi to create VM vif
        """
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])
        if not vm_ref:
            raise exception.VirtualInterfacePlugException(
                "Cannot find instance %s, discard vif plug" % instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref,
                      instance=instance)
            return vif_ref

        if not device:
            device = 0

        # Create an interim network for each VIF, so dom0 has a single
        # bridge for each device (the emulated and PV ethernet devices
        # will both be on this bridge.
        network_ref = self.create_vif_interim_network(vif)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        # Deprecated: 'niciria-iface-id', will remove it in the next release
        vif_rec['other_config'] = {
            'nicira-iface-id': vif['id'],
            'neutron-port-id': vif['id']
        }
        vif_ref = self._create_vif(vif, vif_rec, vm_ref)

        # call XenAPI to plug vif
        self.hot_plug(vif, instance, vm_ref, vif_ref)

        return vif_ref
示例#38
0
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])
        if not vm_ref:
            raise exception.VirtualInterfacePlugException(
                "Cannot find instance %s, discard vif plug" % instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref,
                      instance=instance)
            return vif_ref

        if not device:
            device = 0

        if vif['network'].get_meta('should_create_vlan'):
            network_ref = self._ensure_vlan_bridge(vif['network'])
        else:
            network_ref = network_utils.find_network_with_bridge(
                self._session, vif['network']['bridge'])
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['other_config'] = {}
        if vif.get_meta('rxtx_cap'):
            vif_rec['qos_algorithm_type'] = 'ratelimit'
            vif_rec['qos_algorithm_params'] = {
                'kbps': str(int(vif.get_meta('rxtx_cap')) * 1024)
            }
        else:
            vif_rec['qos_algorithm_type'] = ''
            vif_rec['qos_algorithm_params'] = {}
        return self._create_vif(vif, vif_rec, vm_ref)
示例#39
0
文件: vif.py 项目: arbrandes/nova
    def plug(self, instance, vif, vm_ref=None, device=None):
        """create an interim network for this vif; and build
        the vif_rec which will be used by xapi to create VM vif
        """
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])
        if not vm_ref:
            raise exception.VirtualInterfacePlugException(
                "Cannot find instance %s, discard vif plug" % instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref, instance=instance)
            return vif_ref

        if not device:
            device = 0

        # Create an interim network for each VIF, so dom0 has a single
        # bridge for each device (the emulated and PV ethernet devices
        # will both be on this bridge.
        network_ref = self.create_vif_interim_network(vif)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        vif_rec['other_config'] = {'neutron-port-id': vif['id']}
        vif_ref = self._create_vif(vif, vif_rec, vm_ref)

        # call XenAPI to plug vif
        self.hot_plug(vif, instance, vm_ref, vif_ref)

        return vif_ref
示例#40
0
文件: vif.py 项目: mattstep/nova
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance.name)

        if not device:
            device = 0

        # with OVS model, always plug into an OVS integration bridge
        # that is already created
        network_ref = network_utils.find_network_with_bridge(
            self._session, FLAGS.xenapi_ovs_integration_bridge)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        # OVS on the hypervisor monitors this key and uses it to
        # set the iface-id attribute
        vif_rec['other_config'] = {'nicira-iface-id': vif['id']}
        return vif_rec
示例#41
0
文件: vif.py 项目: A7Zulu/nova
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance.name)

        if not device:
            device = 0

        # with OVS model, always plug into an OVS integration bridge
        # that is already created
        network_ref = network_utils.find_network_with_bridge(
                self._session, FLAGS.xenapi_ovs_integration_bridge)
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['qos_algorithm_type'] = ''
        vif_rec['qos_algorithm_params'] = {}
        # OVS on the hypervisor monitors this key and uses it to
        # set the iface-id attribute
        vif_rec['other_config'] = {'nicira-iface-id': vif['id']}
        return vif_rec
示例#42
0
文件: vif.py 项目: andymcc/nova
    def plug(self, instance, vif, vm_ref=None, device=None):
        if not vm_ref:
            vm_ref = vm_utils.lookup(self._session, instance['name'])
        if not vm_ref:
            raise exception.VirtualInterfacePlugException(
                "Cannot find instance %s, discard vif plug" % instance['name'])

        # if VIF already exists, return this vif_ref directly
        vif_ref = self._get_vif_ref(vif, vm_ref)
        if vif_ref:
            LOG.debug("VIF %s already exists when plug vif",
                      vif_ref, instance=instance)
            return vif_ref

        if not device:
            device = 0

        if vif['network'].get_meta('should_create_vlan'):
            network_ref = self._ensure_vlan_bridge(vif['network'])
        else:
            network_ref = network_utils.find_network_with_bridge(
                    self._session, vif['network']['bridge'])
        vif_rec = {}
        vif_rec['device'] = str(device)
        vif_rec['network'] = network_ref
        vif_rec['VM'] = vm_ref
        vif_rec['MAC'] = vif['address']
        vif_rec['MTU'] = '1500'
        vif_rec['other_config'] = {}
        if vif.get_meta('rxtx_cap'):
            vif_rec['qos_algorithm_type'] = 'ratelimit'
            vif_rec['qos_algorithm_params'] = {'kbps':
                         str(int(vif.get_meta('rxtx_cap')) * 1024)}
        else:
            vif_rec['qos_algorithm_type'] = ''
            vif_rec['qos_algorithm_params'] = {}
        return self._create_vif(vif, vif_rec, vm_ref)
示例#43
0
 def test_no_result(self):
     self._do_mock([])
     result = vm_utils.lookup(self.session, self.name_label)
     self.assertEqual(None, result)
示例#44
0
 def test_normal(self):
     self._do_mock(['x'])
     result = vm_utils.lookup(self.session, self.name_label)
     self.assertEqual('x', result)
示例#45
0
 def test_no_result(self):
     self._do_mock([])
     result = vm_utils.lookup(self.session, self.name_label)
     self.assertEqual(None, result)
示例#46
0
 def test_normal(self):
     self._do_mock(['x'])
     result = vm_utils.lookup(self.session, self.name_label)
     self.assertEqual('x', result)