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

Python resource_registry.get_all_resources函数代码示例

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

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



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

示例1: limit_check

    def limit_check(self, context, tenant_id, **values):
        """Check simple quota limits.

        For limits--those quotas for which there is no usage
        synchronization function--this method checks that a set of
        proposed values are permitted by the limit restriction.  The
        values to check are given as keyword arguments, where the key
        identifies the specific quota limit to check, and the value is
        the proposed value.

        This method will raise a QuotaResourceUnknown exception if a
        given resource is unknown or if it is not a countable resource.

        If any of the proposed values exceeds the respective quota defined
        for the tenant, an OverQuota exception will be raised.
        The exception will include a sorted list with the resources
        which exceed the quota limit. Otherwise, the method returns nothing.

        :param context: Request context
        :param tenant_id: Tenant for which the quota limit is being checked
        :param values: Dict specifying requested deltas for each resource
        """
        # TODO(salv-orlando): Deprecate calls to this API
        # Verify that resources are managed by the quota engine
        requested_resources = set(values.keys())
        managed_resources = set([res for res in resource_registry.get_all_resources() if res in requested_resources])

        # Make sure we accounted for all of them...
        unknown_resources = requested_resources - managed_resources
        if unknown_resources:
            raise exceptions.QuotaResourceUnknown(unknown=sorted(unknown_resources))

        return self.get_driver().limit_check(context, tenant_id, resource_registry.get_all_resources(), values)
开发者ID:yizhongyin,项目名称:OpenstackLiberty,代码行数:33,代码来源:__init__.py


示例2: make_reservation

    def make_reservation(self, context, tenant_id, deltas, plugin):
        # Verify that resources are managed by the quota engine
        # Ensure no value is less than zero
        unders = [key for key, val in deltas.items() if val < 0]
        if unders:
            raise exceptions.InvalidQuotaValue(unders=sorted(unders))

        requested_resources = set(deltas.keys())
        all_resources = resource_registry.get_all_resources()
        managed_resources = set([res for res in all_resources.keys()
                                 if res in requested_resources])
        # Make sure we accounted for all of them...
        unknown_resources = requested_resources - managed_resources

        if unknown_resources:
            raise exceptions.QuotaResourceUnknown(
                unknown=sorted(unknown_resources))
        # FIXME(salv-orlando): There should be no reason for sending all the
        # resource in the registry to the quota driver, but as other driver
        # APIs request them, this will be sorted out with a different patch.
        return self.get_driver().make_reservation(
            context,
            tenant_id,
            all_resources,
            deltas,
            plugin)
开发者ID:AradhanaSingh,项目名称:neutron,代码行数:26,代码来源:__init__.py


示例3: patched_set_resources_dirty

def patched_set_resources_dirty(context):
    if not cfg.CONF.QUOTAS.track_quota_usage:
        return

    with context.session.begin(subtransactions=True):
        for res in res_reg.get_all_resources().values():
            if res_reg.is_tracked(res.name) and res.dirty:
                dirty_tenants_snap = res._dirty_tenants.copy()
                for tenant_id in dirty_tenants_snap:
                    query = common_db_api.model_query(
                            context, quota_models.QuotaUsage)
                    query = query.filter_by(resource=res.name).filter_by(
                            tenant_id=tenant_id)
                    usage_data = query.first()
                    # Set dirty if not set already. This effectively
                    # patches the inner notify method:
                    # https://github.com/openstack/neutron/blob/newton-eol/
                    # neutron/api/v2/base.py#L481
                    # to avoid updating the QuotaUsages table outside
                    # from that method (which starts a new transaction).
                    # The dirty marking would have been already done
                    # in the ml2plus manager at the end of the pre_commit
                    # stage (and prior to the plugin initiated transaction
                    # completing).
                    if usage_data and not usage_data.dirty:
                        res.mark_dirty(context)
开发者ID:openstack,项目名称:group-based-policy,代码行数:26,代码来源:patch_neutron.py


示例4: default

 def default(self, request, id):
     if id != request.context.tenant_id:
         self._check_admin(request.context,
                           reason=_("Only admin is authorized "
                                    "to access quotas for another tenant"))
     return {self._resource_name: self._driver.get_default_quotas(
                context=request.context,
                resources=resource_registry.get_all_resources(),
                tenant_id=id)}
开发者ID:igordcard,项目名称:neutron,代码行数:9,代码来源:quotasv2.py


示例5: _update_attributes

 def _update_attributes(self):
     for quota_resource in resource_registry.get_all_resources().keys():
         attr_dict = EXTENDED_ATTRIBUTES_2_0[RESOURCE_COLLECTION]
         attr_dict[quota_resource] = {
             'allow_post': False,
             'allow_put': True,
             'convert_to': attributes.convert_to_int,
             'validate': {'type:range': [-1, const.DB_INTEGER_MAX_VALUE]},
             'is_visible': True}
     self._update_extended_attributes = False
开发者ID:HoratiusTang,项目名称:neutron,代码行数:10,代码来源:quotasv2.py


示例6: index

 def index(self):
     neutron_context = request.context.get('neutron_context')
     # FIXME(salv-orlando): There shouldn't be any need to to this eplicit
     # check. However some behaviours from the "old" extension have
     # been temporarily carried over here
     self._check_admin(neutron_context)
     # TODO(salv-orlando): proper plurals management
     return {self.collection:
             self._driver.get_all_quotas(
                 neutron_context,
                 resource_registry.get_all_resources())}
开发者ID:Blahhhhh,项目名称:neutron,代码行数:11,代码来源:quota.py


示例7: make_reservation

    def make_reservation(self, context, tenant_id, resources, deltas, plugin):
        """This driver does not support reservations.

        This routine is provided for backward compatibility purposes with
        the API controllers which have now been adapted to make reservations
        rather than counting resources and checking limits - as this
        routine ultimately does.
        """
        for resource in deltas.keys():
            count = QUOTAS.count(context, resource, plugin, tenant_id)
            total_use = deltas.get(resource, 0) + count
            deltas[resource] = total_use

        self.limit_check(context, tenant_id, resource_registry.get_all_resources(), deltas)
        # return a fake reservation - the REST controller expects it
        return quota_api.ReservationInfo("fake", None, None, None)
开发者ID:yizhongyin,项目名称:OpenstackLiberty,代码行数:16,代码来源:__init__.py


示例8: __init__

    def __init__(self, _driver, tenant_id):
        self._driver = _driver
        self._tenant_id = tenant_id

        super(QuotaController, self).__init__(
            "%ss" % RESOURCE_NAME, RESOURCE_NAME)

        # Ensure limits for all registered resources are returned
        attr_dict = attributes.RESOURCE_ATTRIBUTE_MAP[self.collection]
        for quota_resource in resource_registry.get_all_resources().keys():
            attr_dict[quota_resource] = {
                'allow_post': False,
                'allow_put': True,
                'convert_to': attributes.convert_to_int,
                'validate': {
                    'type:range': [-1, constants.DB_INTEGER_MAX_VALUE]},
                'is_visible': True}
开发者ID:TonyChengTW,项目名称:OpenStack_Liberty_Control,代码行数:17,代码来源:quota.py


示例9: __init__

    def __init__(self, _driver, tenant_id):
        self._driver = _driver
        self._tenant_id = tenant_id

        super(QuotaController, self).__init__(
            "%ss" % RESOURCE_NAME, RESOURCE_NAME)

        # Ensure limits for all registered resources are returned
        attr_dict = attributes.RESOURCE_ATTRIBUTE_MAP[self.collection]
        for quota_resource in resource_registry.get_all_resources().keys():
            attr_dict[quota_resource] = {
                'allow_post': False,
                'allow_put': True,
                'convert_to': attributes.convert_to_int,
                'validate': {
                    'type:range': [-1, constants.DB_INTEGER_MAX_VALUE]},
                'is_visible': True}
        # The quota resource must always declare a tenant_id attribute,
        # otherwise the attribute will be stripped off when generating the
        # response
        attr_dict.update(TENANT_ID_ATTR)
开发者ID:Blahhhhh,项目名称:neutron,代码行数:21,代码来源:quota.py


示例10: get_tenant_quotas

def get_tenant_quotas(tenant_id, driver=None):
    if not driver:
        driver = importutils.import_class(cfg.CONF.QUOTAS.quota_driver)

    neutron_context = request.context.get('neutron_context')
    if tenant_id == 'tenant':
        # NOTE(salv-orlando): Read the following before the code in order
        # to avoid puking.
        # There is a weird undocumented behaviour of the Neutron quota API
        # as 'tenant' is used as an API action to return the identifier
        # of the tenant in the request context. This is used exclusively
        # for interaction with python-neutronclient and is a possibly
        # unnecessary 'whoami' API endpoint. Pending resolution of this
        # API issue, this controller will just treat the magic string
        # 'tenant' (and only that string) and return the response expected
        # by python-neutronclient
        return {'tenant': {'tenant_id': neutron_context.tenant_id}}
    tenant_quotas = driver.get_tenant_quotas(
        neutron_context,
        resource_registry.get_all_resources(),
        tenant_id)
    tenant_quotas['tenant_id'] = tenant_id
    return {RESOURCE_NAME: tenant_quotas}
开发者ID:Blahhhhh,项目名称:neutron,代码行数:23,代码来源:quota.py


示例11: index

 def index(self, request):
     context = request.context
     self._check_admin(context)
     return {self._resource_name + "s":
             self._driver.get_all_quotas(
                 context, resource_registry.get_all_resources())}
开发者ID:HoratiusTang,项目名称:neutron,代码行数:6,代码来源:quotasv2.py


示例12: _get_quotas

 def _get_quotas(self, request, tenant_id):
     return self._driver.get_tenant_quotas(
         request.context,
         resource_registry.get_all_resources(),
         tenant_id)
开发者ID:HoratiusTang,项目名称:neutron,代码行数:5,代码来源:quotasv2.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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