本文整理汇总了Python中nova.compute.flavors.save_flavor_info函数的典型用法代码示例。如果您正苦于以下问题:Python save_flavor_info函数的具体用法?Python save_flavor_info怎么用?Python save_flavor_info使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了save_flavor_info函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_test_instance
def get_test_instance(context=None, flavor=None, obj=False):
if not context:
context = get_test_admin_context()
if not flavor:
flavor = get_test_flavor(context)
test_instance = {'memory_kb': '2048000',
'basepath': '/some/path',
'bridge_name': 'br100',
'vcpus': 4,
'root_gb': 40,
'bridge': 'br101',
'image_ref': 'cedef40a-ed67-4d10-800e-17455edce175',
'instance_type_id': flavor['id'],
'system_metadata': {},
'extra_specs': {},
'user_id': context.user_id,
'project_id': context.project_id,
}
if obj:
instance = objects.Instance(context, **test_instance)
instance.flavor = objects.Flavor.get_by_id(context, flavor['id'])
instance.create()
else:
flavors.save_flavor_info(test_instance['system_metadata'], flavor, '')
instance = nova.db.instance_create(context, test_instance)
return instance
示例2: get_test_instance
def get_test_instance(context=None, flavor=None, obj=False):
if not context:
context = get_test_admin_context()
if not flavor:
flavor = get_test_flavor(context)
metadata = {}
flavors.save_flavor_info(metadata, flavor, '')
test_instance = {'memory_kb': '2048000',
'basepath': '/some/path',
'bridge_name': 'br100',
'vcpus': 4,
'root_gb': 40,
'project_id': 'fake',
'bridge': 'br101',
'image_ref': 'cedef40a-ed67-4d10-800e-17455edce175',
'instance_type_id': '5',
'system_metadata': metadata,
'extra_specs': {}}
if obj:
instance = instance_obj.Instance(context, **test_instance)
instance.create()
else:
instance = nova.db.instance_create(context, test_instance)
return instance
示例3: 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, {})
示例4: get_test_instance
def get_test_instance(context=None, flavor=None, obj=False):
if not context:
context = get_test_admin_context()
if not flavor:
flavor = get_test_flavor(context)
test_instance = {
"memory_kb": "2048000",
"basepath": "/some/path",
"bridge_name": "br100",
"vcpus": 4,
"root_gb": 40,
"bridge": "br101",
"image_ref": "cedef40a-ed67-4d10-800e-17455edce175",
"instance_type_id": flavor["id"],
"system_metadata": {},
"extra_specs": {},
"user_id": context.user_id,
"project_id": context.project_id,
}
if obj:
instance = objects.Instance(context, **test_instance)
instance.flavor = objects.Flavor.get_by_id(context, flavor["id"])
instance.create()
else:
flavors.save_flavor_info(test_instance["system_metadata"], flavor, "")
instance = nova.db.instance_create(context, test_instance)
return instance
示例5: get_test_instance
def get_test_instance(context=None, instance_type=None):
if not context:
context = get_test_admin_context()
if not instance_type:
instance_type = get_test_instance_type(context)
metadata = {}
flavors.save_flavor_info(metadata, instance_type, "")
test_instance = {
"memory_kb": "2048000",
"basepath": "/some/path",
"bridge_name": "br100",
"vcpus": 4,
"root_gb": 40,
"project_id": "fake",
"bridge": "br101",
"image_ref": "cedef40a-ed67-4d10-800e-17455edce175",
"instance_type_id": "5",
"system_metadata": metadata,
"extra_specs": {},
}
instance_ref = nova.db.instance_create(context, test_instance)
return instance_ref
示例6: build_request_spec
def build_request_spec(image, instances, instance_type=None):
"""Build a request_spec for the scheduler.
The request_spec assumes that all instances to be scheduled are the same
type.
:param image: optional primitive image meta dict
:param instances: list of instances; objects will be converted to
primitives
:param instance_type: optional flavor; objects will be converted to
primitives
:return: dict with the following keys::
'image': the image dict passed in or {}
'instance_properties': primitive version of the first instance passed
'instance_type': primitive version of the instance_type or None
'num_instances': the number of instances passed in
"""
instance = instances[0]
if instance_type is None:
if isinstance(instance, obj_instance.Instance):
instance_type = instance.get_flavor()
else:
instance_type = flavors.extract_flavor(instance)
if isinstance(instance, obj_instance.Instance):
instance = obj_base.obj_to_primitive(instance)
# obj_to_primitive doesn't copy this enough, so be sure
# to detach our metadata blob because we modify it below.
instance['system_metadata'] = dict(instance.get('system_metadata', {}))
if isinstance(instance_type, objects.Flavor):
instance_type = obj_base.obj_to_primitive(instance_type)
# NOTE(danms): Replicate this old behavior because the
# scheduler RPC interface technically expects it to be
# there. Remove this when we bump the scheduler RPC API to
# v5.0
try:
flavors.save_flavor_info(instance.get('system_metadata', {}),
instance_type)
except KeyError:
# If the flavor isn't complete (which is legit with a
# flavor object, just don't put it in the request spec
pass
request_spec = {
'image': image or {},
'instance_properties': instance,
'instance_type': instance_type,
'num_instances': len(instances)}
# NOTE(mriedem): obj_to_primitive above does not serialize everything
# in an object, like datetime fields, so we need to still call to_primitive
# to recursively serialize the items in the request_spec dict.
return jsonutils.to_primitive(request_spec)
示例7: _test_extract_flavor
def _test_extract_flavor(self, prefix):
instance_type = flavors.get_default_flavor()
metadata = {}
flavors.save_flavor_info(metadata, instance_type, prefix)
instance = {"system_metadata": self._dict_to_metadata(metadata)}
_instance_type = flavors.extract_flavor(instance, prefix)
props = flavors.system_metadata_flavor_props.keys()
for key in instance_type.keys():
if key not in props:
del instance_type[key]
self.assertEqual(instance_type, _instance_type)
示例8: 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)
示例9: _create_instances_here
def _create_instances_here(self, ctxt, instance_uuids, instance_properties,
instance_type, image, security_groups, block_device_mapping):
instance_values = copy.copy(instance_properties)
# The parent may pass these metadata values as lists, and the
# create call expects it to be a dict.
instance_values['metadata'] = utils.instance_meta(instance_values)
sys_metadata = utils.instance_sys_meta(instance_values)
# Make sure the flavor info is set. It may not have been passed
# down.
sys_metadata = flavors.save_flavor_info(sys_metadata, instance_type)
instance_values['system_metadata'] = sys_metadata
instance_values.pop('name')
num_instances = len(instance_uuids)
for i, instance_uuid in enumerate(instance_uuids):
instance_values['uuid'] = instance_uuid
instance = self.compute_api.create_db_entry_for_new_instance(
ctxt,
instance_type,
image,
instance_values,
security_groups,
block_device_mapping,
num_instances, i)
self.msg_runner.instance_update_at_top(ctxt, instance)
示例10: _test_extract_flavor
def _test_extract_flavor(self, prefix):
instance_type = objects.Flavor.get_by_name(self.context, 'm1.small')
instance_type_p = obj_base.obj_to_primitive(instance_type)
metadata = {}
flavors.save_flavor_info(metadata, instance_type, prefix)
instance = {'system_metadata': self._dict_to_metadata(metadata)}
_instance_type = flavors.extract_flavor(instance, prefix)
_instance_type_p = obj_base.obj_to_primitive(_instance_type)
props = flavors.system_metadata_flavor_props.keys()
for key in list(instance_type_p.keys()):
if key not in props:
del instance_type_p[key]
self.assertEqual(instance_type_p, _instance_type_p)
示例11: compat_instance
def compat_instance(instance):
"""Create a dict-like instance structure from an objects.Instance.
This is basically the same as nova.objects.base.obj_to_primitive(),
except that it includes some instance-specific details, like stashing
flavor information in system_metadata.
If you have a function (or RPC client) that needs to see the instance
as a dict that has flavor information in system_metadata, use this
to appease it (while you fix said thing).
:param instance: a nova.objects.Instance instance
:returns: a dict-based instance structure
"""
if not isinstance(instance, objects.Instance):
return instance
db_instance = copy.deepcopy(base.obj_to_primitive(instance))
flavor_attrs = [("", "flavor"), ("old_", "old_flavor"), ("new_", "new_flavor")]
for prefix, attr in flavor_attrs:
flavor = instance.obj_attr_is_set(attr) and getattr(instance, attr) or None
if flavor:
# NOTE(danms): If flavor is unset or None, don't
# copy it into the primitive's system_metadata
db_instance["system_metadata"] = flavors.save_flavor_info(
db_instance.get("system_metadata", {}), flavor, prefix
)
if attr in db_instance:
del db_instance[attr]
return db_instance
示例12: _test_extract_flavor
def _test_extract_flavor(self, prefix):
instance_type = flavors.get_default_flavor()
instance_type_p = obj_base.obj_to_primitive(instance_type)
metadata = {}
flavors.save_flavor_info(metadata, instance_type, prefix)
instance = {'system_metadata': self._dict_to_metadata(metadata)}
_instance_type = flavors.extract_flavor(instance, prefix)
_instance_type_p = obj_base.obj_to_primitive(_instance_type)
props = flavors.system_metadata_flavor_props.keys()
for key in instance_type_p.keys():
if key not in props:
del instance_type_p[key]
self.assertEqual(instance_type_p, _instance_type_p)
示例13: 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)
示例14: test_remove_fixed_ip_from_instance_refresh_cache
def test_remove_fixed_ip_from_instance_refresh_cache(self):
sys_meta = flavors.save_flavor_info({}, test_flavor.fake_flavor)
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=["system_metadata"], system_metadata=sys_meta
)
address = "fake-address"
self._test_refresh_cache("remove_fixed_ip_from_instance", self.context, instance, address)
示例15: test_add_fixed_ip_to_instance_refresh_cache
def test_add_fixed_ip_to_instance_refresh_cache(self):
sys_meta = flavors.save_flavor_info({}, test_flavor.fake_flavor)
instance = fake_instance.fake_instance_obj(
self.context, expected_attrs=["system_metadata"], system_metadata=sys_meta
)
network_id = "fake-network-id"
self._test_refresh_cache("add_fixed_ip_to_instance", self.context, instance, network_id)