diff options
| author | Matthew Treinish <treinish@linux.vnet.ibm.com> | 2012-08-30 11:47:56 -0400 |
|---|---|---|
| committer | Matthew Treinish <treinish@linux.vnet.ibm.com> | 2012-08-30 15:15:22 -0400 |
| commit | eb86e97cebbdbff17e591e5674c334501ced1279 (patch) | |
| tree | e222734fa3174cec0c4d9ee055e07c485479effa /nova/api | |
| parent | b6f5d60f52eb0045ca074826971d9e4529e1eb3c (diff) | |
| download | nova-eb86e97cebbdbff17e591e5674c334501ced1279.tar.gz nova-eb86e97cebbdbff17e591e5674c334501ced1279.tar.xz nova-eb86e97cebbdbff17e591e5674c334501ced1279.zip | |
Fix xml metadata for volumes extension.
Fixes bug 1040891
Change-Id: I3a5d46af18f764e86ab457071d2b3afafdcdaa24
Signed-off-by: Matthew Treinish <treinish@linux.vnet.ibm.com>
Diffstat (limited to 'nova/api')
| -rw-r--r-- | nova/api/openstack/compute/contrib/volumes.py | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/nova/api/openstack/compute/contrib/volumes.py b/nova/api/openstack/compute/contrib/volumes.py index 99d713cef..df3c14169 100644 --- a/nova/api/openstack/compute/contrib/volumes.py +++ b/nova/api/openstack/compute/contrib/volumes.py @@ -17,6 +17,7 @@ import webob from webob import exc +from xml.dom import minidom from nova.api.openstack import common from nova.api.openstack import extensions @@ -74,10 +75,8 @@ def _translate_volume_summary_view(context, vol): LOG.audit(_("vol=%s"), vol, context=context) if vol.get('volume_metadata'): - meta_dict = {} - for i in vol['volume_metadata']: - meta_dict[i['key']] = i['value'] - d['metadata'] = meta_dict + metadata = vol.get('volume_metadata') + d['metadata'] = dict((item['key'], item['value']) for item in metadata) else: d['metadata'] = {} @@ -100,8 +99,8 @@ def make_volume(elem): selector='attachments') make_attachment(attachment) - metadata = xmlutil.make_flat_dict('metadata') - elem.append(metadata) + # Attach metadata node + elem.append(common.MetadataTemplate()) class VolumeTemplate(xmlutil.TemplateBuilder): @@ -119,6 +118,47 @@ class VolumesTemplate(xmlutil.TemplateBuilder): return xmlutil.MasterTemplate(root, 1) +class CommonDeserializer(wsgi.MetadataXMLDeserializer): + """Common deserializer to handle xml-formatted volume requests. + + Handles standard volume attributes as well as the optional metadata + attribute + """ + + metadata_deserializer = common.MetadataXMLDeserializer() + + def _extract_volume(self, node): + """Marshal the volume attribute of a parsed request.""" + volume = {} + volume_node = self.find_first_child_named(node, 'volume') + + attributes = ['display_name', 'display_description', 'size', + 'volume_type', 'availability_zone'] + for attr in attributes: + if volume_node.getAttribute(attr): + volume[attr] = volume_node.getAttribute(attr) + + metadata_node = self.find_first_child_named(volume_node, 'metadata') + if metadata_node is not None: + volume['metadata'] = self.extract_metadata(metadata_node) + + return volume + + +class CreateDeserializer(CommonDeserializer): + """Deserializer to handle xml-formatted create volume requests. + + Handles standard volume attributes as well as the optional metadata + attribute + """ + + def default(self, string): + """Deserialize an xml-formatted volume create request.""" + dom = minidom.parseString(string) + volume = self._extract_volume(dom) + return {'body': {'volume': volume}} + + class VolumeController(object): """The Volumes API controller for the OpenStack API.""" @@ -174,6 +214,7 @@ class VolumeController(object): return {'volumes': res} @wsgi.serializers(xml=VolumeTemplate) + @wsgi.deserializers(xml=CreateDeserializer) def create(self, req, body): """Creates a new volume.""" context = req.environ['nova.context'] |
