本文整理汇总了Python中webob.exc.HTTPBadRequest方法的典型用法代码示例。如果您正苦于以下问题:Python exc.HTTPBadRequest方法的具体用法?Python exc.HTTPBadRequest怎么用?Python exc.HTTPBadRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webob.exc
的用法示例。
在下文中一共展示了exc.HTTPBadRequest方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def update(self, req, share_id, id, body):
try:
meta_item = body['meta']
except (TypeError, KeyError):
expl = _('Malformed request body')
raise exc.HTTPBadRequest(explanation=expl)
if id not in meta_item:
expl = _('Request body and URI mismatch')
raise exc.HTTPBadRequest(explanation=expl)
if len(meta_item) > 1:
expl = _('Request body contains too many items')
raise exc.HTTPBadRequest(explanation=expl)
context = req.environ['manila.context']
self._update_share_metadata(context,
share_id,
meta_item,
delete=False)
return {'meta': meta_item}
示例2: _update_share_metadata
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _update_share_metadata(self, context,
share_id, metadata,
delete=False):
try:
share = self.share_api.get(context, share_id)
return self.share_api.update_share_metadata(context,
share,
metadata,
delete)
except exception.NotFound:
msg = _('share does not exist')
raise exc.HTTPNotFound(explanation=msg)
except (ValueError, AttributeError):
msg = _("Malformed request body")
raise exc.HTTPBadRequest(explanation=msg)
except exception.InvalidMetadata as error:
raise exc.HTTPBadRequest(explanation=error.msg)
except exception.InvalidMetadataSize as error:
raise exc.HTTPBadRequest(explanation=error.msg)
示例3: _parse_is_public
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _parse_is_public(is_public):
"""Parse is_public into something usable.
:returns:
- True: API should list public share group types only
- False: API should list private share group types only
- None: API should list both public and private share group types
"""
if is_public is None:
# preserve default value of showing only public types
return True
elif six.text_type(is_public).lower() == "all":
return None
else:
try:
return strutils.bool_from_string(is_public, strict=True)
except ValueError:
msg = _('Invalid is_public filter [%s]') % is_public
raise exc.HTTPBadRequest(explanation=msg)
示例4: _parse_is_public
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _parse_is_public(is_public):
"""Parse is_public into something usable.
* True: API should list public share types only
* False: API should list private share types only
* None: API should list both public and private share types
"""
if is_public is None:
# preserve default value of showing only public types
return True
elif six.text_type(is_public).lower() == "all":
return None
else:
try:
return strutils.bool_from_string(is_public, strict=True)
except ValueError:
msg = _('Invalid is_public filter [%s]') % is_public
raise exc.HTTPBadRequest(explanation=msg)
示例5: _delete
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _delete(self, req, id):
"""Deletes an existing share type."""
context = req.environ['manila.context']
try:
share_type = share_types.get_share_type(context, id)
share_types.destroy(context, share_type['id'])
self._notify_share_type_info(
context, 'share_type.delete', share_type)
except exception.ShareTypeInUse as err:
notifier_err = dict(id=id, error_message=six.text_type(err))
self._notify_share_type_error(context, 'share_type.delete',
notifier_err)
msg = 'Target share type is still in use.'
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.NotFound as err:
notifier_err = dict(id=id, error_message=six.text_type(err))
self._notify_share_type_error(context, 'share_type.delete',
notifier_err)
raise webob.exc.HTTPNotFound()
return webob.Response(status_int=http_client.ACCEPTED)
示例6: _validate_revert_parameters
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _validate_revert_parameters(self, context, body):
if not (body and self.is_valid_body(body, 'revert')):
msg = _("Revert entity not found in request body.")
raise exc.HTTPBadRequest(explanation=msg)
required_parameters = ('snapshot_id',)
data = body['revert']
for parameter in required_parameters:
if parameter not in data:
msg = _("Required parameter %s not found.") % parameter
raise exc.HTTPBadRequest(explanation=msg)
if not data.get(parameter):
msg = _("Required parameter %s is empty.") % parameter
raise exc.HTTPBadRequest(explanation=msg)
return data
示例7: delete
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def delete(self, req, id):
"""Delete a replica."""
context = req.environ['manila.context']
try:
replica = db.share_replica_get(context, id)
except exception.ShareReplicaNotFound:
msg = _("No replica exists with ID %s.")
raise exc.HTTPNotFound(explanation=msg % id)
try:
self.share_api.delete_share_replica(context, replica)
except exception.ReplicationException as e:
raise exc.HTTPBadRequest(explanation=six.text_type(e))
return webob.Response(status_int=http_client.ACCEPTED)
示例8: promote
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def promote(self, req, id, body):
"""Promote a replica to active state."""
context = req.environ['manila.context']
try:
replica = db.share_replica_get(context, id)
except exception.ShareReplicaNotFound:
msg = _("No replica exists with ID %s.")
raise exc.HTTPNotFound(explanation=msg % id)
replica_state = replica.get('replica_state')
if replica_state == constants.REPLICA_STATE_ACTIVE:
return webob.Response(status_int=http_client.OK)
try:
replica = self.share_api.promote_share_replica(context, replica)
except exception.ReplicationException as e:
raise exc.HTTPBadRequest(explanation=six.text_type(e))
except exception.AdminRequired as e:
raise exc.HTTPForbidden(explanation=six.text_type(e))
return self._view_builder.detail(req, replica)
示例9: resync
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def resync(self, req, id, body):
"""Attempt to update/sync the replica with its source."""
context = req.environ['manila.context']
try:
replica = db.share_replica_get(context, id)
except exception.ShareReplicaNotFound:
msg = _("No replica exists with ID %s.")
raise exc.HTTPNotFound(explanation=msg % id)
replica_state = replica.get('replica_state')
if replica_state == constants.REPLICA_STATE_ACTIVE:
return webob.Response(status_int=http_client.OK)
try:
self.share_api.update_share_replica(context, replica)
except exception.InvalidHost as e:
raise exc.HTTPBadRequest(explanation=six.text_type(e))
示例10: _update_share_group
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _update_share_group(self, req, id, body):
"""Update a share group."""
context = req.environ['manila.context']
if not self.is_valid_body(body, 'share_group'):
msg = _("'share_group' is missing from the request body.")
raise exc.HTTPBadRequest(explanation=msg)
share_group_data = body['share_group']
valid_update_keys = {'name', 'description'}
invalid_fields = set(share_group_data.keys()) - valid_update_keys
if invalid_fields:
msg = _("The fields %s are invalid or not allowed to be updated.")
raise exc.HTTPBadRequest(explanation=msg % invalid_fields)
share_group = self._get_share_group(context, id)
share_group = self.share_group_api.update(
context, share_group, share_group_data)
return self._view_builder.detail(req, share_group)
示例11: _update_group_snapshot
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _update_group_snapshot(self, req, id, body):
"""Update a share group snapshot."""
context = req.environ['manila.context']
key = 'share_group_snapshot'
if not self.is_valid_body(body, key):
msg = _("'%s' is missing from the request body.") % key
raise exc.HTTPBadRequest(explanation=msg)
sg_snapshot_data = body[key]
valid_update_keys = {
'name',
'description',
}
invalid_fields = set(sg_snapshot_data.keys()) - valid_update_keys
if invalid_fields:
msg = _("The fields %s are invalid or not allowed to be updated.")
raise exc.HTTPBadRequest(explanation=msg % invalid_fields)
sg_snapshot = self._get_share_group_snapshot(context, id)
sg_snapshot = self.share_group_api.update_share_group_snapshot(
context, sg_snapshot, sg_snapshot_data)
return self._view_builder.detail(req, sg_snapshot)
示例12: _manage
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _manage(self, req, body):
"""Manage a share server."""
LOG.debug("Manage Share Server with id: %s", id)
context = req.environ['manila.context']
identifier, host, share_network, driver_opts, network_subnet = (
self._validate_manage_share_server_parameters(context, body))
try:
result = self.share_api.manage_share_server(
context, identifier, host, network_subnet, driver_opts)
except exception.InvalidInput as e:
raise exc.HTTPBadRequest(explanation=e.msg)
except exception.PolicyNotAuthorized as e:
raise exc.HTTPForbidden(explanation=e.msg)
result.project_id = share_network["project_id"]
result.share_network_id = share_network["id"]
if share_network['name']:
result.share_network_name = share_network['name']
else:
result.share_network_name = share_network['id']
return self._view_builder.build_share_server(req, result)
示例13: _remove_security_service
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def _remove_security_service(self, req, id, data):
"""Dissociate share network from a given security service."""
context = req.environ['manila.context']
policy.check_policy(context, RESOURCE_NAME, 'remove_security_service')
share_network = db_api.share_network_get(context, id)
if self._share_network_subnets_contain_share_servers(share_network):
msg = _("Cannot remove security services. Share network is used.")
raise exc.HTTPForbidden(explanation=msg)
try:
share_network = db_api.share_network_remove_security_service(
context,
id,
data['security_service_id'])
except KeyError:
msg = "Malformed request body"
raise exc.HTTPBadRequest(explanation=msg)
except exception.NotFound as e:
raise exc.HTTPNotFound(explanation=six.text_type(e))
except exception.ShareNetworkSecurityServiceDissociationError as e:
raise exc.HTTPBadRequest(explanation=six.text_type(e))
return self._view_builder.build_share_network(req, share_network)
示例14: test_create_no_share_id
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def test_create_no_share_id(self):
body = {
'share_replica': {
'share_id': None,
'availability_zone': None,
}
}
mock__view_builder_call = self.mock_object(
share_replicas.replication_view.ReplicationViewBuilder,
'detail_list')
self.assertRaises(exc.HTTPBadRequest,
self.controller.create,
self.replicas_req, body)
self.assertFalse(mock__view_builder_call.called)
self.mock_policy_check.assert_called_once_with(
self.member_context, self.resource_name, 'create')
示例15: test_create_exception_path
# 需要导入模块: from webob import exc [as 别名]
# 或者: from webob.exc import HTTPBadRequest [as 别名]
def test_create_exception_path(self, exception_type):
fake_replica, _ = self._get_fake_replica(
replication_type='writable')
mock__view_builder_call = self.mock_object(
share_replicas.replication_view.ReplicationViewBuilder,
'detail_list')
body = {
'share_replica': {
'share_id': 'FAKE_SHAREID',
'availability_zone': 'FAKE_AZ'
}
}
exc_args = {'id': 'xyz', 'reason': 'abc'}
self.mock_object(share_replicas.db, 'share_get',
mock.Mock(return_value=fake_replica))
self.mock_object(share.API, 'create_share_replica',
mock.Mock(side_effect=exception_type(**exc_args)))
self.assertRaises(exc.HTTPBadRequest,
self.controller.create,
self.replicas_req, body)
self.assertFalse(mock__view_builder_call.called)
self.mock_policy_check.assert_called_once_with(
self.member_context, self.resource_name, 'create')