本文整理汇总了Python中nova.compute.flavors.get_default_flavor函数的典型用法代码示例。如果您正苦于以下问题:Python get_default_flavor函数的具体用法?Python get_default_flavor怎么用?Python get_default_flavor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_default_flavor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_count_members_by_user
def test_count_members_by_user(self):
instance1 = tests_utils.get_test_instance(self.context,
flavor=flavors.get_default_flavor(), obj=True)
instance1.user_id = 'user1'
instance1.save()
instance2 = tests_utils.get_test_instance(self.context,
flavor=flavors.get_default_flavor(), obj=True)
instance2.user_id = 'user2'
instance2.save()
instance3 = tests_utils.get_test_instance(self.context,
flavor=flavors.get_default_flavor(), obj=True)
instance3.user_id = 'user2'
instance3.save()
instance_ids = [instance1.uuid, instance2.uuid, instance3.uuid]
values = self._get_default_values()
group = self._create_instance_group(self.context, values)
instance_group.InstanceGroup.add_members(self.context, group.uuid,
instance_ids)
group = instance_group.InstanceGroup.get_by_uuid(self.context,
group.uuid)
count_user1 = group.count_members_by_user(self.context, 'user1')
count_user2 = group.count_members_by_user(self.context, 'user2')
count_user3 = group.count_members_by_user(self.context, 'user3')
self.assertEqual(1, count_user1)
self.assertEqual(2, count_user2)
self.assertEqual(0, count_user3)
示例2: test_get_hosts
def test_get_hosts(self):
instance1 = tests_utils.get_test_instance(self.context,
flavor=flavors.get_default_flavor(), obj=True)
instance1.host = 'hostA'
instance1.save()
instance2 = tests_utils.get_test_instance(self.context,
flavor=flavors.get_default_flavor(), obj=True)
instance2.host = 'hostB'
instance2.save()
instance3 = tests_utils.get_test_instance(self.context,
flavor=flavors.get_default_flavor(), obj=True)
instance3.host = 'hostB'
instance3.save()
instance_ids = [instance1.uuid, instance2.uuid, instance3.uuid]
values = self._get_default_values()
group = self._create_instance_group(self.context, values)
instance_group.InstanceGroup.add_members(self.context, group.uuid,
instance_ids)
group = instance_group.InstanceGroup.get_by_uuid(self.context,
group.uuid)
hosts = group.get_hosts(self.context)
self.assertEqual(2, len(hosts))
self.assertIn('hostA', hosts)
self.assertIn('hostB', hosts)
hosts = group.get_hosts(self.context, exclude=[instance1.uuid])
self.assertEqual(1, len(hosts))
self.assertIn('hostB', hosts)
示例3: test_allocate_for_instance_handles_macs_passed
def test_allocate_for_instance_handles_macs_passed(self):
# If a macs argument is supplied to the 'nova-network' API, it is just
# ignored. This test checks that the call down to the rpcapi layer
# doesn't pass macs down: nova-network doesn't support hypervisor
# mac address limits (today anyhow).
macs = set(["ab:cd:ef:01:23:34"])
with mock.patch.object(self.network_api.network_rpcapi, "allocate_for_instance") as mock_alloc:
kwargs = dict(
zip(
[
"host",
"instance_id",
"project_id",
"requested_networks",
"rxtx_factor",
"vpn",
"macs",
"dhcp_options",
],
itertools.repeat(mock.ANY),
)
)
mock_alloc.return_value = []
flavor = flavors.get_default_flavor()
flavor["rxtx_factor"] = 0
instance = objects.Instance(
id=1, uuid=uuids.instance, project_id="project_id", host="host", system_metadata={}, flavor=flavor
)
self.network_api.allocate_for_instance(self.context, instance, "vpn", requested_networks=None, macs=macs)
mock_alloc.assert_called_once_with(self.context, **kwargs)
示例4: fake_instance_create
def fake_instance_create(context, inst_, session=None):
inst = fake_instance.fake_db_instance(
**{
"id": 1,
"uuid": AUTO_INSTANCE_UUID,
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"progress": 0,
"name": "instance-1", # this is a property
"task_state": "",
"vm_state": "",
"auto_disk_config": inst_["auto_disk_config"],
"security_groups": inst_["security_groups"],
"instance_type": flavors.get_default_flavor(),
}
)
def fake_instance_get_for_create(context, id_, *args, **kwargs):
return (inst, inst)
self.stubs.Set(db, "instance_update_and_get_original", fake_instance_get_for_create)
def fake_instance_get_all_for_create(context, *args, **kwargs):
return [inst]
self.stubs.Set(db, "instance_get_all", fake_instance_get_all_for_create)
self.stubs.Set(db, "instance_get_all_by_filters", fake_instance_get_all_for_create)
def fake_instance_add_security_group(context, instance_id, security_group_id):
pass
self.stubs.Set(db, "instance_add_security_group", fake_instance_add_security_group)
return inst
示例5: test_flavor_get_by_None_name_returns_default
def test_flavor_get_by_None_name_returns_default(self):
# Ensure get by name returns default flavor with no name.
default = flavors.get_default_flavor()
actual = flavors.get_flavor_by_name(None)
self.assertIsInstance(default, objects.Flavor)
self.assertIsInstance(actual, objects.Flavor)
self.assertEqual(default.flavorid, actual.flavorid)
示例6: setUp
def setUp(self):
super(SimpleTenantUsageControllerTest, self).setUp()
self.controller = simple_tenant_usage.SimpleTenantUsageController()
class FakeComputeAPI:
def get_instance_type(self, context, flavor_type):
if flavor_type == 1:
return flavors.get_default_flavor()
else:
raise exception.InstanceTypeNotFound(flavor_type)
self.compute_api = FakeComputeAPI()
self.context = None
now = timeutils.utcnow()
self.baseinst = dict(display_name='foo',
launched_at=now - datetime.timedelta(1),
terminated_at=now,
instance_type_id=1,
vm_state='deleted',
deleted=0)
basetype = flavors.get_default_flavor()
sys_meta = utils.dict_to_metadata(
flavors.save_flavor_info({}, basetype))
self.baseinst['system_metadata'] = sys_meta
self.basetype = flavors.extract_flavor(self.baseinst)
示例7: fake_inst_obj
def fake_inst_obj(context):
inst = objects.Instance(
context=context,
id=1,
user_id="fake_user",
uuid="b65cee2f-8c69-4aeb-be2f-f79742548fc2",
project_id="test",
key_name="key",
key_data="ssh-rsa AAAAB3Nzai....N3NtHw== [email protected]",
host="test",
launch_index=1,
reservation_id="r-xxxxxxxx",
user_data=ENCODE_USER_DATA_STRING,
image_ref=7,
vcpus=1,
fixed_ips=[],
root_device_name="/dev/sda1",
hostname="test.novadomain",
display_name="my_displayname",
metadata={},
default_ephemeral_device=None,
default_swap_device=None,
system_metadata={},
)
nwinfo = network_model.NetworkInfo([])
inst.info_cache = objects.InstanceInfoCache(context=context, instance_uuid=inst.uuid, network_info=nwinfo)
with mock.patch.object(inst, "save"):
inst.set_flavor(flavors.get_default_flavor())
return inst
示例8: test_delete_flavor_info
def test_delete_flavor_info(self):
instance_type = flavors.get_default_flavor()
metadata = {}
flavors.save_flavor_info(metadata, instance_type)
flavors.save_flavor_info(metadata, instance_type, '_')
flavors.delete_flavor_info(metadata, '', '_')
self.assertEqual(metadata, {})
示例9: test_allocate_for_instance_handles_macs_passed
def test_allocate_for_instance_handles_macs_passed(self):
# If a macs argument is supplied to the 'nova-network' API, it is just
# ignored. This test checks that the call down to the rpcapi layer
# doesn't pass macs down: nova-network doesn't support hypervisor
# mac address limits (today anyhow).
macs = set(['ab:cd:ef:01:23:34'])
self.mox.StubOutWithMock(self.network_api.network_rpcapi,
"allocate_for_instance")
kwargs = dict(
zip([
'host', 'instance_id', 'project_id', 'requested_networks',
'rxtx_factor', 'vpn', 'macs', 'dhcp_options'
], itertools.repeat(mox.IgnoreArg())))
self.network_api.network_rpcapi.allocate_for_instance(
mox.IgnoreArg(), **kwargs).AndReturn([])
self.mox.ReplayAll()
flavor = flavors.get_default_flavor()
flavor['rxtx_factor'] = 0
instance = objects.Instance(
id=1,
uuid='uuid',
project_id='project_id',
host='host',
system_metadata={},
flavor=flavor)
self.network_api.allocate_for_instance(
self.context, instance, 'vpn', 'requested_networks', macs=macs)
示例10: test_allocate_for_instance_handles_macs_passed
def test_allocate_for_instance_handles_macs_passed(self):
# If a macs argument is supplied to the 'nova-network' API, it is just
# ignored. This test checks that the call down to the rpcapi layer
# doesn't pass macs down: nova-network doesn't support hypervisor
# mac address limits (today anyhow).
macs = set(["ab:cd:ef:01:23:34"])
self.mox.StubOutWithMock(self.network_api.network_rpcapi, "allocate_for_instance")
kwargs = dict(
zip(
[
"host",
"instance_id",
"project_id",
"requested_networks",
"rxtx_factor",
"vpn",
"macs",
"dhcp_options",
],
itertools.repeat(mox.IgnoreArg()),
)
)
self.network_api.network_rpcapi.allocate_for_instance(mox.IgnoreArg(), **kwargs).AndReturn([])
self.mox.ReplayAll()
flavor = flavors.get_default_flavor()
flavor["rxtx_factor"] = 0
sys_meta = flavors.save_flavor_info({}, flavor)
instance = dict(
id="id", uuid="uuid", project_id="project_id", host="host", system_metadata=utils.dict_to_metadata(sys_meta)
)
self.network_api.allocate_for_instance(self.context, instance, "vpn", "requested_networks", macs=macs)
示例11: _stub_migrate_instance_calls
def _stub_migrate_instance_calls(self, method, multi_host, info):
fake_flavor = flavors.get_default_flavor()
fake_flavor['rxtx_factor'] = 1.21
fake_instance = objects.Instance(
uuid=uuid.uuid4().hex,
project_id='fake_project_id',
instance_type_id=fake_flavor['id'],
flavor=fake_flavor,
system_metadata={})
fake_migration = {
'source_compute': 'fake_compute_source',
'dest_compute': 'fake_compute_dest'
}
def fake_mig_inst_method(*args, **kwargs):
info['kwargs'] = kwargs
def fake_get_multi_addresses(*args, **kwargs):
return multi_host, ['fake_float1', 'fake_float2']
self.stubs.Set(network_rpcapi.NetworkAPI, method, fake_mig_inst_method)
self.stubs.Set(self.network_api, '_get_multi_addresses',
fake_get_multi_addresses)
expected = {
'instance_uuid': fake_instance.uuid,
'source_compute': 'fake_compute_source',
'dest_compute': 'fake_compute_dest',
'rxtx_factor': 1.21,
'project_id': 'fake_project_id',
'floating_addresses': None
}
if multi_host:
expected['floating_addresses'] = ['fake_float1', 'fake_float2']
return fake_instance, fake_migration, expected
示例12: _stub_migrate_instance_calls
def _stub_migrate_instance_calls(self, method, multi_host, info):
fake_flavor = flavors.get_default_flavor()
fake_flavor["rxtx_factor"] = 1.21
fake_instance = objects.Instance(
uuid=uuid.uuid4().hex,
project_id="fake_project_id",
instance_type_id=fake_flavor["id"],
flavor=fake_flavor,
system_metadata={},
)
fake_migration = {"source_compute": "fake_compute_source", "dest_compute": "fake_compute_dest"}
def fake_mig_inst_method(*args, **kwargs):
info["kwargs"] = kwargs
def fake_get_multi_addresses(*args, **kwargs):
return multi_host, ["fake_float1", "fake_float2"]
self.stub_out("nova.network.rpcapi.NetworkAPI." + method, fake_mig_inst_method)
self.stub_out("nova.network.api.API._get_multi_addresses", fake_get_multi_addresses)
expected = {
"instance_uuid": fake_instance.uuid,
"source_compute": "fake_compute_source",
"dest_compute": "fake_compute_dest",
"rxtx_factor": 1.21,
"project_id": "fake_project_id",
"floating_addresses": None,
}
if multi_host:
expected["floating_addresses"] = ["fake_float1", "fake_float2"]
return fake_instance, fake_migration, expected
示例13: test_get_flavor_from_deleted_with_id
def test_get_flavor_from_deleted_with_id(self):
# Deleted instances may not have type info in system_metadata,
# so verify that they get their type from a lookup of their
# instance_type_id
inst_without_sys_meta = dict(self.baseinst, system_metadata=[], deleted=1)
flavor = self.controller._get_flavor(self.context, self.compute_api, inst_without_sys_meta, {})
self.assertEqual(flavor, flavors.get_default_flavor())
示例14: _stub_migrate_instance_calls
def _stub_migrate_instance_calls(self, method, multi_host, info):
fake_flavor = flavors.get_default_flavor()
fake_flavor['rxtx_factor'] = 1.21
sys_meta = utils.dict_to_metadata(
flavors.save_flavor_info({}, fake_flavor))
fake_instance = {'uuid': 'fake_uuid',
'instance_type_id': fake_flavor['id'],
'project_id': 'fake_project_id',
'system_metadata': sys_meta}
fake_migration = {'source_compute': 'fake_compute_source',
'dest_compute': 'fake_compute_dest'}
def fake_mig_inst_method(*args, **kwargs):
info['kwargs'] = kwargs
def fake_get_multi_addresses(*args, **kwargs):
return multi_host, ['fake_float1', 'fake_float2']
self.stubs.Set(network_rpcapi.NetworkAPI, method,
fake_mig_inst_method)
self.stubs.Set(self.network_api, '_get_multi_addresses',
fake_get_multi_addresses)
expected = {'instance_uuid': 'fake_uuid',
'source_compute': 'fake_compute_source',
'dest_compute': 'fake_compute_dest',
'rxtx_factor': 1.21,
'project_id': 'fake_project_id',
'floating_addresses': None}
if multi_host:
expected['floating_addresses'] = ['fake_float1', 'fake_float2']
return fake_instance, fake_migration, expected
示例15: fake_inst_obj
def fake_inst_obj(context):
inst = objects.Instance(
context=context,
id=1,
user_id='fake_user',
uuid='b65cee2f-8c69-4aeb-be2f-f79742548fc2',
project_id='test',
key_name="key",
key_data="ssh-rsa AAAAB3Nzai....N3NtHw== [email protected]",
host='test',
launch_index=1,
reservation_id='r-xxxxxxxx',
user_data=ENCODE_USER_DATA_STRING,
image_ref=7,
kernel_id=None,
ramdisk_id=None,
vcpus=1,
fixed_ips=[],
root_device_name='/dev/sda1',
hostname='test.novadomain',
display_name='my_displayname',
metadata={},
default_ephemeral_device=None,
default_swap_device=None,
system_metadata={},
availability_zone=None)
nwinfo = network_model.NetworkInfo([])
inst.info_cache = objects.InstanceInfoCache(context=context,
instance_uuid=inst.uuid,
network_info=nwinfo)
with mock.patch.object(inst, 'save'):
inst.set_flavor(flavors.get_default_flavor())
return inst