Skip to content

Commit

Permalink
Fix XML serializer for QoS Specs extension
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Zhiteng Huang authored and openstack-gerrit committed Sep 30, 2013
1 parent e7c666f commit fe1d9db
Showing 1 changed file with 28 additions and 13 deletions.
41 changes: 28 additions & 13 deletions cinder/api/contrib/qos_specs_manage.py
Expand Up @@ -35,24 +35,39 @@
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)


Expand Down Expand Up @@ -245,7 +260,7 @@ def delete_keys(self, req, id, body):

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']
Expand Down

0 comments on commit fe1d9db

Please sign in to comment.