summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorEoghan Glynn <eglynn@redhat.com>2012-07-26 11:02:05 +0100
committerEoghan Glynn <eglynn@redhat.com>2012-07-26 11:41:40 +0100
commiteb1e9ae114eccae373157c5391d06c97eec1e0a2 (patch)
treecab7fc4d48ae763de59cacbf7f7af3e99441af99 /nova/api
parente238e07692c747ddcb0c70452578a812836cea67 (diff)
Trim volume type representation.
Fixes nova-volume aspect of LP 1027281. Use view builder pattern to only include non-extraneous volume type attributes in the representation. Change-Id: I33f1b579fd6ed4ed98fa04e9148e91eca125213e
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/volume/contrib/types_manage.py5
-rw-r--r--nova/api/openstack/volume/types.py10
-rw-r--r--nova/api/openstack/volume/views/types.py34
3 files changed, 45 insertions, 4 deletions
diff --git a/nova/api/openstack/volume/contrib/types_manage.py b/nova/api/openstack/volume/contrib/types_manage.py
index e84f787ab..ff21174c3 100644
--- a/nova/api/openstack/volume/contrib/types_manage.py
+++ b/nova/api/openstack/volume/contrib/types_manage.py
@@ -21,6 +21,7 @@ import webob
from nova.api.openstack import extensions
from nova.api.openstack.volume import types
+from nova.api.openstack.volume.views import types as views_types
from nova.api.openstack import wsgi
from nova import exception
from nova.volume import volume_types
@@ -32,6 +33,8 @@ authorize = extensions.extension_authorizer('volume', 'types_manage')
class VolumeTypesManageController(wsgi.Controller):
""" The volume types API controller for the OpenStack API """
+ _view_builder_class = views_types.ViewBuilder
+
@wsgi.action("create")
@wsgi.serializers(xml=types.VolumeTypeTemplate)
def _create(self, req, body):
@@ -60,7 +63,7 @@ class VolumeTypesManageController(wsgi.Controller):
except exception.NotFound:
raise webob.exc.HTTPNotFound()
- return {'volume_type': vol_type}
+ return self._view_builder.show(req, vol_type)
@wsgi.action("delete")
def _delete(self, req, id):
diff --git a/nova/api/openstack/volume/types.py b/nova/api/openstack/volume/types.py
index e81f23ef6..0a750d86b 100644
--- a/nova/api/openstack/volume/types.py
+++ b/nova/api/openstack/volume/types.py
@@ -20,6 +20,7 @@
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 xmlutil
from nova import exception
from nova.volume import volume_types
@@ -48,14 +49,17 @@ class VolumeTypesTemplate(xmlutil.TemplateBuilder):
return xmlutil.MasterTemplate(root, 1)
-class VolumeTypesController(object):
+class VolumeTypesController(wsgi.Controller):
""" The volume types API controller for the OpenStack API """
+ _view_builder_class = views_types.ViewBuilder
+
@wsgi.serializers(xml=VolumeTypesTemplate)
def index(self, req):
""" Returns the list of volume types """
context = req.environ['nova.context']
- return {'volume_types': volume_types.get_all_types(context).values()}
+ vol_types = volume_types.get_all_types(context).values()
+ return self._view_builder.index(req, vol_types)
@wsgi.serializers(xml=VolumeTypeTemplate)
def show(self, req, id):
@@ -69,7 +73,7 @@ class VolumeTypesController(object):
# TODO(bcwaldon): remove str cast once we use uuids
vol_type['id'] = str(vol_type['id'])
- return {'volume_type': vol_type}
+ return self._view_builder.show(req, vol_type)
def create_resource():
diff --git a/nova/api/openstack/volume/views/types.py b/nova/api/openstack/volume/views/types.py
new file mode 100644
index 000000000..8274a0c6f
--- /dev/null
+++ b/nova/api/openstack/volume/views/types.py
@@ -0,0 +1,34 @@
+# vim: tabstop=4 shiftwidth=4 softtabstop=4
+
+# Copyright 2012 Red Hat, Inc.
+# All Rights Reserved.
+#
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
+# not use this file except in compliance with the License. You may obtain
+# a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+from nova.api.openstack import common
+
+
+class ViewBuilder(common.ViewBuilder):
+
+ def show(self, request, volume_type, brief=False):
+ """Trim away extraneous volume type attributes."""
+ trimmed = dict(id=volume_type.get('id'),
+ name=volume_type.get('name'),
+ extra_specs=volume_type.get('extra_specs'))
+ return trimmed if brief else dict(volume_type=trimmed)
+
+ def index(self, request, volume_types):
+ """Index over trimmed volume types"""
+ volume_types_list = [self.show(request, volume_type, True)
+ for volume_type in volume_types]
+ return dict(volume_types=volume_types_list)