~ubuntu-cloud-archive/ubuntu/precise/nova/trunk

« back to all changes in this revision

Viewing changes to nova/api/openstack/compute/contrib/volumes.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Soren Hansen
  • Date: 2012-09-07 17:49:53 UTC
  • mfrom: (1.1.61)
  • Revision ID: package-import@ubuntu.com-20120907174953-oapuvix1jxm830he
Tags: 2012.2~rc1~20120907.15996-0ubuntu1
[ Chuck Short ]
* New upstream release.
* debian/nova-common.postinst: Drop nova_sudoers permission changing
  since we do it in the debian/rules. (LP: #995285)

[ Soren Hansen ]
* Update debian/watch to account for symbolically named tarballs and
  use newer URL.
* Fix Launchpad URLs in debian/watch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
import webob
19
19
from webob import exc
 
20
from xml.dom import minidom
20
21
 
21
22
from nova.api.openstack import common
22
23
from nova.api.openstack import extensions
74
75
    LOG.audit(_("vol=%s"), vol, context=context)
75
76
 
76
77
    if vol.get('volume_metadata'):
77
 
        meta_dict = {}
78
 
        for i in vol['volume_metadata']:
79
 
            meta_dict[i['key']] = i['value']
80
 
        d['metadata'] = meta_dict
 
78
        metadata = vol.get('volume_metadata')
 
79
        d['metadata'] = dict((item['key'], item['value']) for item in metadata)
81
80
    else:
82
81
        d['metadata'] = {}
83
82
 
100
99
                                            selector='attachments')
101
100
    make_attachment(attachment)
102
101
 
103
 
    metadata = xmlutil.make_flat_dict('metadata')
104
 
    elem.append(metadata)
 
102
    # Attach metadata node
 
103
    elem.append(common.MetadataTemplate())
105
104
 
106
105
 
107
106
class VolumeTemplate(xmlutil.TemplateBuilder):
119
118
        return xmlutil.MasterTemplate(root, 1)
120
119
 
121
120
 
 
121
class CommonDeserializer(wsgi.MetadataXMLDeserializer):
 
122
    """Common deserializer to handle xml-formatted volume requests.
 
123
 
 
124
       Handles standard volume attributes as well as the optional metadata
 
125
       attribute
 
126
    """
 
127
 
 
128
    metadata_deserializer = common.MetadataXMLDeserializer()
 
129
 
 
130
    def _extract_volume(self, node):
 
131
        """Marshal the volume attribute of a parsed request."""
 
132
        volume = {}
 
133
        volume_node = self.find_first_child_named(node, 'volume')
 
134
 
 
135
        attributes = ['display_name', 'display_description', 'size',
 
136
                      'volume_type', 'availability_zone']
 
137
        for attr in attributes:
 
138
            if volume_node.getAttribute(attr):
 
139
                volume[attr] = volume_node.getAttribute(attr)
 
140
 
 
141
        metadata_node = self.find_first_child_named(volume_node, 'metadata')
 
142
        if metadata_node is not None:
 
143
            volume['metadata'] = self.extract_metadata(metadata_node)
 
144
 
 
145
        return volume
 
146
 
 
147
 
 
148
class CreateDeserializer(CommonDeserializer):
 
149
    """Deserializer to handle xml-formatted create volume requests.
 
150
 
 
151
       Handles standard volume attributes as well as the optional metadata
 
152
       attribute
 
153
    """
 
154
 
 
155
    def default(self, string):
 
156
        """Deserialize an xml-formatted volume create request."""
 
157
        dom = minidom.parseString(string)
 
158
        volume = self._extract_volume(dom)
 
159
        return {'body': {'volume': volume}}
 
160
 
 
161
 
122
162
class VolumeController(object):
123
163
    """The Volumes API controller for the OpenStack API."""
124
164
 
174
214
        return {'volumes': res}
175
215
 
176
216
    @wsgi.serializers(xml=VolumeTemplate)
 
217
    @wsgi.deserializers(xml=CreateDeserializer)
177
218
    def create(self, req, body):
178
219
        """Creates a new volume."""
179
220
        context = req.environ['nova.context']