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

Python exc.format_message函数代码示例

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

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



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

示例1: _create

    def _create(self, req, body, **keypair_filters):
        context = req.environ["patron.context"]
        authorize(context, action="create")

        params = body["keypair"]
        name = params["name"]
        key_type = params.get("type", keypair_obj.KEYPAIR_TYPE_SSH)

        try:
            if "public_key" in params:
                keypair = self.api.import_key_pair(context, context.user_id, name, params["public_key"], key_type)
                keypair = self._filter_keypair(keypair, user_id=True, **keypair_filters)
            else:
                keypair, private_key = self.api.create_key_pair(context, context.user_id, name, key_type)
                keypair = self._filter_keypair(keypair, user_id=True, **keypair_filters)
                keypair["private_key"] = private_key

            return {"keypair": keypair}

        except exception.KeypairLimitExceeded:
            msg = _("Quota exceeded, too many key pairs.")
            raise webob.exc.HTTPForbidden(explanation=msg)
        except exception.InvalidKeypair as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
        except exception.KeyPairExists as exc:
            raise webob.exc.HTTPConflict(explanation=exc.format_message())
开发者ID:hsluoyz,项目名称:patron,代码行数:26,代码来源:keypairs.py


示例2: _create

    def _create(self, req, body, user_id=None, **keypair_filters):
        context = req.environ['nova.context']
        params = body['keypair']
        name = common.normalize_name(params['name'])
        key_type = params.get('type', keypair_obj.KEYPAIR_TYPE_SSH)
        user_id = user_id or context.user_id
        context.can(kp_policies.POLICY_ROOT % 'create',
                    target={'user_id': user_id,
                            'project_id': context.project_id})

        try:
            if 'public_key' in params:
                keypair = self.api.import_key_pair(context,
                                              user_id, name,
                                              params['public_key'], key_type)
                keypair = self._filter_keypair(keypair, user_id=True,
                                               **keypair_filters)
            else:
                keypair, private_key = self.api.create_key_pair(
                    context, user_id, name, key_type)
                keypair = self._filter_keypair(keypair, user_id=True,
                                               **keypair_filters)
                keypair['private_key'] = private_key

            return {'keypair': keypair}

        except exception.KeypairLimitExceeded:
            msg = _("Quota exceeded, too many key pairs.")
            raise webob.exc.HTTPForbidden(explanation=msg)
        except exception.InvalidKeypair as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
        except exception.KeyPairExists as exc:
            raise webob.exc.HTTPConflict(explanation=exc.format_message())
开发者ID:klmitch,项目名称:nova,代码行数:33,代码来源:keypairs.py


示例3: create

    def create(self, req, body):
        """Bulk create floating ips."""
        context = req.environ['nova.context']
        authorize(context)

        if 'floating_ips_bulk_create' not in body:
            raise webob.exc.HTTPUnprocessableEntity()
        params = body['floating_ips_bulk_create']

        LOG.debug(params)

        if 'ip_range' not in params:
            raise webob.exc.HTTPUnprocessableEntity()
        ip_range = params['ip_range']

        pool = params.get('pool', CONF.default_floating_pool)
        interface = params.get('interface', CONF.public_interface)

        try:
            ips = ({'address': str(address),
                    'pool': pool,
                    'interface': interface}
                   for address in self._address_to_hosts(ip_range))
        except exception.InvalidInput as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

        try:
            db.floating_ip_bulk_create(context, ips)
        except exception.FloatingIpExists as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

        return {"floating_ips_bulk_create": {"ip_range": ip_range,
                                               "pool": pool,
                                               "interface": interface}}
开发者ID:AnyBucket,项目名称:nova,代码行数:34,代码来源:floating_ips_bulk.py


示例4: create

    def create(self, req, body):
        """Bulk create floating IPs."""
        context = req.environ['nova.context']
        authorize(context)

        if 'floating_ips_bulk_create' not in body:
            raise webob.exc.HTTPUnprocessableEntity()
        params = body['floating_ips_bulk_create']

        if 'ip_range' not in params:
            raise webob.exc.HTTPUnprocessableEntity()
        ip_range = params['ip_range']

        pool = params.get('pool', CONF.default_floating_pool)
        interface = params.get('interface', CONF.public_interface)

        try:
            ips = [objects.FloatingIPList.make_ip_info(addr, pool, interface)
                   for addr in self._address_to_hosts(ip_range)]
        except exception.InvalidInput as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

        try:
            objects.FloatingIPList.create(context, ips)
        except exception.FloatingIpExists as exc:
            raise webob.exc.HTTPConflict(explanation=exc.format_message())

        return {"floating_ips_bulk_create": {"ip_range": ip_range,
                                               "pool": pool,
                                               "interface": interface}}
开发者ID:BeyondTheClouds,项目名称:nova,代码行数:30,代码来源:floating_ips_bulk.py


示例5: _show

    def _show(self, req, id, **keypair_filters):
        """Return data for the given key name."""
        context = req.environ["patron.context"]
        authorize(context, action="show")

        try:
            # The return object needs to be a dict in order to pop the 'type'
            # field, if the api_version < 2.2.
            keypair = self.api.get_key_pair(context, context.user_id, id)
            keypair = self._filter_keypair(
                keypair,
                created_at=True,
                deleted=True,
                deleted_at=True,
                id=True,
                user_id=True,
                updated_at=True,
                **keypair_filters
            )
        except exception.KeypairNotFound as exc:
            raise webob.exc.HTTPNotFound(explanation=exc.format_message())
        # TODO(oomichi): It is necessary to filter a response of keypair with
        # _filter_keypair() when v2.1+microversions for implementing consistent
        # behaviors in this keypair resource.
        return {"keypair": keypair}
开发者ID:hsluoyz,项目名称:patron,代码行数:25,代码来源:keypairs.py


示例6: index

    def index(self, req):
        """List of attributes for a user."""
        context = req.environ['nova.context']
        #authorize(context, action='create')
        '''
        try:
            params = body['attribute']
            name = params['name']
        except KeyError:
            msg = _("Invalid request body")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        '''
        try:
	      #print "IASDASDASDASDASDI am here"
              attlist=self.api.list(context)
	      attribute = []
              for att in attlist: 
                attribute.append({'id': att.id,
                           'name': att.name})
	      print attribute 
              return {'attribute': attribute}	
	

        except exception.InvalidAttribute as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
        '''
开发者ID:kbijon,项目名称:OpenStack-CVRM,代码行数:26,代码来源:attributes.py


示例7: update

    def update(self, req, id, body):
        """Update an existing agent build."""
        context = req.environ['nova.context']
        authorize(context)

        try:
            para = body['para']
            url = para['url']
            md5hash = para['md5hash']
            version = para['version']
        except (TypeError, KeyError):
            raise webob.exc.HTTPUnprocessableEntity()

        try:
            utils.check_string_length(url, 'url', max_length=255)
            utils.check_string_length(md5hash, 'md5hash', max_length=255)
            utils.check_string_length(version, 'version', max_length=255)
        except exception.InvalidInput as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

        try:
            db.agent_build_update(context, id,
                                {'version': version,
                                 'url': url,
                                 'md5hash': md5hash})
        except exception.AgentBuildNotFound as ex:
            raise webob.exc.HTTPNotFound(explanation=ex.format_message())

        # NOTE(alex_xu): The agent_id should be integer that consistent with
        # create/index actions. But parameter 'id' is string type that parsed
        # from url. This is a bug, but because back-compatibility, it can't be
        # fixed for v2 API. This will be fixed after v3 API feature exposed by
        # micro-version in the future. lp bug #1333494
        return {"agent": {'agent_id': id, 'version': version,
                'url': url, 'md5hash': md5hash}}
开发者ID:PFZheng,项目名称:nova,代码行数:35,代码来源:agents.py


示例8: test_create_attach_interfaces_policy_failed

 def test_create_attach_interfaces_policy_failed(self):
     exc = self.assertRaises(
         exception.PolicyNotAuthorized,
         self.controller.create, self.req, fakes.FAKE_UUID, body={})
     self.assertEqual(
         "Policy doesn't allow {0!s} to be performed.".format(self.rule_name),
         exc.format_message())
开发者ID:runt18,项目名称:nova,代码行数:7,代码来源:test_attach_interfaces.py


示例9: list

    def list(self, req):
        """Create or import attribute.

        Sending name will generate a key and return private_key
        and fingerprint.

        You can send a public_key to add an existing ssh key

        params: attribute object with:
            name (required) - string
            public_key (optional) - string
        """
        traceback.print_stack()
        context = req.environ["nova.context"]
        # authorize(context, action='create')
        """
        try:
            params = body['attribute']
            name = params['name']
        except KeyError:
            msg = _("Invalid request body")
            raise webob.exc.HTTPBadRequest(explanation=msg)
        """
        try:
            # for att in attribute:
            # 	print att.name
            attribute = self.api.attribute_list(context)

        except exception.InvalidAttribute as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
开发者ID:kbijon,项目名称:OpenStack-CVRM,代码行数:30,代码来源:scopes_backup.py


示例10: test_delete_attach_interfaces_policy_failed

 def test_delete_attach_interfaces_policy_failed(self):
     exc = self.assertRaises(
         exception.PolicyNotAuthorized,
         self.controller.delete, self.req, fakes.FAKE_UUID, FAKE_PORT_ID1)
     self.assertEqual(
         "Policy doesn't allow %s to be performed." % self.rule_name,
         exc.format_message())
开发者ID:B3n0n3,项目名称:nova,代码行数:7,代码来源:test_attach_interfaces.py


示例11: test_remove_host_no_admin

 def test_remove_host_no_admin(self):
     exc = self.assertRaises(exception.PolicyNotAuthorized,
                             self.controller._remove_host,
                             self.user_req, "1",
                             body={"remove_host": {"host": "host1"}})
     self.assertIn("compute_extension:v3:os-aggregates:remove_host",
                   exc.format_message())
开发者ID:Cisco-OCPChina,项目名称:nova,代码行数:7,代码来源:test_aggregates.py


示例12: _update

 def _update(self, context, host, binary, payload):
     """Do the actual PUT/update"""
     try:
         self.host_api.service_update(context, host, binary, payload)
     except (exception.HostBinaryNotFound,
             exception.HostMappingNotFound) as exc:
         raise webob.exc.HTTPNotFound(explanation=exc.format_message())
开发者ID:mikalstill,项目名称:nova,代码行数:7,代码来源:services.py


示例13: _common_policy_check

 def _common_policy_check(self, rules, rule_name, func, *arg, **kwarg):
     self.policy.set_rules(rules)
     exc = self.assertRaises(
          exception.PolicyNotAuthorized, func, *arg, **kwarg)
     self.assertEqual(
         "Policy doesn't allow %s to be performed." % rule_name,
         exc.format_message())
开发者ID:ravikamachi,项目名称:nova,代码行数:7,代码来源:test_volumes.py


示例14: delete

    def delete(self, req, id):
        """Deletes the specified service."""
        context = req.environ['nova.context']
        context.can(services_policies.BASE_POLICY_NAME)

        try:
            utils.validate_integer(id, 'id')
        except exception.InvalidInput as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

        try:
            service = self.host_api.service_get_by_id(context, id)
            # remove the service from all the aggregates in which it's included
            if service.binary == 'nova-compute':
                aggrs = self.aggregate_api.get_aggregates_by_host(context,
                                                                  service.host)
                for ag in aggrs:
                    self.aggregate_api.remove_host_from_aggregate(context,
                                                                  ag.id,
                                                                  service.host)
            self.host_api.service_delete(context, id)

        except exception.ServiceNotFound:
            explanation = _("Service %s not found.") % id
            raise webob.exc.HTTPNotFound(explanation=explanation)
开发者ID:2020human,项目名称:nova,代码行数:25,代码来源:services.py


示例15: update

    def update(self, req, id, body):
        """Update an existing agent build."""
        context = req.environ['nova.context']
        authorize(context)

        try:
            para = body['agent']
            url = para['url']
            md5hash = para['md5hash']
            version = para['version']
        except TypeError as e:
            raise webob.exc.HTTPBadRequest()
        except KeyError as e:
            raise webob.exc.HTTPBadRequest(explanation=_(
                "Could not find %s parameter in the request") % e.args[0])

        try:
            utils.check_string_length(url, 'url', max_length=255)
            utils.check_string_length(md5hash, 'md5hash', max_length=255)
            utils.check_string_length(version, 'version', max_length=255)
        except exception.InvalidInput as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())

        try:
            db.agent_build_update(context, id,
                                {'version': version,
                                 'url': url,
                                 'md5hash': md5hash})
        except exception.AgentBuildNotFound as ex:
            raise webob.exc.HTTPNotFound(explanation=ex.format_message())

        return {"agent": {'agent_id': id, 'version': version,
                'url': url, 'md5hash': md5hash}}
开发者ID:674009287,项目名称:nova,代码行数:33,代码来源:agents.py


示例16: create

    def create(self, req, body):
        """Create or import attribute.

        Sending name will generate a key and return private_key
        and fingerprint.

        You can send a public_key to add an existing ssh key

        params: attribute object with:
            name (required) - string
            public_key (optional) - string
        """
        # traceback.print_stack()
        context = req.environ["nova.context"]
        authorize(context, action="create")

        try:
            params = body["attribute"]
            name = params["name"]
        except KeyError:
            msg = _("Invalid request body")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            attribute = self.api.create_attribute(context, name)

            return {"attribute": attribute}

        except exception.InvalidAttribute as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
开发者ID:kbijon,项目名称:OpenStack-CVRM,代码行数:30,代码来源:scopes_backup.py


示例17: create

    def create(self, req, body):
        """
        Create or import keypair.

        Sending name will generate a key and return private_key
        and fingerprint.

        You can send a public_key to add an existing ssh key

        params: keypair object with:
            name (required) - string
            public_key (optional) - string
        """

        context = req.environ['nova.context']
        authorize(context, action='create')

        try:
            params = body['keypair']
            name = params['name']
        except KeyError:
            msg = _("Invalid request body")
            raise webob.exc.HTTPBadRequest(explanation=msg)

        try:
            if 'public_key' in params:
                keypair = self.api.import_key_pair(context,
                                              context.user_id, name,
                                              params['public_key'])
                keypair = self._filter_keypair(keypair, user_id=True)
            else:
                keypair, private_key = self.api.create_key_pair(
                    context, context.user_id, name)
                keypair = self._filter_keypair(keypair, user_id=True)
                keypair['private_key'] = private_key

            return {'keypair': keypair}

        except exception.KeypairLimitExceeded:
            msg = _("Quota exceeded, too many key pairs.")
            raise webob.exc.HTTPRequestEntityTooLarge(
                        explanation=msg,
                        headers={'Retry-After': 0})
        except exception.InvalidKeypair as exc:
            raise webob.exc.HTTPBadRequest(explanation=exc.format_message())
        except exception.KeyPairExists as exc:
            raise webob.exc.HTTPConflict(explanation=exc.format_message())
开发者ID:674009287,项目名称:nova,代码行数:47,代码来源:keypairs.py


示例18: test_set_metadata_no_admin

 def test_set_metadata_no_admin(self):
     exc = self.assertRaises(exception.PolicyNotAuthorized,
                             self.controller._set_metadata,
                             self.user_req, "1",
                             body={"set_metadata": {"metadata":
                                                   {"foo": "bar"}}})
     self.assertIn("compute_extension:v3:os-aggregates:set_metadata",
                   exc.format_message())
开发者ID:Cisco-OCPChina,项目名称:nova,代码行数:8,代码来源:test_aggregates.py


示例19: delete

 def delete(self, req, id):
     """Delete a keypair with a given name."""
     context = req.environ["nova.context"]
     authorize(context, action="delete")
     try:
         self.api.delete_key_pair(context, context.user_id, id)
     except exception.KeypairNotFound as exc:
         raise webob.exc.HTTPNotFound(explanation=exc.format_message())
开发者ID:AsherBond,项目名称:nova,代码行数:8,代码来源:keypairs.py


示例20: test_create_no_admin

 def test_create_no_admin(self):
     exc = self.assertRaises(exception.PolicyNotAuthorized,
                             self.controller.create, self.user_req,
                             {"aggregate":
                                 {"name": "test",
                                 "availability_zone": "nova1"}})
     self.assertIn("compute_extension:v3:os-aggregates:create",
                   exc.format_message())
开发者ID:Cisco-OCPChina,项目名称:nova,代码行数:8,代码来源:test_aggregates.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

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

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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