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

Python api.get_object函数代码示例

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

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



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

示例1: test_get_object_create_update_delete

    def test_get_object_create_update_delete(self):
        obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})

        new_obj = api.get_object(self.ctxt, self.model, id=obj.id)
        self.assertEqual(obj, new_obj)

        obj = new_obj
        api.update_object(self.ctxt, self.model, {'name': 'bar'}, id=obj.id)

        new_obj = api.get_object(self.ctxt, self.model, id=obj.id)
        self.assertEqual(obj, new_obj)

        obj = new_obj
        api.delete_object(self.ctxt, self.model, id=obj.id)

        new_obj = api.get_object(self.ctxt, self.model, id=obj.id)
        self.assertIsNone(new_obj)

        # delete_object raises an exception on missing object
        self.assertRaises(
            n_exc.ObjectNotFound,
            api.delete_object, self.ctxt, self.model, id=obj.id)

        # but delete_objects does not not
        api.delete_objects(self.ctxt, self.model, id=obj.id)
开发者ID:sebrandon1,项目名称:neutron,代码行数:25,代码来源:test_api.py


示例2: validate_rbac_policy_change

    def validate_rbac_policy_change(cls, resource, event, trigger, context,
                                    object_type, policy, **kwargs):
        """Callback to validate RBAC_POLICY changes.

        This is the dispatching function for create, update and delete
        callbacks. On creation and update, verify that the creator is an admin
        or owns the resource being shared.
        """
        # TODO(hdaniel): As this code was shamelessly stolen from
        # NeutronDbPluginV2.validate_network_rbac_policy_change(), those pieces
        # should be synced and contain the same bugs, until Network RBAC logic
        # (hopefully) melded with this one.
        if object_type != cls.rbac_db_model.object_type:
            return
        db_obj = obj_db_api.get_object(
            context.elevated(), cls.db_model, id=policy['object_id'])
        if event in (events.BEFORE_CREATE, events.BEFORE_UPDATE):
            if (not context.is_admin and
                    db_obj['tenant_id'] != context.tenant_id):
                msg = _("Only admins can manipulate policies on objects "
                        "they do not own")
                raise lib_exc.InvalidInput(error_message=msg)
        callback_map = {events.BEFORE_UPDATE: cls.validate_rbac_policy_update,
                        events.BEFORE_DELETE: cls.validate_rbac_policy_delete}
        if event in callback_map:
            return callback_map[event](resource, event, trigger, context,
                                       object_type, policy, **kwargs)
开发者ID:sebrandon1,项目名称:neutron,代码行数:27,代码来源:rbac_db.py


示例3: get_object

    def get_object(cls, context, fields=None, **kwargs):
        """Fetch a single object

        Return the first result of given context or None if the result doesn't
        contain any row. Next, convert it to a versioned object.

        :param context:
        :param fields: indicate which fields the caller is interested in
                       using. Note that currently this is limited to
                       avoid loading synthetic fields when possible, and
                       does not affect db queries. Default is None, which
                       is the same as []. Example: ['id', 'name']
        :param kwargs: multiple keys defined by key=value pairs
        :return: single object of NeutronDbObject class or None
        """
        lookup_keys = set(kwargs.keys())
        all_keys = itertools.chain([cls.primary_keys], cls.unique_keys)
        if not any(lookup_keys.issuperset(keys) for keys in all_keys):
            missing_keys = set(cls.primary_keys).difference(lookup_keys)
            raise o_exc.NeutronPrimaryKeyMissing(object_class=cls,
                                                 missing_keys=missing_keys)

        with cls.db_context_reader(context):
            db_obj = obj_db_api.get_object(
                cls, context, **cls.modify_fields_to_db(kwargs))
            if db_obj:
                return cls._load_object(context, db_obj, fields=fields)
开发者ID:openstack,项目名称:neutron,代码行数:27,代码来源:base.py


示例4: delete

    def delete(self):
        with db_api.autonested_transaction(self._context.session):
            for object_type, model in self.binding_models.items():
                binding_db_obj = obj_db_api.get_object(self._context, model, policy_id=self.id)
                if binding_db_obj:
                    raise exceptions.QosPolicyInUse(
                        policy_id=self.id, object_type=object_type, object_id=binding_db_obj["%s_id" % object_type]
                    )

            super(QosPolicy, self).delete()
开发者ID:klmitch,项目名称:neutron,代码行数:10,代码来源:policy.py


示例5: objects_exist

    def objects_exist(cls, context, validate_filters=True, **kwargs):
        """Check if objects are present in DB.

        :param context:
        :param validate_filters: Raises an error in case of passing an unknown
                                 filter
        :param kwargs: multiple keys defined by key=value pairs
        :return: boolean. True if object is present.
        """
        if validate_filters:
            cls.validate_filters(**kwargs)
        # Succeed if at least a single object matches; no need to fetch more
        return bool(obj_db_api.get_object(
            cls, context, **cls.modify_fields_to_db(kwargs))
        )
开发者ID:noironetworks,项目名称:neutron,代码行数:15,代码来源:base.py


示例6: validate_rbac_policy_delete

    def validate_rbac_policy_delete(cls, resource, event, trigger, context,
                                    object_type, policy, **kwargs):
        """Callback to handle RBAC_POLICY, BEFORE_DELETE callback.

        :raises: RbacPolicyInUse -- in case the policy is in use.
        """
        if policy['action'] != models.ACCESS_SHARED:
            return
        target_tenant = policy['target_tenant']
        db_obj = obj_db_api.get_object(
            context.elevated(), cls.db_model, id=policy['object_id'])
        if db_obj.tenant_id == target_tenant:
            return
        cls._validate_rbac_policy_delete(context=context,
                                         obj_id=policy['object_id'],
                                         target_tenant=target_tenant)
开发者ID:sebrandon1,项目名称:neutron,代码行数:16,代码来源:rbac_db.py


示例7: get_object

    def get_object(cls, context, **kwargs):
        """
        Fetch object from DB and convert it to a versioned object.

        :param context:
        :param kwargs: multiple keys defined by key=value pairs
        :return: single object of NeutronDbObject class
        """
        missing_keys = set(cls.primary_keys).difference(kwargs.keys())
        if missing_keys:
            raise NeutronPrimaryKeyMissing(object_class=cls.__class__,
                                           missing_keys=missing_keys)

        with db_api.autonested_transaction(context.session):
            db_obj = obj_db_api.get_object(context, cls.db_model, **kwargs)
            if db_obj:
                return cls._load_object(context, db_obj)
开发者ID:ISCAS-VDI,项目名称:neutron-base,代码行数:17,代码来源:base.py


示例8: update_shared

    def update_shared(self, is_shared_new, obj_id):
        admin_context = self.obj_context.elevated()
        shared_prev = obj_db_api.get_object(admin_context, self.rbac_db_model,
                                        object_id=obj_id, target_tenant='*',
                                        action=models.ACCESS_SHARED)
        is_shared_prev = bool(shared_prev)
        if is_shared_prev == is_shared_new:
            return

        # 'shared' goes False -> True
        if not is_shared_prev and is_shared_new:
            self.attach_rbac(obj_id, self.obj_context.tenant_id)
            return

        # 'shared' goes True -> False is actually an attempt to delete
        # rbac rule for sharing obj_id with target_tenant = '*'
        self._validate_rbac_policy_delete(self.obj_context, obj_id, '*')
        return self.obj_context.session.delete(shared_prev)
开发者ID:jaguar13,项目名称:neutron,代码行数:18,代码来源:rbac_db.py


示例9: get_object

    def get_object(cls, context, **kwargs):
        """
        This method fetches object from DB and convert it to versioned
        object.

        :param context:
        :param kwargs: multiple primary keys defined key=value pairs
        :return: single object of NeutronDbObject class
        """
        missing_keys = set(cls.primary_keys).difference(kwargs.keys())
        if missing_keys:
            raise NeutronPrimaryKeyMissing(object_class=cls.__class__,
                                           missing_keys=missing_keys)

        db_obj = obj_db_api.get_object(context, cls.db_model, **kwargs)
        if db_obj:
            obj = cls(context, **db_obj)
            obj.obj_reset_changes()
            return obj
开发者ID:FedericoRessi,项目名称:neutron,代码行数:19,代码来源:base.py


示例10: get_object

    def get_object(cls, context, **kwargs):
        """
        Return the first result of given context or None if the result doesn't
        contain any row. Next, convert it to a versioned object.

        :param context:
        :param kwargs: multiple keys defined by key=value pairs
        :return: single object of NeutronDbObject class or None
        """
        lookup_keys = set(kwargs.keys())
        all_keys = itertools.chain([cls.primary_keys], cls.unique_keys)
        if not any(lookup_keys.issuperset(keys) for keys in all_keys):
            missing_keys = set(cls.primary_keys).difference(lookup_keys)
            raise o_exc.NeutronPrimaryKeyMissing(object_class=cls,
                                                 missing_keys=missing_keys)

        with cls.db_context_reader(context):
            db_obj = obj_db_api.get_object(
                cls, context, **cls.modify_fields_to_db(kwargs))
            if db_obj:
                return cls._load_object(context, db_obj)
开发者ID:mmalchuk,项目名称:openstack-neutron,代码行数:21,代码来源:base.py


示例11: _get_object_policy

 def _get_object_policy(cls, context, model, **kwargs):
     with db_api.autonested_transaction(context.session):
         binding_db_obj = obj_db_api.get_object(context, model, **kwargs)
         if binding_db_obj:
             return cls.get_object(context, id=binding_db_obj['policy_id'])
开发者ID:eayunstack,项目名称:neutron,代码行数:5,代码来源:policy.py


示例12: test_get_object_with_None_value_in_filters

 def test_get_object_with_None_value_in_filters(self):
     obj = api.create_object(self.ctxt, self.model, {'name': 'foo'})
     new_obj = api.get_object(
         self.ctxt, self.model, name='foo', status=None)
     self.assertEqual(obj, new_obj)
开发者ID:eayunstack,项目名称:neutron,代码行数:5,代码来源:test_api.py


示例13: _get_object_policy

 def _get_object_policy(cls, context, binding_cls, **kwargs):
     with cls.db_context_reader(context):
         binding_db_obj = obj_db_api.get_object(binding_cls, context,
                                                **kwargs)
         if binding_db_obj:
             return cls.get_object(context, id=binding_db_obj['policy_id'])
开发者ID:openstack,项目名称:neutron,代码行数:6,代码来源:policy.py


示例14: _create_fip_qos_db

 def _create_fip_qos_db(self, context, fip_id, policy_id):
     policy = self._get_policy_obj(context, policy_id)
     policy.attach_floatingip(fip_id)
     binding_db_obj = obj_db_api.get_object(
         context, policy.fip_binding_model, fip_id=fip_id)
     return binding_db_obj
开发者ID:eayunstack,项目名称:neutron,代码行数:6,代码来源:l3_fip_qos.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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