diff options
| author | Jorge L. Williams <jorge.williams@rackspace.com> | 2011-04-21 05:09:43 -0500 |
|---|---|---|
| committer | Jorge L. Williams <jorge.williams@rackspace.com> | 2011-04-21 05:09:43 -0500 |
| commit | 61f495812a648180cd91e6a1d63dfd0e6bfb7aa7 (patch) | |
| tree | 6ff08d2a78eba8a969077dac7b487e40bb8b509b | |
| parent | 34e212b49135f86f535451afa2fc130876b52fe2 (diff) | |
XML and JSON rendering on tenant/s
| -rw-r--r-- | keystone/logic/types/tenant.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/keystone/logic/types/tenant.py b/keystone/logic/types/tenant.py index 33f82120..9a43b0d6 100644 --- a/keystone/logic/types/tenant.py +++ b/keystone/logic/types/tenant.py @@ -13,6 +13,10 @@ # See the License for the specific language governing permissions and # limitations under the License. +import string as s +import simplejson as json +from lxml import etree + class Tenant(object): "Describes a tenant in the auth system" @@ -34,6 +38,31 @@ class Tenant(object): def enabled(self): return self.__enabled + def to_dom(self): + dom = etree.Element("tenant", + xmlns="http://docs.openstack.org/idm/api/v1.0", + enabled=s.lower(self.__enabled.__str__())) + dom.set("id", self.__tenant_id) + desc = etree.Element("description") + desc.text = self.__description + dom.append(desc) + return dom + + def to_xml(self): + return etree.tostring(self.to_dom()) + + def to_dict(self): + tenant = {} + tenant["id"] = self.__tenant_id + tenant["description"] = self.__description + tenant["enabled"] = s.lower(self.__enabled.__str__()) + ret = {} + ret["tenant"] = tenant + return ret + + def to_json(self): + return json.dumps(self.to_dict()) + class Tenants(object): "A collection of tenants." @@ -49,3 +78,20 @@ class Tenants(object): @property def links(self): return self.__links + + def to_xml(self): + dom = etree.Element("tenants", + xmlns="http://docs.openstack.org/idm/api/v1.0") + for t in self.__values: + dom.append(t.to_dom()) + return etree.tostring(dom) + + def to_json(self): + values=[] + for t in self.__values: + values.append(t.to_dict()["tenant"]) + v = {} + v["values"] = values + ret = {} + ret["tenants"] = values + return json.dumps(ret) |
