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:
@@ -17,20 +17,12 @@ from reddwarfclient import base
|
|||||||
from reddwarfclient.common import check_for_exceptions
|
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):
|
class Quotas(base.ManagerWithFind):
|
||||||
"""
|
"""
|
||||||
Manage :class:`Quota` information.
|
Manage :class:`Quota` information.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
resource_class = Quota
|
resource_class = base.Resource
|
||||||
|
|
||||||
def show(self, tenant_id):
|
def show(self, tenant_id):
|
||||||
"""Get a list of all quotas for a 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)
|
check_for_exceptions(resp, body)
|
||||||
if not body:
|
if not body:
|
||||||
raise Exception("Call to " + url + " did not return a 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):
|
def update(self, id, quotas):
|
||||||
"""
|
"""
|
||||||
@@ -52,4 +46,6 @@ class Quotas(base.ManagerWithFind):
|
|||||||
check_for_exceptions(resp, body)
|
check_for_exceptions(resp, body)
|
||||||
if not body:
|
if not body:
|
||||||
raise Exception("Call to " + url + " did not return a 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']
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ LISTIFY = {
|
|||||||
"backups": [[]]
|
"backups": [[]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class IntDict(object):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
TYPE_MAP = {
|
TYPE_MAP = {
|
||||||
"instance": {
|
"instance": {
|
||||||
"volume": {
|
"volume": {
|
||||||
@@ -55,6 +60,7 @@ TYPE_MAP = {
|
|||||||
"from_port": int,
|
"from_port": int,
|
||||||
"to_port": int,
|
"to_port": int,
|
||||||
},
|
},
|
||||||
|
"quotas": IntDict,
|
||||||
}
|
}
|
||||||
TYPE_MAP["flavors"] = TYPE_MAP["flavor"]
|
TYPE_MAP["flavors"] = TYPE_MAP["flavor"]
|
||||||
|
|
||||||
@@ -242,10 +248,14 @@ def modify_response_types(value, type_translator):
|
|||||||
return type_translator(value)
|
return type_translator(value)
|
||||||
elif isinstance(value, dict):
|
elif isinstance(value, dict):
|
||||||
for k, v in value.iteritems():
|
for k, v in value.iteritems():
|
||||||
if v.__class__ is dict and v.__len__() == 0:
|
if type_translator is not IntDict:
|
||||||
value[k] = None
|
if v.__class__ is dict and v.__len__() == 0:
|
||||||
if k in type_translator:
|
value[k] = None
|
||||||
value[k] = modify_response_types(value[k], type_translator[k])
|
elif k in type_translator:
|
||||||
|
value[k] = modify_response_types(value[k],
|
||||||
|
type_translator[k])
|
||||||
|
else:
|
||||||
|
value[k] = int(value[k])
|
||||||
return value
|
return value
|
||||||
elif isinstance(value, list):
|
elif isinstance(value, list):
|
||||||
return [modify_response_types(element, type_translator)
|
return [modify_response_types(element, type_translator)
|
||||||
|
|||||||
Reference in New Issue
Block a user