]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fix XML serializer for QoS Specs extension
authorZhiteng Huang <zhithuang@ebaysf.com>
Wed, 25 Sep 2013 08:40:41 +0000 (16:40 +0800)
committerGerrit Code Review <review@openstack.org>
Mon, 30 Sep 2013 03:55:38 +0000 (03:55 +0000)
This patch fixes XML serializer for QoS Specs exension calls like
list(), show(), associations().  Note that using XML as input for
create(), update() doesn't support yet.

Closes-Bug: # 1229619

Change-Id: I2eab9d69e05bb03269b51731458994d6268ac852

cinder/api/contrib/qos_specs_manage.py

index 89b309f08c4a3205724e91389d2c15989b3acbf0..43a94f646bd8062f89189c165eda17c1518f857e 100644 (file)
@@ -35,24 +35,39 @@ LOG = logging.getLogger(__name__)
 authorize = extensions.extension_authorizer('volume', 'qos_specs_manage')
 
 
-class QoSSpecsTemplate(xmlutil.TemplateBuilder):
+def make_qos_specs(elem):
+    elem.set('id')
+    elem.set('name')
+    elem.set('consumer')
+    elem.append(SpecsTemplate())
+
+
+def make_associations(elem):
+    elem.set('association_type')
+    elem.set('name')
+    elem.set('id')
+
+
+class SpecsTemplate(xmlutil.TemplateBuilder):
     def construct(self):
-        root = xmlutil.make_flat_dict('qos_specs', selector='qos_specs')
-        return xmlutil.MasterTemplate(root, 1)
+        return xmlutil.MasterTemplate(xmlutil.make_flat_dict('specs'), 1)
 
 
-class QoSSpecTemplate(xmlutil.TemplateBuilder):
-    # FIXME(zhiteng) Need to handle consumer
+class QoSSpecsTemplate(xmlutil.TemplateBuilder):
     def construct(self):
-        tagname = xmlutil.Selector('key')
+        root = xmlutil.TemplateElement('qos_specs')
+        elem = xmlutil.SubTemplateElement(root, 'qos_spec',
+                                          selector='qos_specs')
+        make_qos_specs(elem)
+        return xmlutil.MasterTemplate(root, 1)
 
-        def qosspec_sel(obj, do_raise=False):
-            # Have to extract the key and value for later use...
-            key, value = obj.items()[0]
-            return dict(key=key, value=value)
 
-        root = xmlutil.TemplateElement(tagname, selector=qosspec_sel)
-        root.text = 'value'
+class AssociationsTemplate(xmlutil.TemplateBuilder):
+    def construct(self):
+        root = xmlutil.TemplateElement('qos_associations')
+        elem = xmlutil.SubTemplateElement(root, 'associations',
+                                          selector='qos_associations')
+        make_associations(elem)
         return xmlutil.MasterTemplate(root, 1)
 
 
@@ -245,7 +260,7 @@ class QoSSpecsController(wsgi.Controller):
 
         return webob.Response(status_int=202)
 
-    @wsgi.serializers(xml=QoSSpecsTemplate)
+    @wsgi.serializers(xml=AssociationsTemplate)
     def associations(self, req, id):
         """List all associations of given qos specs."""
         context = req.environ['cinder.context']