• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python flavors.get_flavor_by_flavor_id函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中nova.compute.flavors.get_flavor_by_flavor_id函数的典型用法代码示例。如果您正苦于以下问题:Python get_flavor_by_flavor_id函数的具体用法?Python get_flavor_by_flavor_id怎么用?Python get_flavor_by_flavor_id使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了get_flavor_by_flavor_id函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_resize_quota_exceeds_fails

    def test_resize_quota_exceeds_fails(self):
        self.mox.StubOutWithMock(flavors, 'get_flavor_by_flavor_id')
        self.mox.StubOutWithMock(self.compute_api, '_upsize_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        # Should never reach these.
        self.mox.StubOutWithMock(self.compute_api, 'update')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(self.compute_api.compute_task_api,
                                 'migrate_server')

        fake_inst = obj_base.obj_to_primitive(self._create_instance_obj())
        current_flavor = flavors.extract_flavor(fake_inst)
        fake_flavor = dict(id=200, flavorid='flavor-id', name='foo',
                           disabled=False)
        flavors.get_flavor_by_flavor_id(
                'flavor-id', read_deleted='no').AndReturn(fake_flavor)
        deltas = dict(resource=0)
        self.compute_api._upsize_quota_delta(
                self.context, fake_flavor,
                current_flavor).AndReturn(deltas)
        usage = dict(in_use=0, reserved=0)
        over_quota_args = dict(quotas={'resource': 0},
                               usages={'resource': usage},
                               overs=['resource'])
        self.compute_api._reserve_quota_delta(self.context, deltas,
                project_id=fake_inst['project_id']).AndRaise(
                        exception.OverQuota(**over_quota_args))

        self.mox.ReplayAll()

        self.assertRaises(exception.TooManyInstances,
                          self.compute_api.resize, self.context,
                          fake_inst, flavor_id='flavor-id')
开发者ID:wingo1990,项目名称:nova,代码行数:34,代码来源:test_compute_api.py


示例2: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = "76fa36fc-c930-4bf3-8c8a-ea2a2420deb6"
            def_image_ref = "http://localhost/v3/os-images/%s" % image_uuid
            self.instance_cache_num += 1
            instance = {
                "id": self.instance_cache_num,
                "display_name": inst["display_name"] or "test",
                "uuid": MANUAL_INSTANCE_UUID,
                "instance_type": dict(inst_type),
                "access_ip_v4": "1.2.3.4",
                "access_ip_v6": "fead::1234",
                "image_ref": inst.get("image_ref", def_image_ref),
                "user_id": "fake",
                "project_id": "fake",
                "reservation_id": inst["reservation_id"],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "user_data": None,
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
            }

            self.instance_cache_by_id[instance["id"]] = instance
            self.instance_cache_by_uuid[instance["uuid"]] = instance
            return instance
开发者ID:cloudbau,项目名称:nova,代码行数:28,代码来源:test_disk_config.py


示例3: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "config_drive": None,
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
                "security_groups": inst['security_groups'],
                "extra": {"pci_requests": None,
                          "numa_topology": None},
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance
开发者ID:EdLeafe,项目名称:nova,代码行数:32,代码来源:test_multiple_create.py


示例4: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/{0!s}'.format(image_uuid)
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': inst['uuid'],
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "security_groups": inst['security_groups'],
            })

            self.instance_cache_by_id[instance['id']] = instance
            self.instance_cache_by_uuid[instance['uuid']] = instance
            return instance
开发者ID:runt18,项目名称:nova,代码行数:28,代码来源:test_multiple_create.py


示例5: _fake_compute_api_create

        def _fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
            self._block_device_mapping_seen = kwargs.get("block_device_mapping")
            self._legacy_bdm_seen = kwargs.get("legacy_bdm")

            inst_type = flavors.get_flavor_by_flavor_id(2)
            resv_id = None
            return (
                [
                    {
                        "id": 1,
                        "display_name": "test_server",
                        "uuid": FAKE_UUID,
                        "instance_type": inst_type,
                        "access_ip_v4": "1.2.3.4",
                        "access_ip_v6": "fead::1234",
                        "image_ref": IMAGE_UUID,
                        "user_id": "fake",
                        "project_id": "fake",
                        "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                        "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                        "progress": 0,
                        "fixed_ips": [],
                    }
                ],
                resv_id,
            )
开发者ID:yizhongyin,项目名称:OpenstackLiberty,代码行数:26,代码来源:test_volumes.py


示例6: instance_create

        def instance_create(context, inst):
            inst_type = flavors.get_flavor_by_flavor_id(3)
            image_uuid = '76fa36fc-c930-4bf3-8c8a-ea2a2420deb6'
            def_image_ref = 'http://localhost/images/%s' % image_uuid
            self.instance_cache_num += 1
            instance = fake_instance.fake_db_instance(**{
                'id': self.instance_cache_num,
                'display_name': inst['display_name'] or 'test',
                'uuid': FAKE_UUID,
                'instance_type': inst_type,
                'access_ip_v4': '1.2.3.4',
                'access_ip_v6': 'fead::1234',
                'image_ref': inst.get('image_ref', def_image_ref),
                'user_id': 'fake',
                'project_id': 'fake',
                'availability_zone': 'nova',
                'reservation_id': inst['reservation_id'],
                "created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
                "updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
                "progress": 0,
                "fixed_ips": [],
                "task_state": "",
                "vm_state": "",
                "root_device_name": inst.get('root_device_name', 'vda'),
            })

            return instance
开发者ID:ezhangle,项目名称:nova,代码行数:27,代码来源:test_availability_zone.py


示例7: resize_vm

def resize_vm(uid, flavor_id, context):
    """
    Resizes a VM up or down

    Update: libvirt now supports resize see:
    http://wiki.openstack.org/HypervisorSupportMatrix

    uid -- id of the instance
    flavor_id -- image reference.
    context -- the os context
    """
    instance = get_vm(uid, context)
    kwargs = {}
    try:
        flavor = flavors.get_flavor_by_flavor_id(flavor_id)
        COMPUTE_API.resize(context, instance, flavor_id=flavor['flavorid'],
                           **kwargs)
        ready = False
        i = 0
        # XXX are 15 secs enough to resize?
        while not ready and i < 15:
            i += 1
            state = get_vm(uid, context)['vm_state']
            if state == 'resized':
                ready = True
            import time
            time.sleep(1)
        instance = get_vm(uid, context)
        COMPUTE_API.confirm_resize(context, instance)
    except Exception as e:
        raise AttributeError(str(e))
开发者ID:ic-hep,项目名称:occi-os,代码行数:31,代码来源:vm.py


示例8: test_will_get_instance_by_flavor_id

 def test_will_get_instance_by_flavor_id(self):
     default_instance_type = objects.Flavor.get_by_name(
         context.get_admin_context(), 'm1.small')
     flavorid = default_instance_type.flavorid
     fetched = flavors.get_flavor_by_flavor_id(flavorid)
     self.assertIsInstance(fetched, objects.Flavor)
     self.assertEqual(default_instance_type.flavorid, fetched.flavorid)
开发者ID:mahak,项目名称:nova,代码行数:7,代码来源:test_flavors.py


示例9: show

    def show(self, req, id):
        """Return data about the given flavor id."""
        try:
            flavor = flavors.get_flavor_by_flavor_id(id)
            req.cache_db_flavor(flavor)
        except exception.NotFound:
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, flavor)
开发者ID:ChaosCloud,项目名称:nova,代码行数:9,代码来源:flavors.py


示例10: show

    def show(self, req, id):
        """Return data about the given flavor id."""
        try:
            flavor = flavors.get_flavor_by_flavor_id(id)
            req.cache_db_flavor(flavor)
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        return self._view_builder.show(req, flavor)
开发者ID:joseluizrf,项目名称:nova,代码行数:9,代码来源:flavors.py


示例11: _delete

    def _delete(self, req, id):
        context = req.environ["nova.context"]
        authorize(context)

        try:
            flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context, read_deleted="no")
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        flavors.destroy(flavor["name"])
开发者ID:BU-NU-CLOUD-SP16,项目名称:Trusted-Platform-Module-nova,代码行数:10,代码来源:flavor_manage.py


示例12: show

    def show(self, req, id):
        """Return data about the given flavor id."""
        try:
            context = req.environ['nova.context']
            flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context, read_deleted='no')
            req.cache_db_flavor(flavor)
        except exception.NotFound:
            raise webob.exc.HTTPNotFound()

        return self._view_builder.show(req, flavor)
开发者ID:guykr-stratoscale,项目名称:nova,代码行数:10,代码来源:flavors.py


示例13: test_read_deleted_false_converting_flavorid

    def test_read_deleted_false_converting_flavorid(self):
        """Ensure deleted flavors are not returned when not needed (for
        example when creating a server and attempting to translate from
        flavorid to instance_type_id.
        """
        flavors.create("instance_type1", 256, 1, 120, 100, "test1")
        flavors.destroy("instance_type1")
        flavors.create("instance_type1_redo", 256, 1, 120, 100, "test1")

        instance_type = flavors.get_flavor_by_flavor_id("test1", read_deleted="no")
        self.assertEqual("instance_type1_redo", instance_type.name)
开发者ID:isyippee,项目名称:nova,代码行数:11,代码来源:test_flavors.py


示例14: test_resize_invalid_flavor_fails

    def test_resize_invalid_flavor_fails(self):
        self.mox.StubOutWithMock(flavors, 'get_flavor_by_flavor_id')
        # Should never reach these.
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, 'update')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(self.compute_api.compute_task_api,
                                 'migrate_server')

        fake_inst = obj_base.obj_to_primitive(self._create_instance_obj())
        exc = exception.FlavorNotFound(flavor_id='flavor-id')

        flavors.get_flavor_by_flavor_id('flavor-id',
                                        read_deleted='no').AndRaise(exc)

        self.mox.ReplayAll()

        self.assertRaises(exception.FlavorNotFound,
                          self.compute_api.resize, self.context,
                          fake_inst, flavor_id='flavor-id')
开发者ID:wingo1990,项目名称:nova,代码行数:21,代码来源:test_compute_api.py


示例15: _delete

    def _delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)
        try:
            flavor = flavors.get_flavor_by_flavor_id(
                    id, ctxt=context, read_deleted="no")
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        flavors.destroy(flavor['name'])

        return webob.Response(status_int=202)
开发者ID:375670450,项目名称:nova,代码行数:12,代码来源:flavormanage.py


示例16: test_can_read_deleted_types_using_flavor_id

    def test_can_read_deleted_types_using_flavor_id(self):
        # Ensure deleted flavors can be read when querying flavor_id.
        inst_type_name = "test"
        inst_type_flavor_id = "test1"

        inst_type = flavors.create(inst_type_name, 256, 1, 120, 100, inst_type_flavor_id)
        self.assertEqual(inst_type_name, inst_type["name"])

        # NOTE(jk0): The deleted flavor will show up here because the context
        # in get_flavor_by_flavor_id() is set to use read_deleted by
        # default.
        flavors.destroy(inst_type["name"])
        deleted_inst_type = flavors.get_flavor_by_flavor_id(inst_type_flavor_id)
        self.assertEqual(inst_type_name, deleted_inst_type["name"])
开发者ID:newgoliath,项目名称:nova,代码行数:14,代码来源:test_flavors.py


示例17: test_resize_same_flavor_fails

    def test_resize_same_flavor_fails(self):
        self.mox.StubOutWithMock(flavors, 'get_flavor_by_flavor_id')
        # Should never reach these.
        self.mox.StubOutWithMock(self.compute_api, '_reserve_quota_delta')
        self.mox.StubOutWithMock(self.compute_api, 'update')
        self.mox.StubOutWithMock(quota.QUOTAS, 'commit')
        self.mox.StubOutWithMock(self.compute_api, '_record_action_start')
        self.mox.StubOutWithMock(self.compute_api.compute_task_api,
                                 'migrate_server')

        fake_inst = obj_base.obj_to_primitive(self._create_instance_obj())
        fake_flavor = flavors.extract_flavor(fake_inst)

        flavors.get_flavor_by_flavor_id(
                fake_flavor['flavorid'],
                read_deleted='no').AndReturn(fake_flavor)

        self.mox.ReplayAll()

        # Pass in flavor_id.. same as current flavor.
        self.assertRaises(exception.CannotResizeToSameFlavor,
                          self.compute_api.resize, self.context,
                          fake_inst, flavor_id=fake_flavor['flavorid'])
开发者ID:wingo1990,项目名称:nova,代码行数:23,代码来源:test_compute_api.py


示例18: index

    def index(self, req, flavor_id):
        context = req.environ['nova.context']
        authorize(context)

        try:
            flavor = flavors.get_flavor_by_flavor_id(flavor_id, ctxt=context)
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        # public flavor to all projects
        if flavor['is_public']:
            explanation = _("Access list not available for public flavors.")
            raise webob.exc.HTTPNotFound(explanation=explanation)

        # private flavor to listed projects only
        return _marshall_flavor_access(flavor_id)
开发者ID:Ivan-Zhu,项目名称:nova-v3-api-doc,代码行数:16,代码来源:flavor_access.py


示例19: _delete

    def _delete(self, req, id):
        context = req.environ['nova.context']
        authorize(context)

        # NOTE(alex_xu): back-compatible with db layer hard-code admin
        # permission checks.
        nova_context.require_admin_context(context)

        try:
            flavor = flavors.get_flavor_by_flavor_id(
                    id, ctxt=context, read_deleted="no")
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        flavors.destroy(flavor['name'])

        return webob.Response(status_int=202)
开发者ID:Dynavisor,项目名称:nova,代码行数:17,代码来源:flavormanage.py


示例20: show

    def show(self, req, id):
        """Return data about the given flavor id."""
        context = req.environ['nova.context']
        try:
            flavor = flavors.get_flavor_by_flavor_id(id, ctxt=context)
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        include_extra_specs = False
        if api_version_request.is_supported(
                req, flavors_view.FLAVOR_EXTRA_SPECS_MICROVERSION):
            include_extra_specs = context.can(
                fes_policies.POLICY_ROOT % 'index', fatal=False)
        include_description = api_version_request.is_supported(
            req, flavors_view.FLAVOR_DESCRIPTION_MICROVERSION)
        return self._view_builder.show(
            req, flavor, include_description=include_description,
            include_extra_specs=include_extra_specs)
开发者ID:arbrandes,项目名称:nova,代码行数:18,代码来源:flavors.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python flavors.get_flavor_by_name函数代码示例发布时间:2022-05-27
下一篇:
Python flavors.get_default_flavor函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap