本文整理汇总了Python中webob.exc.format_message函数的典型用法代码示例。如果您正苦于以下问题:Python format_message函数的具体用法?Python format_message怎么用?Python format_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了format_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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())
示例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())
示例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}}
示例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}}
示例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}
示例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())
'''
示例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}}
示例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())
示例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())
示例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())
示例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())
示例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())
示例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())
示例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)
示例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}}