From 3f71934f0e05b43c2093104c0412e46f5343595a Mon Sep 17 00:00:00 2001 From: Eoghan Glynn Date: Fri, 20 Jul 2012 12:00:12 +0100 Subject: Return location header on volume creation Partially addresses LP 1026600 Normal RESTful idiom would dictate that the "Location" header is set to reference the newly created resource. We defer lining up the status code returned with generally accepted RESTful convention (currently "200 OK", should be "201 Created" or "202 Accepted") until the next API major version bump. There is already substantial code duplication between the volumes API and the os-volumes API extension - this will be addressed in a later patch. Change-Id: I166846a4cfea8adc8c156b8ae0e0d288681ac08c --- nova/api/openstack/compute/contrib/volumes.py | 5 ++++- nova/api/openstack/volume/types.py | 2 +- nova/api/openstack/volume/volumes.py | 6 +++++- nova/api/openstack/wsgi.py | 4 ++-- 4 files changed, 12 insertions(+), 5 deletions(-) (limited to 'nova/api') diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py index 6b04e3240..085f8d7c5 100644 --- a/nova/api/openstack/compute/contrib/volumes.py +++ b/nova/api/openstack/compute/contrib/volumes.py @@ -220,8 +220,11 @@ class VolumeController(object): # trying to lazy load, but for now we turn it into # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) + result = {'volume': retval} - return {'volume': retval} + location = '%s/%s' % (req.url, new_volume['id']) + + return wsgi.ResponseObject(result, headers=dict(location=location)) def _translate_attachment_detail_view(volume_id, instance_uuid, mountpoint): diff --git a/nova/api/openstack/volume/types.py b/nova/api/openstack/volume/types.py index 0a750d86b..a39d2a1f6 100644 --- a/nova/api/openstack/volume/types.py +++ b/nova/api/openstack/volume/types.py @@ -19,8 +19,8 @@ from webob import exc -from nova.api.openstack import wsgi from nova.api.openstack.volume.views import types as views_types +from nova.api.openstack import wsgi from nova.api.openstack import xmlutil from nova import exception from nova.volume import volume_types diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py index 1b0c8dfca..83a2b2f63 100644 --- a/nova/api/openstack/volume/volumes.py +++ b/nova/api/openstack/volume/volumes.py @@ -247,7 +247,11 @@ class VolumeController(object): # a dict to avoid an error. retval = _translate_volume_detail_view(context, dict(new_volume)) - return {'volume': retval} + result = {'volume': retval} + + location = '%s/%s' % (req.url, new_volume['id']) + + return wsgi.ResponseObject(result, headers=dict(location=location)) def create_resource(): diff --git a/nova/api/openstack/wsgi.py b/nova/api/openstack/wsgi.py index e92954711..229783d54 100644 --- a/nova/api/openstack/wsgi.py +++ b/nova/api/openstack/wsgi.py @@ -454,7 +454,7 @@ class ResponseObject(object): optional. """ - def __init__(self, obj, code=None, **serializers): + def __init__(self, obj, code=None, headers=None, **serializers): """Binds serializers with an object. Takes keyword arguments akin to the @serializer() decorator @@ -467,7 +467,7 @@ class ResponseObject(object): self.serializers = serializers self._default_code = 200 self._code = code - self._headers = {} + self._headers = headers or {} self.serializer = None self.media_type = None -- cgit