From fe1d9db358c1da4ff041eedaff76f282f28a8670 Mon Sep 17 00:00:00 2001 From: Zhiteng Huang Date: Wed, 25 Sep 2013 16:40:41 +0800 Subject: [PATCH] Fix XML serializer for QoS Specs extension 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 | 41 ++++++++++++++++++-------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/cinder/api/contrib/qos_specs_manage.py b/cinder/api/contrib/qos_specs_manage.py index 89b309f08..43a94f646 100644 --- a/cinder/api/contrib/qos_specs_manage.py +++ b/cinder/api/contrib/qos_specs_manage.py @@ -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'] -- 2.45.2