summaryrefslogtreecommitdiffstats
path: root/nova/api
diff options
context:
space:
mode:
authorMatthew Treinish <treinish@linux.vnet.ibm.com>2012-09-04 10:23:18 -0400
committerMatthew Treinish <treinish@linux.vnet.ibm.com>2012-09-04 10:23:18 -0400
commit1f82e30db8e628e956190ea76f71c8a6f4803e24 (patch)
treef436fc35746cc7a80dff5d0233eac2c64b024847 /nova/api
parent0318efe625682ee8703b91f363a966200503782f (diff)
downloadnova-1f82e30db8e628e956190ea76f71c8a6f4803e24.tar.gz
nova-1f82e30db8e628e956190ea76f71c8a6f4803e24.tar.xz
nova-1f82e30db8e628e956190ea76f71c8a6f4803e24.zip
Fix xml metadata for volumes api in nova-volume.
Fixes bug 1040891 Change-Id: I6295e4084adc33999bfdf66728623b278895b2d6 Signed-off-by: Matthew Treinish <treinish@linux.vnet.ibm.com>
Diffstat (limited to 'nova/api')
-rw-r--r--nova/api/openstack/volume/volumes.py53
1 files changed, 47 insertions, 6 deletions
diff --git a/nova/api/openstack/volume/volumes.py b/nova/api/openstack/volume/volumes.py
index 8c5652084..0589e63a2 100644
--- a/nova/api/openstack/volume/volumes.py
+++ b/nova/api/openstack/volume/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 wsgi
@@ -100,10 +101,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'] = {}
@@ -133,8 +132,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):
@@ -152,6 +151,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."""
@@ -210,6 +250,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']