当前位置: 首页>>代码示例>>Python>>正文


Python flavors.save_flavor_info函数代码示例

本文整理汇总了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
开发者ID:Juniper,项目名称:nova,代码行数:29,代码来源:utils.py

示例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
开发者ID:B-Rich,项目名称:gantt,代码行数:28,代码来源:utils.py

示例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, {})
开发者ID:MasterZ40,项目名称:nova,代码行数:7,代码来源:test_flavors.py

示例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
开发者ID:billhu422,项目名称:nova,代码行数:30,代码来源:utils.py

示例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
开发者ID:habuka036,项目名称:nova,代码行数:26,代码来源:utils.py

示例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)
开发者ID:openstack,项目名称:nova,代码行数:54,代码来源:utils.py

示例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)
开发者ID:newgoliath,项目名称:nova,代码行数:14,代码来源:test_flavors.py

示例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)
开发者ID:Acidburn0zzz,项目名称:nova,代码行数:26,代码来源:test_simple_tenant_usage.py

示例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)
开发者ID:Brocade-OpenSource,项目名称:OpenStack-DNRM-Nova,代码行数:26,代码来源:scheduler.py

示例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)
开发者ID:mahak,项目名称:nova,代码行数:16,代码来源:test_flavors.py

示例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
开发者ID:jcalonsoh,项目名称:openstack-nova,代码行数:31,代码来源:instance.py

示例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)
开发者ID:Milstein,项目名称:nova,代码行数:16,代码来源:test_flavors.py

示例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)
开发者ID:Thingee,项目名称:nova,代码行数:31,代码来源:test_api.py

示例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)
开发者ID:Thingee,项目名称:nova,代码行数:7,代码来源:test_api.py

示例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)
开发者ID:Thingee,项目名称:nova,代码行数:7,代码来源:test_api.py


注:本文中的nova.compute.flavors.save_flavor_info函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。