Use a plain dict for Quotas.show method.

This also fixes the XML version translator to convert the strings
to integers.

implements blueprint use-plain-dict-for-quotas-show

Change-Id: I4764313a863e9c1fd0ee8fa00645b57535d47c76
This commit is contained in:
Tim Simpson
2013-04-10 10:39:09 -05:00
parent df4175ea5c
commit 6222dea140
2 changed files with 21 additions and 15 deletions

View File

@@ -17,20 +17,12 @@ from reddwarfclient import base
from reddwarfclient.common import check_for_exceptions
class Quota(base.Resource):
"""
Quota is a resource used to hold quota information.
"""
def __repr__(self):
return "<Quota: %s>" % self.name
class Quotas(base.ManagerWithFind):
"""
Manage :class:`Quota` information.
"""
resource_class = Quota
resource_class = base.Resource
def show(self, tenant_id):
"""Get a list of all quotas for a tenant id"""
@@ -40,7 +32,9 @@ class Quotas(base.ManagerWithFind):
check_for_exceptions(resp, body)
if not body:
raise Exception("Call to " + url + " did not return a body.")
return base.Resource(self, body)
if 'quotas' not in body:
raise Exception("Missing key value 'quotas' in response body.")
return body['quotas']
def update(self, id, quotas):
"""
@@ -52,4 +46,6 @@ class Quotas(base.ManagerWithFind):
check_for_exceptions(resp, body)
if not body:
raise Exception("Call to " + url + " did not return a body.")
return base.Resource(self, body)
if 'quotas' not in body:
raise Exception("Missing key value 'quotas' in response body.")
return body['quotas']

View File

@@ -24,6 +24,11 @@ LISTIFY = {
"backups": [[]]
}
class IntDict(object):
pass
TYPE_MAP = {
"instance": {
"volume": {
@@ -55,6 +60,7 @@ TYPE_MAP = {
"from_port": int,
"to_port": int,
},
"quotas": IntDict,
}
TYPE_MAP["flavors"] = TYPE_MAP["flavor"]
@@ -242,10 +248,14 @@ def modify_response_types(value, type_translator):
return type_translator(value)
elif isinstance(value, dict):
for k, v in value.iteritems():
if v.__class__ is dict and v.__len__() == 0:
value[k] = None
if k in type_translator:
value[k] = modify_response_types(value[k], type_translator[k])
if type_translator is not IntDict:
if v.__class__ is dict and v.__len__() == 0:
value[k] = None
elif k in type_translator:
value[k] = modify_response_types(value[k],
type_translator[k])
else:
value[k] = int(value[k])
return value
elif isinstance(value, list):
return [modify_response_types(element, type_translator)