From 6222dea1404038b70ca0c18179b9cac4227bd851 Mon Sep 17 00:00:00 2001 From: Tim Simpson Date: Wed, 10 Apr 2013 10:39:09 -0500 Subject: [PATCH] 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 --- reddwarfclient/quota.py | 18 +++++++----------- reddwarfclient/xml.py | 18 ++++++++++++++---- 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/reddwarfclient/quota.py b/reddwarfclient/quota.py index 8fa72278..e5a8f749 100644 --- a/reddwarfclient/quota.py +++ b/reddwarfclient/quota.py @@ -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 "" % 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'] diff --git a/reddwarfclient/xml.py b/reddwarfclient/xml.py index fc9e5ff8..fe94f196 100644 --- a/reddwarfclient/xml.py +++ b/reddwarfclient/xml.py @@ -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)