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

Python flavors.add_flavor_access函数代码示例

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

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



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

示例1: _create

    def _create(self, req, body):
        context = req.environ['nova.context']
        authorize(context)
        if not self.is_valid_body(body, 'flavor'):
            msg = _("Invalid request body")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        vals = body['flavor']
        name = vals.get('name')
        flavorid = vals.get('id')
        memory = vals.get('ram')
        vcpus = vals.get('vcpus')
        root_gb = vals.get('disk')
        ephemeral_gb = vals.get('OS-FLV-EXT-DATA:ephemeral', 0)
        swap = vals.get('swap', 0)
        rxtx_factor = vals.get('rxtx_factor', 1.0)
        is_public = vals.get('os-flavor-access:is_public', True)

        try:
            flavor = flavors.create(name, memory, vcpus, root_gb,
                                    ephemeral_gb=ephemeral_gb,
                                    flavorid=flavorid, swap=swap,
                                    rxtx_factor=rxtx_factor,
                                    is_public=is_public)
            if not flavor['is_public']:
                flavors.add_flavor_access(flavor['flavorid'],
                                          context.project_id, context)
            req.cache_db_flavor(flavor)
        except (exception.FlavorExists,
                exception.FlavorIdExists) as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())
        except exception.InvalidInput as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

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


示例2: _create

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

        vals = body['flavor']

        name = vals['name']
        flavorid = vals.get('id')
        memory = vals['ram']
        vcpus = vals['vcpus']
        root_gb = vals['disk']
        ephemeral_gb = vals.get('ephemeral', 0)
        swap = vals.get('swap', 0)
        rxtx_factor = vals.get('os-flavor-rxtx:rxtx_factor', 1.0)
        is_public = vals.get('flavor-access:is_public', True)

        try:
            flavor = flavors.create(name, memory, vcpus, root_gb,
                                    ephemeral_gb=ephemeral_gb,
                                    flavorid=flavorid, swap=swap,
                                    rxtx_factor=rxtx_factor,
                                    is_public=is_public)
            if not flavor['is_public']:
                flavors.add_flavor_access(flavor['flavorid'],
                                          context.project_id, context)
            req.cache_db_flavor(flavor)
        except (exception.FlavorExists,
                exception.FlavorIdExists) as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())

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


示例3: test_add_flavor_access_already_exists

 def test_add_flavor_access_already_exists(self):
     user_id = "fake"
     project_id = "fake"
     ctxt = context.RequestContext(user_id, project_id, is_admin=True)
     flavor_id = "flavor1"
     flavors.create("some flavor", 256, 1, 120, 100, flavorid=flavor_id)
     flavors.add_flavor_access(flavor_id, project_id, ctxt=ctxt)
     self.assertRaises(exception.FlavorAccessExists, flavors.add_flavor_access, flavor_id, project_id, ctxt)
开发者ID:newgoliath,项目名称:nova,代码行数:8,代码来源:test_flavors.py


示例4: test_remove_flavor_access

    def test_remove_flavor_access(self):
        user_id = "fake"
        project_id = "fake"
        ctxt = context.RequestContext(user_id, project_id, is_admin=True)
        flavor_id = "flavor1"
        flavors.create("some flavor", 256, 1, 120, 100, flavorid=flavor_id)
        flavors.add_flavor_access(flavor_id, project_id, ctxt)
        flavors.remove_flavor_access(flavor_id, project_id, ctxt)

        projects = flavors.get_flavor_access_by_flavor_id(flavor_id, ctxt)
        self.assertEqual([], projects)
开发者ID:newgoliath,项目名称:nova,代码行数:11,代码来源:test_flavors.py


示例5: _addTenantAccess

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

        vals = body['addTenantAccess']
        tenant = vals['tenant']

        try:
            flavors.add_flavor_access(id, tenant, context)
        except exception.FlavorAccessExists as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())

        return _marshall_flavor_access(id)
开发者ID:Charu-Sharma,项目名称:nova,代码行数:14,代码来源:flavor_access.py


示例6: test_add_instance_type_access

 def test_add_instance_type_access(self):
     user_id = "fake"
     project_id = "fake"
     ctxt = context.RequestContext(user_id, project_id, is_admin=True)
     flavor_id = "flavor1"
     type_ref = flavors.create("some flavor", 256, 1, 120, 100, flavorid=flavor_id)
     access_ref = flavors.add_flavor_access(flavor_id, project_id, ctxt=ctxt)
     self.assertEqual(access_ref["project_id"], project_id)
     self.assertEqual(access_ref["instance_type_id"], type_ref["id"])
开发者ID:newgoliath,项目名称:nova,代码行数:9,代码来源:test_flavors.py


示例7: _add_tenant_access

    def _add_tenant_access(self, req, id, body):
        context = req.environ['nova.context']
        authorize(context)
        if not self.is_valid_body(body, 'add_tenant_access'):
            raise webob.exc.HTTPBadRequest(explanation=_("Invalid request"))

        vals = body['add_tenant_access']
        try:
            tenant = vals['tenant_id']
        except KeyError:
            raise webob.exc.HTTPBadRequest(
                explanation=_("tenant_id is required"))

        try:
            flavors.add_flavor_access(id, tenant, context)
        except exception.FlavorAccessExists as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())
        except exception.FlavorNotFound as e:
            raise webob.exc.HTTPNotFound(explanation=e.format_message())

        return _marshall_flavor_access(id)
开发者ID:Ivan-Zhu,项目名称:nova-v3-api-doc,代码行数:21,代码来源:flavor_access.py


示例8: _create

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

        if not self.is_valid_body(body, "flavor"):
            raise webob.exc.HTTPBadRequest("Invalid request body ")

        vals = body["flavor"]

        name = vals.get("name")
        flavorid = vals.get("id")
        memory = vals.get("ram")
        vcpus = vals.get("vcpus")
        root_gb = vals.get("disk")
        ephemeral_gb = vals.get("ephemeral", 0)
        swap = vals.get("swap", 0)
        rxtx_factor = vals.get("os-flavor-rxtx:rxtx_factor", 1.0)
        is_public = vals.get("flavor-access:is_public", True)

        try:
            flavor = flavors.create(
                name,
                memory,
                vcpus,
                root_gb,
                ephemeral_gb=ephemeral_gb,
                flavorid=flavorid,
                swap=swap,
                rxtx_factor=rxtx_factor,
                is_public=is_public,
            )
            if not flavor["is_public"]:
                flavors.add_flavor_access(flavor["flavorid"], context.project_id, context)
            req.cache_db_flavor(flavor)
        except (exception.FlavorExists, exception.FlavorIdExists) as err:
            raise webob.exc.HTTPConflict(explanation=err.format_message())
        except exception.InvalidInput as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

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


示例9: test_add_flavor_access_already_exists

 def test_add_flavor_access_already_exists(self):
     user_id = 'fake'
     project_id = 'fake'
     ctxt = context.RequestContext(user_id, project_id, is_admin=True)
     flavor_id = 'flavor1'
     type_ref = flavors.create('some flavor', 256, 1, 120, 100,
                                       flavorid=flavor_id)
     access_ref = flavors.add_flavor_access(flavor_id,
                                                          project_id,
                                                          ctxt=ctxt)
     self.assertRaises(exception.FlavorAccessExists,
                       flavors.add_flavor_access,
                       flavor_id, project_id, ctxt)
开发者ID:MasterZ40,项目名称:nova,代码行数:13,代码来源:test_flavors.py


示例10: test_remove_flavor_access

    def test_remove_flavor_access(self):
        user_id = 'fake'
        project_id = 'fake'
        ctxt = context.RequestContext(user_id, project_id, is_admin=True)
        flavor_id = 'flavor1'
        type_ref = flavors.create('some flavor', 256, 1, 120, 100,
                                          flavorid=flavor_id)
        access_ref = flavors.add_flavor_access(flavor_id, project_id,
                                                      ctxt)
        flavors.remove_flavor_access(flavor_id, project_id, ctxt)

        projects = flavors.get_flavor_access_by_flavor_id(flavor_id,
                                                                 ctxt)
        self.assertEqual([], projects)
开发者ID:MasterZ40,项目名称:nova,代码行数:14,代码来源:test_flavors.py


示例11: create

    def create(self, req, body):
        """Extend Server create action with resource allocation.
        """
        if not self.is_valid_body(body, 'server'):
            raise exc.HTTPUnprocessableEntity()
        context = req.environ['nova.context']

        server_dict = body['server']
        flavor_dict = server_dict.get('flavor')

        if flavor_dict:
            # only authorize if they have the flavor_dict otherwise the policy
            # is always applied whether it is present or not
            authorize(context)

            # verify input parameters
            if server_dict.get('flavorRef'):
                msg = _("only one of flavorRef or flavor can be specified.")
                raise exc.HTTPBadRequest(explanation=msg)
            for opt in ['ram', 'vcpus', 'disk']:
                try:
                    val = int(flavor_dict.get(opt))
                    if opt == 'disk':
                        assert val >= 0
                    else:
                        assert val > 0
                except (ValueError, TypeError, AssertionError):
                    if opt == 'disk':
                        msg = _("%s argument must be an integer") % opt
                    else:
                        msg = _("%s argument must be a positive integer") % opt
                    raise exc.HTTPBadRequest(explanation=msg)

            memory_mb = flavor_dict.get('ram')
            vcpus = flavor_dict.get('vcpus')
            root_gb = flavor_dict.get('disk')
            ephemeral_gb = flavor_dict.get('OS-FLV-EXT-DATA:ephemeral')

            # query the flavor
            flavor_name = self._generate_unique_name(flavor_dict)
            inst_type = None
            try:
                inst_type = flavors. \
                    get_flavor_by_name(flavor_name, context)
            except exception.FlavorNotFoundByName:
                LOG.debug("Flavor not found. Creating...")

            # create flavor if no matched flavor
            if not inst_type:
                if ephemeral_gb is None:
                    ephemeral_gb = 0
                try:
                    inst_type = flavors.create(flavor_name,
                                          memory_mb,
                                          vcpus,
                                          root_gb,
                                          ephemeral_gb=ephemeral_gb,
                                          flavorid=None,
                                          swap=0,
                                          rxtx_factor=1.0,
                                          is_public=False)
                    admin_context = (context.is_admin and
                                    context or context.elevated())
                    flavors.add_flavor_access(inst_type['flavorid'],
                                admin_context.project_id, admin_context)
                    self._add_extra_specs(context, flavor_dict, inst_type)
                    req.cache_db_flavor(inst_type)
                except (exception.FlavorExists,
                        exception.FlavorIdExists):
                    try:
                        inst_type = flavors. \
                            get_flavor_by_name(flavor_name, context)
                    except exception.FlavorNotFoundByName:
                        raise exception.FlavorCreateFailed
                except exception.FlavorCreateFailed:
                    msg = _('An unknown db error has occurred. ')
                    raise exc.HTTPInternalServerError(explanation=msg)

            # update flavorRef parameters
            server_dict['flavorRef'] = inst_type['flavorid']
            del server_dict['flavor']
        elif not server_dict.get('flavorRef'):
            msg = _("Missing flavorRef or flavor attribute.")
            raise exc.HTTPBadRequest(explanation=msg)
        yield
开发者ID:windskyer,项目名称:k_nova,代码行数:85,代码来源:flavor_dynamic.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python flavors.create函数代码示例发布时间:2022-05-27
下一篇:
Python arch.canonicalize函数代码示例发布时间: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