Fix compatibility with falcon >= 4.0
The falcon library deprecated some interfaces used in zaqar in 3.0 and removed these in 4.0 . Replace the removed interfaces to fix compatibility with the latest release of the library. * The `body` attribute of Reponse class was removed [1] * HTTP error classes now accepts only keyword arguments [2] [1]c76f44248a
[2]0b9d26c7f6
Change-Id: Ied13446be2e1b5cb7c5839a84e8ad2413cca6fe3
This commit is contained in:
parent
fecef8a839
commit
4543e7691c
4
releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml
Normal file
4
releasenotes/notes/falcon-4-e4b5aab856e3228c.yaml
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
---
|
||||||
|
fixes:
|
||||||
|
- |
|
||||||
|
Fixed compatibility with falcon 4.0.0 and later.
|
@ -96,15 +96,16 @@ def extract_project_id(req, resp, params):
|
|||||||
# a check for the project-id.
|
# a check for the project-id.
|
||||||
return
|
return
|
||||||
if params['project_id'] == "":
|
if params['project_id'] == "":
|
||||||
raise falcon.HTTPBadRequest('Empty project header not allowed',
|
raise falcon.HTTPBadRequest(
|
||||||
_(u'X-PROJECT-ID cannot be an empty '
|
title='Empty project header not allowed',
|
||||||
u'string. Specify the right header '
|
description=_('X-PROJECT-ID cannot be an empty string. Specify '
|
||||||
u'X-PROJECT-ID and retry.'))
|
'the right header X-PROJECT-ID and retry.'))
|
||||||
|
|
||||||
if not params['project_id'] and versionutils.is_compatible(
|
if not params['project_id'] and versionutils.is_compatible(
|
||||||
'v1.1', api_version_string, same_major=False):
|
'v1.1', api_version_string, same_major=False):
|
||||||
raise falcon.HTTPBadRequest('Project-Id Missing',
|
raise falcon.HTTPBadRequest(
|
||||||
_(u'The header X-PROJECT-ID was missing'))
|
title='Project-Id Missing',
|
||||||
|
description=_('The header X-PROJECT-ID was missing'))
|
||||||
|
|
||||||
|
|
||||||
def require_client_id(validate, req, resp, params):
|
def require_client_id(validate, req, resp, params):
|
||||||
@ -127,10 +128,11 @@ def require_client_id(validate, req, resp, params):
|
|||||||
try:
|
try:
|
||||||
validate(req.get_header('Client-ID', required=True))
|
validate(req.get_header('Client-ID', required=True))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
description = _(u'Malformed hexadecimal UUID.')
|
description = _('Malformed hexadecimal UUID.')
|
||||||
raise falcon.HTTPBadRequest('Wrong UUID value', description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title='Wrong UUID value', description=description)
|
||||||
except validation.ValidationFailed as ex:
|
except validation.ValidationFailed as ex:
|
||||||
raise falcon.HTTPBadRequest(str(ex))
|
raise falcon.HTTPBadRequest(title=str(ex))
|
||||||
else:
|
else:
|
||||||
# NOTE(wanghao): Since we changed the get_client_uuid to support
|
# NOTE(wanghao): Since we changed the get_client_uuid to support
|
||||||
# other format of client id, so need to check the uuid here for
|
# other format of client id, so need to check the uuid here for
|
||||||
@ -140,8 +142,9 @@ def require_client_id(validate, req, resp, params):
|
|||||||
if client_id or client_id == '':
|
if client_id or client_id == '':
|
||||||
uuid.UUID(client_id)
|
uuid.UUID(client_id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
description = _(u'Malformed hexadecimal UUID.')
|
description = _('Malformed hexadecimal UUID.')
|
||||||
raise falcon.HTTPBadRequest('Wrong UUID value', description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title='Wrong UUID value', description=description)
|
||||||
|
|
||||||
|
|
||||||
def validate_queue_identification(validate, req, resp, params):
|
def validate_queue_identification(validate, req, resp, params):
|
||||||
@ -178,9 +181,10 @@ def validate_queue_identification(validate, req, resp, params):
|
|||||||
u'project: %(project)s',
|
u'project: %(project)s',
|
||||||
{'queue': queue, 'project': project})
|
{'queue': queue, 'project': project})
|
||||||
|
|
||||||
raise falcon.HTTPBadRequest(_(u'Invalid queue identification'),
|
raise falcon.HTTPBadRequest(
|
||||||
_(u'The format of the submitted queue '
|
title=_('Invalid queue identification'),
|
||||||
u'name or project id is not valid.'))
|
description=_('The format of the submitted queue '
|
||||||
|
'name or project id is not valid.'))
|
||||||
|
|
||||||
|
|
||||||
def require_accepts_json(req, resp, params):
|
def require_accepts_json(req, resp, params):
|
||||||
@ -199,11 +203,11 @@ def require_accepts_json(req, resp, params):
|
|||||||
"""
|
"""
|
||||||
if not req.client_accepts('application/json'):
|
if not req.client_accepts('application/json'):
|
||||||
raise falcon.HTTPNotAcceptable(
|
raise falcon.HTTPNotAcceptable(
|
||||||
u'''
|
description='Endpoint only serves `application/json`; '
|
||||||
Endpoint only serves `application/json`; specify client-side
|
'specify client-side media type support with '
|
||||||
media type support with the "Accept" header.''',
|
'the "Accept" header.',
|
||||||
href=u'http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html',
|
href='http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html',
|
||||||
href_text=u'14.1 Accept, Hypertext Transfer Protocol -- HTTP/1.1')
|
href_text='14.1 Accept, Hypertext Transfer Protocol -- HTTP/1.1')
|
||||||
|
|
||||||
|
|
||||||
def require_content_type_be_non_urlencoded(req, resp, params):
|
def require_content_type_be_non_urlencoded(req, resp, params):
|
||||||
@ -232,13 +236,13 @@ def require_content_type_be_non_urlencoded(req, resp, params):
|
|||||||
return
|
return
|
||||||
if req.content_type and (req.content_type.lower() ==
|
if req.content_type and (req.content_type.lower() ==
|
||||||
'application/x-www-form-urlencoded'):
|
'application/x-www-form-urlencoded'):
|
||||||
title = _(u'Invalid Content-Type')
|
title = _('Invalid Content-Type')
|
||||||
description = _(u'Endpoint does not accept '
|
description = _('Endpoint does not accept '
|
||||||
u'`application/x-www-form-urlencoded` content; '
|
'`application/x-www-form-urlencoded` content; '
|
||||||
u'currently supported media type is '
|
'currently supported media type is '
|
||||||
u'`application/json`; specify proper client-side '
|
'`application/json`; specify proper client-side '
|
||||||
u'media type with the "Content-Type" header.')
|
'media type with the "Content-Type" header.')
|
||||||
raise falcon.HTTPBadRequest(title, description)
|
raise falcon.HTTPBadRequest(title=title, description=description)
|
||||||
|
|
||||||
|
|
||||||
def inject_context(req, resp, params):
|
def inject_context(req, resp, params):
|
||||||
@ -306,13 +310,14 @@ def validate_topic_identification(validate, req, resp, params):
|
|||||||
project = params['project_id']
|
project = params['project_id']
|
||||||
queue = params['topic_name']
|
queue = params['topic_name']
|
||||||
|
|
||||||
LOG.debug(u'Invalid topic name "%(topic)s" submitted for '
|
LOG.debug('Invalid topic name "%(topic)s" submitted for '
|
||||||
u'project: %(project)s',
|
'project: %(project)s',
|
||||||
{'topic': queue, 'project': project})
|
{'topic': queue, 'project': project})
|
||||||
|
|
||||||
raise falcon.HTTPBadRequest(_(u'Invalid topic identification'),
|
raise falcon.HTTPBadRequest(
|
||||||
_(u'The format of the submitted topic '
|
title=_('Invalid topic identification'),
|
||||||
u'name or project id is not valid.'))
|
description=_('The format of the submitted topic '
|
||||||
|
'name or project id is not valid.'))
|
||||||
|
|
||||||
|
|
||||||
def verify_extra_spec(req, resp, params):
|
def verify_extra_spec(req, resp, params):
|
||||||
@ -333,9 +338,10 @@ def verify_extra_spec(req, resp, params):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if extra_spec == "":
|
if extra_spec == "":
|
||||||
raise falcon.HTTPBadRequest('Empty extra spec not allowed',
|
raise falcon.HTTPBadRequest(
|
||||||
_(u'Extra spec cannot be an empty '
|
title='Empty extra spec not allowed',
|
||||||
u'if specify the header.'))
|
description=_('Extra spec cannot be an empty '
|
||||||
|
'if specify the header.'))
|
||||||
extra_spec_schema = extra_spec.split(':')[0]
|
extra_spec_schema = extra_spec.split(':')[0]
|
||||||
if extra_spec_schema:
|
if extra_spec_schema:
|
||||||
mgr = driver.DriverManager('zaqar.extraspec.tasks', extra_spec_schema,
|
mgr = driver.DriverManager('zaqar.extraspec.tasks', extra_spec_schema,
|
||||||
|
@ -170,8 +170,9 @@ class Driver(transport.DriverBase):
|
|||||||
if isinstance(exc, falcon.HTTPError):
|
if isinstance(exc, falcon.HTTPError):
|
||||||
raise
|
raise
|
||||||
LOG.exception('Internal server error')
|
LOG.exception('Internal server error')
|
||||||
raise falcon.HTTPInternalServerError('Internal server error',
|
raise falcon.HTTPInternalServerError(
|
||||||
str(exc))
|
title='Internal server error',
|
||||||
|
description=str(exc))
|
||||||
|
|
||||||
def _get_server_cls(self, host):
|
def _get_server_cls(self, host):
|
||||||
"""Return an appropriate WSGI server class base on provided host
|
"""Return an appropriate WSGI server class base on provided host
|
||||||
|
@ -21,37 +21,39 @@ from zaqar.i18n import _
|
|||||||
class HTTPServiceUnavailable(falcon.HTTPServiceUnavailable):
|
class HTTPServiceUnavailable(falcon.HTTPServiceUnavailable):
|
||||||
"""Wraps falcon.HTTPServiceUnavailable with Zaqar messaging."""
|
"""Wraps falcon.HTTPServiceUnavailable with Zaqar messaging."""
|
||||||
|
|
||||||
TITLE = _(u'Service temporarily unavailable')
|
TITLE = _('Service temporarily unavailable')
|
||||||
DESCRIPTION = _(u'Please try again in a few seconds.')
|
DESCRIPTION = _('Please try again in a few seconds.')
|
||||||
|
|
||||||
def __init__(self, description):
|
def __init__(self, description):
|
||||||
description = description + ' ' + self.DESCRIPTION
|
description = description + ' ' + self.DESCRIPTION
|
||||||
super(HTTPServiceUnavailable, self).__init__(
|
super(HTTPServiceUnavailable, self).__init__(
|
||||||
self.TITLE, description)
|
title=self.TITLE, description=description)
|
||||||
|
|
||||||
|
|
||||||
class HTTPBadRequestAPI(falcon.HTTPBadRequest):
|
class HTTPBadRequestAPI(falcon.HTTPBadRequest):
|
||||||
"""Wraps falcon.HTTPBadRequest with a contextual title."""
|
"""Wraps falcon.HTTPBadRequest with a contextual title."""
|
||||||
|
|
||||||
TITLE = _(u'Invalid API request')
|
TITLE = _('Invalid API request')
|
||||||
|
|
||||||
def __init__(self, description):
|
def __init__(self, description):
|
||||||
super(HTTPBadRequestAPI, self).__init__(self.TITLE, description)
|
super(HTTPBadRequestAPI, self).__init__(
|
||||||
|
title=self.TITLE, description=description)
|
||||||
|
|
||||||
|
|
||||||
class HTTPBadRequestBody(falcon.HTTPBadRequest):
|
class HTTPBadRequestBody(falcon.HTTPBadRequest):
|
||||||
"""Wraps falcon.HTTPBadRequest with a contextual title."""
|
"""Wraps falcon.HTTPBadRequest with a contextual title."""
|
||||||
|
|
||||||
TITLE = _(u'Invalid request body')
|
TITLE = _('Invalid request body')
|
||||||
|
|
||||||
def __init__(self, description):
|
def __init__(self, description):
|
||||||
super(HTTPBadRequestBody, self).__init__(self.TITLE, description)
|
super(HTTPBadRequestBody, self).__init__(
|
||||||
|
title=self.TITLE, description=description)
|
||||||
|
|
||||||
|
|
||||||
class HTTPDocumentTypeNotSupported(HTTPBadRequestBody):
|
class HTTPDocumentTypeNotSupported(HTTPBadRequestBody):
|
||||||
"""Wraps HTTPBadRequestBody with a standard description."""
|
"""Wraps HTTPBadRequestBody with a standard description."""
|
||||||
|
|
||||||
DESCRIPTION = _(u'Document type not supported.')
|
DESCRIPTION = _('Document type not supported.')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(HTTPDocumentTypeNotSupported, self).__init__(self.DESCRIPTION)
|
super(HTTPDocumentTypeNotSupported, self).__init__(self.DESCRIPTION)
|
||||||
@ -60,34 +62,37 @@ class HTTPDocumentTypeNotSupported(HTTPBadRequestBody):
|
|||||||
class HTTPForbidden(falcon.HTTPForbidden):
|
class HTTPForbidden(falcon.HTTPForbidden):
|
||||||
"""Wraps falcon.HTTPForbidden with a contextual title."""
|
"""Wraps falcon.HTTPForbidden with a contextual title."""
|
||||||
|
|
||||||
TITLE = _(u'Not authorized')
|
TITLE = _('Not authorized')
|
||||||
DESCRIPTION = _(u'You are not authorized to complete this action.')
|
DESCRIPTION = _('You are not authorized to complete this action.')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(HTTPForbidden, self).__init__(self.TITLE, self.DESCRIPTION)
|
super(HTTPForbidden, self).__init__(
|
||||||
|
title=self.TITLE, description=self.DESCRIPTION)
|
||||||
|
|
||||||
|
|
||||||
class HTTPConflict(falcon.HTTPConflict):
|
class HTTPConflict(falcon.HTTPConflict):
|
||||||
"""Wraps falcon.HTTPConflict with contextual title."""
|
"""Wraps falcon.HTTPConflict with contextual title."""
|
||||||
|
|
||||||
TITLE = _(u'Resource conflict')
|
TITLE = _('Resource conflict')
|
||||||
|
|
||||||
def __init__(self, description, **kwargs):
|
def __init__(self, description, **kwargs):
|
||||||
super(HTTPConflict, self).__init__(self.TITLE, description, **kwargs)
|
super(HTTPConflict, self).__init__(
|
||||||
|
title=self.TITLE, description=description, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class HTTPNotFound(falcon.HTTPNotFound):
|
class HTTPNotFound(falcon.HTTPNotFound):
|
||||||
"""Wraps falcon.HTTPConflict with contextual title."""
|
"""Wraps falcon.HTTPConflict with contextual title."""
|
||||||
|
|
||||||
TITLE = _(u'Not found')
|
TITLE = _('Not found')
|
||||||
|
|
||||||
def __init__(self, description):
|
def __init__(self, description):
|
||||||
super(HTTPNotFound, self).__init__(title=self.TITLE,
|
super(HTTPNotFound, self).__init__(
|
||||||
description=description)
|
title=self.TITLE, description=description)
|
||||||
|
|
||||||
|
|
||||||
class HTTPUnsupportedMediaType(falcon.HTTPUnsupportedMediaType):
|
class HTTPUnsupportedMediaType(falcon.HTTPUnsupportedMediaType):
|
||||||
"""Wraps falcon.HTTPUnsupportedMediaType with contextual title."""
|
"""Wraps falcon.HTTPUnsupportedMediaType with contextual title."""
|
||||||
|
|
||||||
def __init__(self, description):
|
def __init__(self, description):
|
||||||
super(HTTPUnsupportedMediaType, self).__init__(description)
|
super(HTTPUnsupportedMediaType, self).__init__(
|
||||||
|
description=description)
|
||||||
|
@ -81,7 +81,7 @@ class CollectionResource(Resource):
|
|||||||
msg, req.path.rpartition('/')[0], cid) for msg in resp_msgs]
|
msg, req.path.rpartition('/')[0], cid) for msg in resp_msgs]
|
||||||
|
|
||||||
resp.location = req.path + '/' + cid
|
resp.location = req.path + '/' + cid
|
||||||
resp.body = utils.to_json(resp_msgs)
|
resp.text = utils.to_json(resp_msgs)
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
else:
|
else:
|
||||||
resp.status = falcon.HTTP_204
|
resp.status = falcon.HTTP_204
|
||||||
@ -125,7 +125,7 @@ class ItemResource(Resource):
|
|||||||
del meta['id']
|
del meta['id']
|
||||||
|
|
||||||
resp.content_location = req.relative_uri
|
resp.content_location = req.relative_uri
|
||||||
resp.body = utils.to_json(meta)
|
resp.text = utils.to_json(meta)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Claim item")
|
@decorators.TransportLog("Claim item")
|
||||||
|
@ -183,7 +183,7 @@ class CollectionResource(object):
|
|||||||
# field has been removed in v1.1.
|
# field has been removed in v1.1.
|
||||||
body = {'resources': hrefs, 'partial': False}
|
body = {'resources': hrefs, 'partial': False}
|
||||||
|
|
||||||
resp.body = utils.to_json(body)
|
resp.text = utils.to_json(body)
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
|
|
||||||
@decorators.TransportLog("Messages collection")
|
@decorators.TransportLog("Messages collection")
|
||||||
@ -201,7 +201,7 @@ class CollectionResource(object):
|
|||||||
resp.status = falcon.HTTP_204
|
resp.status = falcon.HTTP_204
|
||||||
return
|
return
|
||||||
|
|
||||||
resp.body = utils.to_json(response)
|
resp.text = utils.to_json(response)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Messages collection")
|
@decorators.TransportLog("Messages collection")
|
||||||
@ -256,7 +256,7 @@ class ItemResource(object):
|
|||||||
resp.content_location = req.relative_uri
|
resp.content_location = req.relative_uri
|
||||||
message = wsgi_utils.format_message_v1(
|
message = wsgi_utils.format_message_v1(
|
||||||
message, req.path.rsplit('/', 2)[0])
|
message, req.path.rsplit('/', 2)[0])
|
||||||
resp.body = utils.to_json(message)
|
resp.text = utils.to_json(message)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Messages item")
|
@decorators.TransportLog("Messages item")
|
||||||
@ -274,19 +274,22 @@ class ItemResource(object):
|
|||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'A claim was specified, but the message '
|
description = _(u'A claim was specified, but the message '
|
||||||
u'is not currently claimed.')
|
u'is not currently claimed.')
|
||||||
raise falcon.HTTPBadRequest(error_title, description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except storage_errors.ClaimDoesNotExist as ex:
|
except storage_errors.ClaimDoesNotExist as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'The specified claim does not exist or '
|
description = _(u'The specified claim does not exist or '
|
||||||
u'has expired.')
|
u'has expired.')
|
||||||
raise falcon.HTTPBadRequest(error_title, description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except storage_errors.NotPermitted as ex:
|
except storage_errors.NotPermitted as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'This message is claimed; it cannot be '
|
description = _(u'This message is claimed; it cannot be '
|
||||||
u'deleted without a valid claim ID.')
|
u'deleted without a valid claim ID.')
|
||||||
raise falcon.HTTPForbidden(error_title, description)
|
raise falcon.HTTPForbidden(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
description = _(u'Message could not be deleted.')
|
description = _(u'Message could not be deleted.')
|
||||||
|
@ -52,7 +52,7 @@ class Resource(object):
|
|||||||
raise wsgi_errors.HTTPServiceUnavailable(description)
|
raise wsgi_errors.HTTPServiceUnavailable(description)
|
||||||
|
|
||||||
resp.content_location = req.path
|
resp.content_location = req.path
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Queue metadata")
|
@decorators.TransportLog("Queue metadata")
|
||||||
|
@ -105,7 +105,7 @@ class Listing(object):
|
|||||||
results['pools'] = pools
|
results['pools'] = pools
|
||||||
|
|
||||||
response.content_location = request.relative_uri
|
response.content_location = request.relative_uri
|
||||||
response.body = transport_utils.to_json(results)
|
response.text = transport_utils.to_json(results)
|
||||||
response.status = falcon.HTTP_200
|
response.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
||||||
@ -147,7 +147,7 @@ class Resource(object):
|
|||||||
|
|
||||||
data['href'] = request.path
|
data['href'] = request.path
|
||||||
|
|
||||||
response.body = transport_utils.to_json(data)
|
response.text = transport_utils.to_json(data)
|
||||||
response.content_location = request.relative_uri
|
response.content_location = request.relative_uri
|
||||||
|
|
||||||
def on_put(self, request, response, project_id, pool):
|
def on_put(self, request, response, project_id, pool):
|
||||||
|
@ -128,5 +128,5 @@ class CollectionResource(object):
|
|||||||
}
|
}
|
||||||
|
|
||||||
resp.content_location = req.relative_uri
|
resp.content_location = req.relative_uri
|
||||||
resp.body = utils.to_json(response_body)
|
resp.text = utils.to_json(response_body)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
@ -50,7 +50,7 @@ class Resource(object):
|
|||||||
del oldest['id']
|
del oldest['id']
|
||||||
|
|
||||||
resp.content_location = req.path
|
resp.content_location = req.path
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
except storage_errors.QueueIsEmpty:
|
except storage_errors.QueueIsEmpty:
|
||||||
@ -61,7 +61,7 @@ class Resource(object):
|
|||||||
'total': 0
|
'total': 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
except storage_errors.DoesNotExist as ex:
|
except storage_errors.DoesNotExist as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
raise wsgi_errors.HTTPNotFound(str(ex))
|
raise wsgi_errors.HTTPNotFound(str(ex))
|
||||||
|
@ -102,7 +102,7 @@ class CollectionResource(object):
|
|||||||
for msg in resp_msgs]
|
for msg in resp_msgs]
|
||||||
|
|
||||||
resp.location = req.path + '/' + cid
|
resp.location = req.path + '/' + cid
|
||||||
resp.body = utils.to_json({'messages': resp_msgs})
|
resp.text = utils.to_json({'messages': resp_msgs})
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
else:
|
else:
|
||||||
resp.status = falcon.HTTP_204
|
resp.status = falcon.HTTP_204
|
||||||
@ -152,7 +152,7 @@ class ItemResource(object):
|
|||||||
meta['href'] = req.path
|
meta['href'] = req.path
|
||||||
del meta['id']
|
del meta['id']
|
||||||
|
|
||||||
resp.body = utils.to_json(meta)
|
resp.text = utils.to_json(meta)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Claim item")
|
@decorators.TransportLog("Claim item")
|
||||||
|
@ -83,7 +83,7 @@ class Listing(object):
|
|||||||
|
|
||||||
results['flavors'] = flavors
|
results['flavors'] = flavors
|
||||||
|
|
||||||
response.body = transport_utils.to_json(results)
|
response.text = transport_utils.to_json(results)
|
||||||
response.status = falcon.HTTP_200
|
response.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ class Resource(object):
|
|||||||
|
|
||||||
data['href'] = request.path
|
data['href'] = request.path
|
||||||
|
|
||||||
response.body = transport_utils.to_json(data)
|
response.text = transport_utils.to_json(data)
|
||||||
|
|
||||||
def on_put(self, request, response, project_id, flavor):
|
def on_put(self, request, response, project_id, flavor):
|
||||||
"""Registers a new flavor. Expects the following input:
|
"""Registers a new flavor. Expects the following input:
|
||||||
@ -153,7 +153,8 @@ class Resource(object):
|
|||||||
description = (_(u'Flavor %(flavor)s could not be created. ') %
|
description = (_(u'Flavor %(flavor)s could not be created. ') %
|
||||||
dict(flavor=flavor))
|
dict(flavor=flavor))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description=description)
|
||||||
|
|
||||||
def on_delete(self, request, response, project_id, flavor):
|
def on_delete(self, request, response, project_id, flavor):
|
||||||
"""Deregisters a flavor.
|
"""Deregisters a flavor.
|
||||||
|
@ -32,7 +32,7 @@ class Resource(object):
|
|||||||
def on_get(self, req, resp, **kwargs):
|
def on_get(self, req, resp, **kwargs):
|
||||||
try:
|
try:
|
||||||
resp_dict = self._driver.health()
|
resp_dict = self._driver.health()
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
except Exception:
|
except Exception:
|
||||||
description = _(u'Health status could not be read.')
|
description = _(u'Health status could not be read.')
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
|
@ -207,7 +207,7 @@ class CollectionResource(object):
|
|||||||
|
|
||||||
hrefs = [req.path + '/' + id for id in message_ids]
|
hrefs = [req.path + '/' + id for id in message_ids]
|
||||||
body = {'resources': hrefs}
|
body = {'resources': hrefs}
|
||||||
resp.body = utils.to_json(body)
|
resp.text = utils.to_json(body)
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
|
|
||||||
@decorators.TransportLog("Messages collection")
|
@decorators.TransportLog("Messages collection")
|
||||||
@ -232,7 +232,7 @@ class CollectionResource(object):
|
|||||||
raise wsgi_errors.HTTPNotFound(description)
|
raise wsgi_errors.HTTPNotFound(description)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
resp.body = utils.to_json(response)
|
resp.text = utils.to_json(response)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Messages collection")
|
@decorators.TransportLog("Messages collection")
|
||||||
@ -251,7 +251,7 @@ class CollectionResource(object):
|
|||||||
project_id)
|
project_id)
|
||||||
|
|
||||||
elif pop_limit:
|
elif pop_limit:
|
||||||
resp.status, resp.body = self._pop_messages(queue_name,
|
resp.status, resp.text = self._pop_messages(queue_name,
|
||||||
project_id,
|
project_id,
|
||||||
pop_limit)
|
pop_limit)
|
||||||
|
|
||||||
@ -324,7 +324,7 @@ class ItemResource(object):
|
|||||||
req.path.rsplit('/', 2)[0],
|
req.path.rsplit('/', 2)[0],
|
||||||
message['claim_id'])
|
message['claim_id'])
|
||||||
|
|
||||||
resp.body = utils.to_json(message)
|
resp.text = utils.to_json(message)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Messages item")
|
@decorators.TransportLog("Messages item")
|
||||||
@ -342,19 +342,22 @@ class ItemResource(object):
|
|||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'A claim was specified, but the message '
|
description = _(u'A claim was specified, but the message '
|
||||||
u'is not currently claimed.')
|
u'is not currently claimed.')
|
||||||
raise falcon.HTTPBadRequest(error_title, description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except storage_errors.ClaimDoesNotExist as ex:
|
except storage_errors.ClaimDoesNotExist as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'The specified claim does not exist or '
|
description = _(u'The specified claim does not exist or '
|
||||||
u'has expired.')
|
u'has expired.')
|
||||||
raise falcon.HTTPBadRequest(error_title, description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except storage_errors.NotPermitted as ex:
|
except storage_errors.NotPermitted as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'This message is claimed; it cannot be '
|
description = _(u'This message is claimed; it cannot be '
|
||||||
u'deleted without a valid claim ID.')
|
u'deleted without a valid claim ID.')
|
||||||
raise falcon.HTTPForbidden(error_title, description)
|
raise falcon.HTTPForbidden(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
description = _(u'Message could not be deleted.')
|
description = _(u'Message could not be deleted.')
|
||||||
|
@ -107,7 +107,7 @@ class Listing(object):
|
|||||||
results['pools'] = pools
|
results['pools'] = pools
|
||||||
|
|
||||||
response.content_location = request.relative_uri
|
response.content_location = request.relative_uri
|
||||||
response.body = transport_utils.to_json(results)
|
response.text = transport_utils.to_json(results)
|
||||||
response.status = falcon.HTTP_200
|
response.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ class Resource(object):
|
|||||||
|
|
||||||
data['href'] = request.path
|
data['href'] = request.path
|
||||||
|
|
||||||
response.body = transport_utils.to_json(data)
|
response.text = transport_utils.to_json(data)
|
||||||
|
|
||||||
def on_put(self, request, response, project_id, pool):
|
def on_put(self, request, response, project_id, pool):
|
||||||
"""Registers a new pool. Expects the following input:
|
"""Registers a new pool. Expects the following input:
|
||||||
@ -183,7 +183,7 @@ class Resource(object):
|
|||||||
except errors.PoolCapabilitiesMismatch as e:
|
except errors.PoolCapabilitiesMismatch as e:
|
||||||
title = _(u'Unable to create pool')
|
title = _(u'Unable to create pool')
|
||||||
LOG.exception(title)
|
LOG.exception(title)
|
||||||
raise falcon.HTTPBadRequest(title, str(e))
|
raise falcon.HTTPBadRequest(title=title, description=str(e))
|
||||||
except errors.PoolAlreadyExists as e:
|
except errors.PoolAlreadyExists as e:
|
||||||
LOG.exception('Pool "%s" already exists', pool)
|
LOG.exception('Pool "%s" already exists', pool)
|
||||||
raise wsgi_errors.HTTPConflict(str(e))
|
raise wsgi_errors.HTTPConflict(str(e))
|
||||||
@ -204,7 +204,7 @@ class Resource(object):
|
|||||||
u'It cannot be deleted.')
|
u'It cannot be deleted.')
|
||||||
description = description.format(flavor=ex.flavor)
|
description = description.format(flavor=ex.flavor)
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPForbidden(title, description)
|
raise falcon.HTTPForbidden(title=title, description=description)
|
||||||
|
|
||||||
response.status = falcon.HTTP_204
|
response.status = falcon.HTTP_204
|
||||||
|
|
||||||
|
@ -52,7 +52,7 @@ class ItemResource(object):
|
|||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise wsgi_errors.HTTPServiceUnavailable(description)
|
raise wsgi_errors.HTTPServiceUnavailable(description)
|
||||||
|
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Queue item")
|
@decorators.TransportLog("Queue item")
|
||||||
@ -157,5 +157,5 @@ class CollectionResource(object):
|
|||||||
'links': links
|
'links': links
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.body = utils.to_json(response_body)
|
resp.text = utils.to_json(response_body)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
@ -49,7 +49,7 @@ class Resource(object):
|
|||||||
oldest['href'] = base_path + oldest['id']
|
oldest['href'] = base_path + oldest['id']
|
||||||
del oldest['id']
|
del oldest['id']
|
||||||
|
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
except (storage_errors.QueueDoesNotExist,
|
except (storage_errors.QueueDoesNotExist,
|
||||||
@ -61,7 +61,7 @@ class Resource(object):
|
|||||||
'total': 0
|
'total': 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
|
|
||||||
except storage_errors.DoesNotExist as ex:
|
except storage_errors.DoesNotExist as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
|
@ -104,7 +104,7 @@ class CollectionResource(object):
|
|||||||
for msg in resp_msgs]
|
for msg in resp_msgs]
|
||||||
|
|
||||||
resp.location = req.path + '/' + cid
|
resp.location = req.path + '/' + cid
|
||||||
resp.body = utils.to_json({'messages': resp_msgs})
|
resp.text = utils.to_json({'messages': resp_msgs})
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
else:
|
else:
|
||||||
resp.status = falcon.HTTP_204
|
resp.status = falcon.HTTP_204
|
||||||
@ -155,7 +155,7 @@ class ItemResource(object):
|
|||||||
meta['href'] = req.path
|
meta['href'] = req.path
|
||||||
del meta['id']
|
del meta['id']
|
||||||
|
|
||||||
resp.body = utils.to_json(meta)
|
resp.text = utils.to_json(meta)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Claims item")
|
@decorators.TransportLog("Claims item")
|
||||||
|
@ -110,7 +110,7 @@ class Listing(object):
|
|||||||
|
|
||||||
results['flavors'] = flavors
|
results['flavors'] = flavors
|
||||||
|
|
||||||
response.body = transport_utils.to_json(results)
|
response.text = transport_utils.to_json(results)
|
||||||
response.status = falcon.HTTP_200
|
response.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ class Resource(object):
|
|||||||
|
|
||||||
data['href'] = request.path
|
data['href'] = request.path
|
||||||
|
|
||||||
response.body = transport_utils.to_json(data)
|
response.text = transport_utils.to_json(data)
|
||||||
|
|
||||||
def _check_pools_exists(self, pool_list):
|
def _check_pools_exists(self, pool_list):
|
||||||
if pool_list is not None:
|
if pool_list is not None:
|
||||||
@ -194,7 +194,8 @@ class Resource(object):
|
|||||||
if len(pool_list) == 0:
|
if len(pool_list) == 0:
|
||||||
response.status = falcon.HTTP_400
|
response.status = falcon.HTTP_400
|
||||||
response.location = request.path
|
response.location = request.path
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), 'Bad Request')
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description='Bad Request')
|
||||||
# NOTE(gengchc2): Check if pools in the pool_list exist.
|
# NOTE(gengchc2): Check if pools in the pool_list exist.
|
||||||
try:
|
try:
|
||||||
self._check_pools_exists(pool_list)
|
self._check_pools_exists(pool_list)
|
||||||
@ -203,7 +204,8 @@ class Resource(object):
|
|||||||
'error:%(msg)s') %
|
'error:%(msg)s') %
|
||||||
dict(flavor=flavor, msg=str(ex)))
|
dict(flavor=flavor, msg=str(ex)))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description=description)
|
||||||
capabilities = self._pools_ctrl.capabilities(name=pool_list[0])
|
capabilities = self._pools_ctrl.capabilities(name=pool_list[0])
|
||||||
try:
|
try:
|
||||||
self._ctrl.create(flavor,
|
self._ctrl.create(flavor,
|
||||||
@ -216,7 +218,8 @@ class Resource(object):
|
|||||||
'error:%(msg)s') %
|
'error:%(msg)s') %
|
||||||
dict(flavor=flavor, msg=str(ex)))
|
dict(flavor=flavor, msg=str(ex)))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description=description)
|
||||||
# NOTE(gengchc2): Update the 'flavor' field in pools tables.
|
# NOTE(gengchc2): Update the 'flavor' field in pools tables.
|
||||||
try:
|
try:
|
||||||
self._update_pools_by_flavor(flavor, pool_list)
|
self._update_pools_by_flavor(flavor, pool_list)
|
||||||
@ -225,7 +228,8 @@ class Resource(object):
|
|||||||
'error:%(msg)s') %
|
'error:%(msg)s') %
|
||||||
dict(flavor=flavor, msg=str(ex)))
|
dict(flavor=flavor, msg=str(ex)))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description=description)
|
||||||
|
|
||||||
@decorators.TransportLog("Flavors item")
|
@decorators.TransportLog("Flavors item")
|
||||||
@acl.enforce("flavors:create")
|
@acl.enforce("flavors:create")
|
||||||
@ -268,7 +272,8 @@ class Resource(object):
|
|||||||
description = (_(u'Flavor %(flavor)s could not be deleted.') %
|
description = (_(u'Flavor %(flavor)s could not be deleted.') %
|
||||||
dict(flavor=flavor))
|
dict(flavor=flavor))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description=description)
|
||||||
self._ctrl.delete(flavor, project=project_id)
|
self._ctrl.delete(flavor, project=project_id)
|
||||||
response.status = falcon.HTTP_204
|
response.status = falcon.HTTP_204
|
||||||
|
|
||||||
@ -278,7 +283,8 @@ class Resource(object):
|
|||||||
if len(pool_list) == 0:
|
if len(pool_list) == 0:
|
||||||
response.status = falcon.HTTP_400
|
response.status = falcon.HTTP_400
|
||||||
response.location = request.path
|
response.location = request.path
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), 'Bad Request')
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description='Bad Request')
|
||||||
# NOTE(gengchc2): If the flavor does not exist, return
|
# NOTE(gengchc2): If the flavor does not exist, return
|
||||||
try:
|
try:
|
||||||
self._ctrl.get(flavor, project=project_id)
|
self._ctrl.get(flavor, project=project_id)
|
||||||
@ -299,7 +305,8 @@ class Resource(object):
|
|||||||
'error:%(msg)s') %
|
'error:%(msg)s') %
|
||||||
dict(flavor=flavor, msg=str(ex)))
|
dict(flavor=flavor, msg=str(ex)))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('updatefail'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('updatefail'), description=description)
|
||||||
capabilities = self._pools_ctrl.capabilities(name=pool_list[0])
|
capabilities = self._pools_ctrl.capabilities(name=pool_list[0])
|
||||||
try:
|
try:
|
||||||
self._ctrl.update(flavor, project=project_id,
|
self._ctrl.update(flavor, project=project_id,
|
||||||
@ -318,7 +325,8 @@ class Resource(object):
|
|||||||
'error:%(msg)s') %
|
'error:%(msg)s') %
|
||||||
dict(flavor=flavor, msg=str(ex)))
|
dict(flavor=flavor, msg=str(ex)))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description=description)
|
||||||
# (gengchc) Remove flavor from old pool list.
|
# (gengchc) Remove flavor from old pool list.
|
||||||
try:
|
try:
|
||||||
pool_list_removed = []
|
pool_list_removed = []
|
||||||
@ -331,10 +339,11 @@ class Resource(object):
|
|||||||
'error:%(msg)s') %
|
'error:%(msg)s') %
|
||||||
dict(flavor=flavor, msg=str(ex)))
|
dict(flavor=flavor, msg=str(ex)))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to create'), description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=_('Unable to create'), description=description)
|
||||||
resp_data['pool_list'] = pool_list
|
resp_data['pool_list'] = pool_list
|
||||||
resp_data['href'] = request.path
|
resp_data['href'] = request.path
|
||||||
response.body = transport_utils.to_json(resp_data)
|
response.text = transport_utils.to_json(resp_data)
|
||||||
|
|
||||||
@decorators.TransportLog("Flavors item")
|
@decorators.TransportLog("Flavors item")
|
||||||
@acl.enforce("flavors:update")
|
@acl.enforce("flavors:update")
|
||||||
|
@ -36,7 +36,7 @@ class Resource(object):
|
|||||||
def on_get(self, req, resp, **kwargs):
|
def on_get(self, req, resp, **kwargs):
|
||||||
try:
|
try:
|
||||||
resp_dict = self._driver.health()
|
resp_dict = self._driver.health()
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
except Exception:
|
except Exception:
|
||||||
description = _(u'Health status could not be read.')
|
description = _(u'Health status could not be read.')
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
|
@ -264,7 +264,7 @@ class CollectionResource(object):
|
|||||||
|
|
||||||
hrefs = [req.path + '/' + id for id in message_ids]
|
hrefs = [req.path + '/' + id for id in message_ids]
|
||||||
body = {'resources': hrefs}
|
body = {'resources': hrefs}
|
||||||
resp.body = utils.to_json(body)
|
resp.text = utils.to_json(body)
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
|
|
||||||
@decorators.TransportLog("Messages collection")
|
@decorators.TransportLog("Messages collection")
|
||||||
@ -290,7 +290,7 @@ class CollectionResource(object):
|
|||||||
raise wsgi_errors.HTTPNotFound(description)
|
raise wsgi_errors.HTTPNotFound(description)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
resp.body = utils.to_json(response)
|
resp.text = utils.to_json(response)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Messages collection")
|
@decorators.TransportLog("Messages collection")
|
||||||
@ -313,7 +313,7 @@ class CollectionResource(object):
|
|||||||
project_id, claim_ids)
|
project_id, claim_ids)
|
||||||
|
|
||||||
elif pop_limit:
|
elif pop_limit:
|
||||||
resp.status, resp.body = self._pop_messages(queue_name,
|
resp.status, resp.text = self._pop_messages(queue_name,
|
||||||
project_id,
|
project_id,
|
||||||
pop_limit)
|
pop_limit)
|
||||||
|
|
||||||
@ -402,7 +402,7 @@ class ItemResource(object):
|
|||||||
req.path.rsplit('/', 2)[0],
|
req.path.rsplit('/', 2)[0],
|
||||||
message['claim_id'])
|
message['claim_id'])
|
||||||
|
|
||||||
resp.body = utils.to_json(message)
|
resp.text = utils.to_json(message)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Messages item")
|
@decorators.TransportLog("Messages item")
|
||||||
@ -421,19 +421,22 @@ class ItemResource(object):
|
|||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'A claim was specified, but the message '
|
description = _(u'A claim was specified, but the message '
|
||||||
u'is not currently claimed.')
|
u'is not currently claimed.')
|
||||||
raise falcon.HTTPBadRequest(error_title, description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except storage_errors.ClaimDoesNotExist as ex:
|
except storage_errors.ClaimDoesNotExist as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'The specified claim does not exist or '
|
description = _(u'The specified claim does not exist or '
|
||||||
u'has expired.')
|
u'has expired.')
|
||||||
raise falcon.HTTPBadRequest(error_title, description)
|
raise falcon.HTTPBadRequest(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except storage_errors.NotPermitted as ex:
|
except storage_errors.NotPermitted as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
description = _(u'This message is claimed; it cannot be '
|
description = _(u'This message is claimed; it cannot be '
|
||||||
u'deleted without a valid claim ID.')
|
u'deleted without a valid claim ID.')
|
||||||
raise falcon.HTTPForbidden(error_title, description)
|
raise falcon.HTTPForbidden(
|
||||||
|
title=error_title, description=description)
|
||||||
|
|
||||||
except Exception:
|
except Exception:
|
||||||
description = _(u'Message could not be deleted.')
|
description = _(u'Message could not be deleted.')
|
||||||
|
@ -119,7 +119,7 @@ class Listing(object):
|
|||||||
results['pools'] = pools
|
results['pools'] = pools
|
||||||
|
|
||||||
response.content_location = request.relative_uri
|
response.content_location = request.relative_uri
|
||||||
response.body = transport_utils.to_json(results)
|
response.text = transport_utils.to_json(results)
|
||||||
response.status = falcon.HTTP_200
|
response.status = falcon.HTTP_200
|
||||||
|
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ class Resource(object):
|
|||||||
|
|
||||||
data['href'] = request.path
|
data['href'] = request.path
|
||||||
|
|
||||||
response.body = transport_utils.to_json(data)
|
response.text = transport_utils.to_json(data)
|
||||||
|
|
||||||
@decorators.TransportLog("Pools item")
|
@decorators.TransportLog("Pools item")
|
||||||
@acl.enforce("pools:create")
|
@acl.enforce("pools:create")
|
||||||
@ -200,7 +200,7 @@ class Resource(object):
|
|||||||
except errors.PoolCapabilitiesMismatch as e:
|
except errors.PoolCapabilitiesMismatch as e:
|
||||||
title = _(u'Unable to create pool')
|
title = _(u'Unable to create pool')
|
||||||
LOG.exception(title)
|
LOG.exception(title)
|
||||||
raise falcon.HTTPBadRequest(title, str(e))
|
raise falcon.HTTPBadRequest(title=title, description=str(e))
|
||||||
except errors.PoolAlreadyExists as e:
|
except errors.PoolAlreadyExists as e:
|
||||||
LOG.exception('Pool "%s" already exists', pool)
|
LOG.exception('Pool "%s" already exists', pool)
|
||||||
raise wsgi_errors.HTTPConflict(str(e))
|
raise wsgi_errors.HTTPConflict(str(e))
|
||||||
@ -223,7 +223,7 @@ class Resource(object):
|
|||||||
u'It cannot be deleted.')
|
u'It cannot be deleted.')
|
||||||
description = description.format(flavor=ex.flavor)
|
description = description.format(flavor=ex.flavor)
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPForbidden(title, description)
|
raise falcon.HTTPForbidden(title=title, description=description)
|
||||||
|
|
||||||
response.status = falcon.HTTP_204
|
response.status = falcon.HTTP_204
|
||||||
|
|
||||||
@ -274,4 +274,4 @@ class Resource(object):
|
|||||||
raise wsgi_errors.HTTPNotFound(str(ex))
|
raise wsgi_errors.HTTPNotFound(str(ex))
|
||||||
|
|
||||||
resp_data['href'] = request.path
|
resp_data['href'] = request.path
|
||||||
response.body = transport_utils.to_json(resp_data)
|
response.text = transport_utils.to_json(resp_data)
|
||||||
|
@ -73,7 +73,7 @@ class ItemResource(object):
|
|||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise wsgi_errors.HTTPServiceUnavailable(description)
|
raise wsgi_errors.HTTPServiceUnavailable(description)
|
||||||
|
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Queues item")
|
@decorators.TransportLog("Queues item")
|
||||||
@ -217,7 +217,7 @@ class ItemResource(object):
|
|||||||
for meta, value in _get_reserved_metadata(self._validate).items():
|
for meta, value in _get_reserved_metadata(self._validate).items():
|
||||||
if not metadata.get(meta):
|
if not metadata.get(meta):
|
||||||
metadata[meta] = value
|
metadata[meta] = value
|
||||||
resp.body = utils.to_json(metadata)
|
resp.text = utils.to_json(metadata)
|
||||||
|
|
||||||
def _do_replace(self, req, metadata, reserved_metadata, change):
|
def _do_replace(self, req, metadata, reserved_metadata, change):
|
||||||
path = change['path']
|
path = change['path']
|
||||||
@ -321,7 +321,7 @@ class CollectionResource(object):
|
|||||||
if total_number:
|
if total_number:
|
||||||
response_body['count'] = total_number
|
response_body['count'] = total_number
|
||||||
|
|
||||||
resp.body = utils.to_json(response_body)
|
resp.text = utils.to_json(response_body)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Queues collection")
|
@decorators.TransportLog("Queues collection")
|
||||||
|
@ -53,7 +53,7 @@ class Resource(object):
|
|||||||
oldest['href'] = base_path + oldest['id']
|
oldest['href'] = base_path + oldest['id']
|
||||||
del oldest['id']
|
del oldest['id']
|
||||||
|
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
except (storage_errors.QueueDoesNotExist,
|
except (storage_errors.QueueDoesNotExist,
|
||||||
@ -65,7 +65,7 @@ class Resource(object):
|
|||||||
'total': 0
|
'total': 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
|
|
||||||
except storage_errors.DoesNotExist as ex:
|
except storage_errors.DoesNotExist as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
|
@ -59,7 +59,7 @@ class ItemResource(object):
|
|||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise wsgi_errors.HTTPServiceUnavailable(description)
|
raise wsgi_errors.HTTPServiceUnavailable(description)
|
||||||
|
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Subscriptions item")
|
@decorators.TransportLog("Subscriptions item")
|
||||||
@ -106,8 +106,9 @@ class ItemResource(object):
|
|||||||
' updated.') %
|
' updated.') %
|
||||||
dict(subscription_id=subscription_id))
|
dict(subscription_id=subscription_id))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to update subscription'),
|
raise falcon.HTTPBadRequest(
|
||||||
description)
|
title=_('Unable to update subscription'),
|
||||||
|
description=description)
|
||||||
|
|
||||||
|
|
||||||
class CollectionResource(object):
|
class CollectionResource(object):
|
||||||
@ -167,7 +168,7 @@ class CollectionResource(object):
|
|||||||
'links': links
|
'links': links
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.body = utils.to_json(response_body)
|
resp.text = utils.to_json(response_body)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Subscriptions collection")
|
@decorators.TransportLog("Subscriptions collection")
|
||||||
@ -221,7 +222,7 @@ class CollectionResource(object):
|
|||||||
|
|
||||||
resp.location = req.path
|
resp.location = req.path
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
resp.body = utils.to_json(
|
resp.text = utils.to_json(
|
||||||
{'subscription_id': str(created)})
|
{'subscription_id': str(created)})
|
||||||
else:
|
else:
|
||||||
subscription = self._subscription_controller.get_with_subscriber(
|
subscription = self._subscription_controller.get_with_subscriber(
|
||||||
@ -242,7 +243,7 @@ class CollectionResource(object):
|
|||||||
|
|
||||||
resp.location = req.path
|
resp.location = req.path
|
||||||
resp.status = falcon.HTTP_201
|
resp.status = falcon.HTTP_201
|
||||||
resp.body = utils.to_json(
|
resp.text = utils.to_json(
|
||||||
{'subscription_id': str(subscription['id'])})
|
{'subscription_id': str(subscription['id'])})
|
||||||
|
|
||||||
|
|
||||||
@ -301,5 +302,6 @@ class ConfirmResource(object):
|
|||||||
' confirmed.') %
|
' confirmed.') %
|
||||||
dict(subscription_id=subscription_id))
|
dict(subscription_id=subscription_id))
|
||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise falcon.HTTPBadRequest(_('Unable to confirm subscription'),
|
raise falcon.HTTPBadRequest(
|
||||||
description)
|
title=_('Unable to confirm subscription'),
|
||||||
|
description=description)
|
||||||
|
@ -69,7 +69,7 @@ class ItemResource(object):
|
|||||||
LOG.exception(description)
|
LOG.exception(description)
|
||||||
raise wsgi_errors.HTTPServiceUnavailable(description)
|
raise wsgi_errors.HTTPServiceUnavailable(description)
|
||||||
|
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Topics item")
|
@decorators.TransportLog("Topics item")
|
||||||
@ -213,7 +213,7 @@ class ItemResource(object):
|
|||||||
for meta, value in _get_reserved_metadata(self._validate).items():
|
for meta, value in _get_reserved_metadata(self._validate).items():
|
||||||
if not metadata.get(meta):
|
if not metadata.get(meta):
|
||||||
metadata[meta] = value
|
metadata[meta] = value
|
||||||
resp.body = utils.to_json(metadata)
|
resp.text = utils.to_json(metadata)
|
||||||
|
|
||||||
def _do_replace(self, req, metadata, reserved_metadata, change):
|
def _do_replace(self, req, metadata, reserved_metadata, change):
|
||||||
path = change['path']
|
path = change['path']
|
||||||
@ -307,7 +307,7 @@ class CollectionResource(object):
|
|||||||
'links': links
|
'links': links
|
||||||
}
|
}
|
||||||
|
|
||||||
resp.body = utils.to_json(response_body)
|
resp.text = utils.to_json(response_body)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
@decorators.TransportLog("Topics collection")
|
@decorators.TransportLog("Topics collection")
|
||||||
|
@ -53,7 +53,7 @@ class Resource(object):
|
|||||||
oldest['href'] = base_path + oldest['id']
|
oldest['href'] = base_path + oldest['id']
|
||||||
del oldest['id']
|
del oldest['id']
|
||||||
|
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
# status defaults to 200
|
# status defaults to 200
|
||||||
|
|
||||||
except (storage_errors.TopicDoesNotExist,
|
except (storage_errors.TopicDoesNotExist,
|
||||||
@ -65,7 +65,7 @@ class Resource(object):
|
|||||||
'total': 0
|
'total': 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
resp.body = utils.to_json(resp_dict)
|
resp.text = utils.to_json(resp_dict)
|
||||||
|
|
||||||
except storage_errors.DoesNotExist as ex:
|
except storage_errors.DoesNotExist as ex:
|
||||||
LOG.debug(ex)
|
LOG.debug(ex)
|
||||||
|
@ -74,4 +74,4 @@ class Resource(object):
|
|||||||
except ValueError as err:
|
except ValueError as err:
|
||||||
raise wsgi_errors.HTTPBadRequestAPI(str(err))
|
raise wsgi_errors.HTTPBadRequestAPI(str(err))
|
||||||
|
|
||||||
resp.body = utils.to_json(data)
|
resp.text = utils.to_json(data)
|
||||||
|
@ -34,6 +34,6 @@ class Resource(object):
|
|||||||
self.versions = utils.to_json(VERSIONS)
|
self.versions = utils.to_json(VERSIONS)
|
||||||
|
|
||||||
def on_get(self, req, resp, project_id):
|
def on_get(self, req, resp, project_id):
|
||||||
resp.body = self.versions
|
resp.text = self.versions
|
||||||
|
|
||||||
resp.status = falcon.HTTP_300
|
resp.status = falcon.HTTP_300
|
||||||
|
Loading…
x
Reference in New Issue
Block a user