本文整理汇总了Python中nova.db.flavor_get_by_name函数的典型用法代码示例。如果您正苦于以下问题:Python flavor_get_by_name函数的具体用法?Python flavor_get_by_name怎么用?Python flavor_get_by_name使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了flavor_get_by_name函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _sync_flavor
def _sync_flavor(self, ctx, flavor, extra_specs):
"""
Insert the flavor with extra specs if not in local database
"""
flavor_name = self.prefix + flavor.name
try:
db.flavor_get_by_name(ctx, flavor_name)
except exception.FlavorNotFoundByName:
self._insert_pvc_flavor_extraspecs(ctx, flavor, extra_specs)
示例2: test_instance_type_get_by_name_with_extra_specs
def test_instance_type_get_by_name_with_extra_specs(self):
instance_type = db.flavor_get_by_name(
self.context,
"cg1.4xlarge")
self.assertEqual(instance_type['extra_specs'],
self.specs)
instance_type = db.flavor_get_by_name(
self.context,
"m1.small")
self.assertEqual(instance_type['extra_specs'], {})
示例3: test_instance_type_get_by_name_with_extra_specs
def test_instance_type_get_by_name_with_extra_specs(self):
instance_type = db.flavor_get_by_name(
self.context,
"cg1.4xlarge")
self.assertEquals(instance_type['extra_specs'],
dict(cpu_arch="x86_64",
cpu_model="Nehalem",
xpu_arch="fermi",
xpus="2",
xpu_model="Tesla 2050"))
instance_type = db.flavor_get_by_name(
self.context,
"m1.small")
self.assertEquals(instance_type['extra_specs'], {})
示例4: test_spawn_attach_volume_vmdk
def test_spawn_attach_volume_vmdk(self):
self._create_instance_in_the_db()
self.type_data = db.flavor_get_by_name(None, 'm1.large')
self.mox.StubOutWithMock(block_device, 'volume_in_mapping')
self.mox.StubOutWithMock(v_driver, 'block_device_info_get_mapping')
ebs_root = 'fake_root'
block_device.volume_in_mapping(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(ebs_root)
connection_info = self._test_vmdk_connection_info('vmdk')
root_disk = [{'connection_info': connection_info}]
v_driver.block_device_info_get_mapping(
mox.IgnoreArg()).AndReturn(root_disk)
mount_point = '/dev/vdc'
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
'_get_res_pool_of_vm')
volumeops.VMwareVolumeOps._get_res_pool_of_vm(
mox.IgnoreArg()).AndReturn('fake_res_pool')
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
'_relocate_vmdk_volume')
volumeops.VMwareVolumeOps._relocate_vmdk_volume(mox.IgnoreArg(),
'fake_res_pool', mox.IgnoreArg())
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
'attach_volume')
volumeops.VMwareVolumeOps.attach_volume(connection_info,
self.instance, mox.IgnoreArg())
self.mox.ReplayAll()
self.conn.spawn(self.context, self.instance, self.image,
injected_files=[], admin_password=None,
network_info=self.network_info,
block_device_info=None)
示例5: get_by_name
def get_by_name(cls, context, name):
try:
db_flavor = cls._flavor_get_by_name_from_db(context, name)
except exception.FlavorNotFoundByName:
db_flavor = db.flavor_get_by_name(context, name)
return cls._from_db_object(context, cls(context), db_flavor,
expected_attrs=['extra_specs'])
示例6: test_spawn_attach_volume_vmdk
def test_spawn_attach_volume_vmdk(self):
self._create_instance_in_the_db()
self.type_data = db.flavor_get_by_name(None, "m1.large")
self.mox.StubOutWithMock(block_device, "volume_in_mapping")
self.mox.StubOutWithMock(v_driver, "block_device_info_get_mapping")
ebs_root = "fake_root"
block_device.volume_in_mapping(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(ebs_root)
connection_info = self._test_vmdk_connection_info("vmdk")
root_disk = [{"connection_info": connection_info}]
v_driver.block_device_info_get_mapping(mox.IgnoreArg()).AndReturn(root_disk)
mount_point = "/dev/vdc"
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "_get_volume_uuid")
volumeops.VMwareVolumeOps._get_volume_uuid(mox.IgnoreArg(), "volume-fake-id").AndReturn("fake_disk_uuid")
self.mox.StubOutWithMock(vm_util, "get_vmdk_backed_disk_device")
vm_util.get_vmdk_backed_disk_device(mox.IgnoreArg(), "fake_disk_uuid").AndReturn("fake_device")
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "_consolidate_vmdk_volume")
volumeops.VMwareVolumeOps._consolidate_vmdk_volume(
self.instance, mox.IgnoreArg(), "fake_device", mox.IgnoreArg()
)
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "attach_volume")
volumeops.VMwareVolumeOps.attach_volume(connection_info, self.instance, mox.IgnoreArg())
self.mox.ReplayAll()
self.conn.spawn(
self.context,
self.instance,
self.image,
injected_files=[],
admin_password=None,
network_info=self.network_info,
block_device_info=None,
)
示例7: get_flavor_by_name
def get_flavor_by_name(name, ctxt=None):
"""Retrieves single flavor by name."""
if name is None:
return get_default_flavor()
if ctxt is None:
ctxt = context.get_admin_context()
return db.flavor_get_by_name(ctxt, name)
示例8: _create_vm
def _create_vm(self):
"""Create and spawn the VM."""
self._create_instance_in_the_db()
self.type_data = db.flavor_get_by_name(None, 'm1.large')
self.conn.spawn(self.context, self.instance, self.image,
injected_files=[], admin_password=None,
network_info=self.network_info,
block_device_info=None)
self._check_vm_record()
示例9: _create_vm
def _create_vm(self, node=None, num_instances=1):
"""Create and spawn the VM."""
if not node:
node = self.node_name
self._create_instance_in_the_db(node=node)
self.type_data = db.flavor_get_by_name(None, "m1.large")
self.conn.spawn(
self.context,
self.instance,
self.image,
injected_files=[],
admin_password=None,
network_info=self.network_info,
block_device_info=None,
)
self._check_vm_record(num_instances=num_instances)
示例10: test_spawn_attach_volume_iscsi
def test_spawn_attach_volume_iscsi(self):
self._create_instance_in_the_db()
self.type_data = db.flavor_get_by_name(None, 'm1.large')
self.mox.StubOutWithMock(block_device, 'volume_in_mapping')
self.mox.StubOutWithMock(v_driver, 'block_device_info_get_mapping')
connection_info = self._test_vmdk_connection_info('iscsi')
root_disk = [{'connection_info': connection_info}]
v_driver.block_device_info_get_mapping(
mox.IgnoreArg()).AndReturn(root_disk)
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps,
'attach_volume')
volumeops.VMwareVolumeOps.attach_volume(connection_info,
self.instance, mox.IgnoreArg())
self.mox.ReplayAll()
block_device_info = {'mount_device': 'vda'}
self.conn.spawn(self.context, self.instance, self.image,
injected_files=[], admin_password=None,
network_info=self.network_info,
block_device_info=block_device_info)
示例11: _sync_flavor
def _sync_flavor(self, ctx, flavor, extra_specs):
"""
Insert the flavor with extra specs if not in local database
"""
flavor_in_local_db = None
flavor_name = self.prefix + flavor.name
try:
flavor_in_local_db = db.flavor_get_by_name(ctx, flavor_name)
except exception.FlavorNotFoundByName:
self._insert_pvc_flavor_extraspecs(ctx, flavor, extra_specs)
# Update the extra_speces of the flavor
if flavor_in_local_db is not None:
flavor_id = flavor_in_local_db.get('flavorid', '')
if (flavor_id is not ''
and extra_specs):
self._update_flavor_extraspecs(ctx,
flavor_id,
extra_specs)
示例12: test_spawn_attach_volume_iscsi
def test_spawn_attach_volume_iscsi(self):
self._create_instance_in_the_db()
self.type_data = db.flavor_get_by_name(None, "m1.large")
self.mox.StubOutWithMock(block_device, "volume_in_mapping")
self.mox.StubOutWithMock(v_driver, "block_device_info_get_mapping")
ebs_root = "fake_root"
block_device.volume_in_mapping(mox.IgnoreArg(), mox.IgnoreArg()).AndReturn(ebs_root)
connection_info = self._test_vmdk_connection_info("iscsi")
root_disk = [{"connection_info": connection_info}]
v_driver.block_device_info_get_mapping(mox.IgnoreArg()).AndReturn(root_disk)
self.mox.StubOutWithMock(volumeops.VMwareVolumeOps, "attach_volume")
volumeops.VMwareVolumeOps.attach_volume(connection_info, self.instance, mox.IgnoreArg())
self.mox.ReplayAll()
self.conn.spawn(
self.context,
self.instance,
self.image,
injected_files=[],
admin_password=None,
network_info=self.network_info,
block_device_info=None,
)
示例13: get_by_name
def get_by_name(cls, context, name):
db_flavor = db.flavor_get_by_name(context, name)
return cls._from_db_object(context, cls(), db_flavor,
expected_attrs=['extra_specs'])
示例14: _setup_test_migrate_disk_and_power_off_mocks
def _setup_test_migrate_disk_and_power_off_mocks(self, same_host=False, copy_exception=False, size_exception=False):
self._instance_data = self._get_instance_data()
instance = db.instance_create(self._context, self._instance_data)
network_info = fake_network.fake_get_instance_nw_info(self.stubs, spectacular=True)
instance["root_gb"] = 10
fake_local_ip = "10.0.0.1"
if same_host:
fake_dest_ip = fake_local_ip
else:
fake_dest_ip = "10.0.0.2"
if size_exception:
flavor = "m1.tiny"
else:
flavor = "m1.small"
instance_type = db.flavor_get_by_name(self._context, flavor)
if not size_exception:
fake_root_vhd_path = "C:\\FakePath\\root.vhd"
fake_revert_path = os.path.join(self._test_instance_dir, "_revert")
func = mox.Func(self._check_instance_name)
vmutils.VMUtils.set_vm_state(func, constants.HYPERV_VM_STATE_DISABLED)
m = vmutils.VMUtils.get_vm_storage_paths(func)
m.AndReturn(([fake_root_vhd_path], []))
m = hostutils.HostUtils.get_local_ips()
m.AndReturn([fake_local_ip])
m = fake.PathUtils.get_instance_dir(mox.IsA(str))
m.AndReturn(self._test_instance_dir)
m = pathutils.PathUtils.get_instance_migr_revert_dir(instance["name"], remove_dir=True)
m.AndReturn(fake_revert_path)
if same_host:
fake.PathUtils.makedirs(mox.IsA(str))
m = fake.PathUtils.copy(fake_root_vhd_path, mox.IsA(str))
if copy_exception:
m.AndRaise(shutil.Error("Simulated copy error"))
m = fake.PathUtils.get_instance_dir(mox.IsA(str), mox.IsA(str), remove_dir=True)
m.AndReturn(self._test_instance_dir)
else:
fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
destroy_disks = True
if same_host:
fake.PathUtils.rename(mox.IsA(str), mox.IsA(str))
destroy_disks = False
self._setup_destroy_mocks(False)
if destroy_disks:
m = fake.PathUtils.get_instance_dir(mox.IsA(str), mox.IsA(str), remove_dir=True)
m.AndReturn(self._test_instance_dir)
return (instance, fake_dest_ip, network_info, instance_type)
示例15: _setup_test_migrate_disk_and_power_off_mocks
def _setup_test_migrate_disk_and_power_off_mocks(self, same_host=False,
copy_exception=False,
size_exception=False):
self._instance = self._get_instance()
network_info = fake_network.fake_get_instance_nw_info(self.stubs)
self._instance['root_gb'] = 10
fake_local_ip = '10.0.0.1'
if same_host:
fake_dest_ip = fake_local_ip
else:
fake_dest_ip = '10.0.0.2'
if size_exception:
flavor = 'm1.tiny'
else:
flavor = 'm1.small'
flavor = db.flavor_get_by_name(self._context, flavor)
flavor = fake_flavor.fake_flavor_obj(self._context, **flavor)
if not size_exception:
fake_root_vhd_path = 'C:\\FakePath\\root.vhd'
fake_revert_path = os.path.join(self._test_instance_dir, '_revert')
func = mox.Func(self._check_instance_name)
vmutils.VMUtils.set_vm_state(func,
constants.HYPERV_VM_STATE_DISABLED)
self._setup_delete_vm_log_mocks()
m = vmutils.VMUtils.get_vm_storage_paths(func)
m.AndReturn(([fake_root_vhd_path], []))
m = hostutils.HostUtils.get_local_ips()
m.AndReturn([fake_local_ip])
m = fake.PathUtils.get_instance_dir(mox.IsA(str))
m.AndReturn(self._test_instance_dir)
m = pathutils.PathUtils.get_instance_migr_revert_dir(
self._instance.name, remove_dir=True, create_dir=True)
m.AndReturn(fake_revert_path)
if same_host:
fake.PathUtils.makedirs(mox.IsA(str))
m = fake.PathUtils.copy(fake_root_vhd_path, mox.IsA(str))
if copy_exception:
m.AndRaise(shutil.Error('Simulated copy error'))
m = fake.PathUtils.get_instance_dir(mox.IsA(str),
mox.IsA(str),
remove_dir=True)
m.AndReturn(self._test_instance_dir)
else:
fake.PathUtils.move_folder_files(mox.IsA(str),
mox.IsA(str))
destroy_disks = True
if same_host:
fake.PathUtils.move_folder_files(mox.IsA(str),
mox.IsA(str))
destroy_disks = False
self._setup_destroy_mocks(False)
if destroy_disks:
m = fake.PathUtils.get_instance_dir(mox.IsA(str),
mox.IsA(str),
remove_dir=True)
m.AndReturn(self._test_instance_dir)
return (self._instance, fake_dest_ip, network_info, flavor)