1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright (c) 2011 Zadara Storage Inc.
4
# Copyright (c) 2011 OpenStack LLC.
6
# Licensed under the Apache License, Version 2.0 (the "License"); you may
7
# not use this file except in compliance with the License. You may obtain
8
# a copy of the License at
10
# http://www.apache.org/licenses/LICENSE-2.0
12
# Unless required by applicable law or agreed to in writing, software
13
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15
# License for the specific language governing permissions and limitations
18
""" The volume type & volume types extra specs extension"""
22
from nova.api.openstack import wsgi
23
from nova.api.openstack import xmlutil
24
from nova import exception
25
from nova.volume import volume_types
28
class VolumeTypesController(object):
29
""" The volume types API controller for the Openstack API """
32
""" Returns the list of volume types """
33
context = req.environ['nova.context']
34
return volume_types.get_all_types(context)
36
def show(self, req, id):
37
""" Return a single volume type item """
38
context = req.environ['nova.context']
41
vol_type = volume_types.get_volume_type(context, id)
42
except exception.NotFound or exception.ApiError:
43
raise exc.HTTPNotFound()
45
return {'volume_type': vol_type}
48
def make_voltype(elem):
51
extra_specs = xmlutil.make_flat_dict('extra_specs', selector='extra_specs')
52
elem.append(extra_specs)
55
class VolumeTypeTemplate(xmlutil.TemplateBuilder):
57
root = xmlutil.TemplateElement('volume_type', selector='volume_type')
59
return xmlutil.MasterTemplate(root, 1)
62
class VolumeTypesTemplate(xmlutil.TemplateBuilder):
64
root = xmlutil.TemplateElement('volume_types')
65
sel = lambda obj, do_raise=False: obj.values()
66
elem = xmlutil.SubTemplateElement(root, 'volume_type', selector=sel)
68
return xmlutil.MasterTemplate(root, 1)
71
class VolumeTypesSerializer(xmlutil.XMLTemplateSerializer):
73
return VolumeTypesTemplate()
76
return VolumeTypeTemplate()
79
def create_resource():
81
'application/xml': VolumeTypesSerializer(),
83
serializer = wsgi.ResponseSerializer(body_serializers)
85
deserializer = wsgi.RequestDeserializer()
87
return wsgi.Resource(VolumeTypesController(), serializer=serializer)