From f7989f34a6a2eefe3ccdbf27d429e0dfb35dc42f Mon Sep 17 00:00:00 2001 From: "Jorge L. Williams" Date: Fri, 22 Apr 2011 21:57:02 -0500 Subject: Initial implementation of get tenants. --- keystone/identity2.py | 13 +++++++++++++ keystone/logic/service.py | 13 ++++++++++--- keystone/logic/types/tenant.py | 7 +++++-- test/IdentitySOAPUI.xml | 6 ++++-- 4 files changed, 32 insertions(+), 7 deletions(-) diff --git a/keystone/identity2.py b/keystone/identity2.py index 0ca65c0d..af20b363 100644 --- a/keystone/identity2.py +++ b/keystone/identity2.py @@ -122,4 +122,17 @@ def create_tenant(): except Exception as e: return send_error (e) +@route('/v1.0/tenants', method='GET') +def get_tenants(): + try: + marker = None + if "marker" in request.GET: + marker = request.GET["marker"] + limit = None + if "limit" in request.GET: + limit = request.GET["limit"] + return send_result(service.get_tenants(get_auth_token(), marker, limit), 200) + except Exception as e: + return send_error (e) + run(host='localhost', port=8080) diff --git a/keystone/logic/service.py b/keystone/logic/service.py index 43a42a32..51c9c7b7 100644 --- a/keystone/logic/service.py +++ b/keystone/logic/service.py @@ -110,10 +110,17 @@ class IDMService(object): return tenant - def get_tenant(self, admin_token, tenant_id): - True - def get_tenants(self, admin_token, marker, limit): + self.__validate_token(admin_token) + + ts = [] + dtenants = db_api.tenant_get_all() + for dtenant in dtenants: + ts.append (tenants.Tenant(dtenant.id, dtenant.desc, dtenant.enabled)) + + return tenants.Tenants(ts,[]) + + def get_tenant(self, admin_token, tenant_id): True def update_tenant(self, admin_token, tenant): diff --git a/keystone/logic/types/tenant.py b/keystone/logic/types/tenant.py index 5a4c6de1..a1d50902 100644 --- a/keystone/logic/types/tenant.py +++ b/keystone/logic/types/tenant.py @@ -25,7 +25,10 @@ class Tenant(object): def __init__(self, tenant_id, description, enabled): self.__tenant_id = tenant_id self.__description = description - self.__enabled = enabled + if enabled: + self.__enabled = True + else: + self.__enabled = False @staticmethod def from_xml(xml_str): @@ -141,5 +144,5 @@ class Tenants(object): v = {} v["values"] = values ret = {} - ret["tenants"] = values + ret["tenants"] = v return json.dumps(ret) diff --git a/test/IdentitySOAPUI.xml b/test/IdentitySOAPUI.xml index aebccc27..2de1593d 100644 --- a/test/IdentitySOAPUI.xml +++ b/test/IdentitySOAPUI.xml @@ -1114,7 +1114,7 @@ xmlns="http://docs.openstack.org/idm/api/v1.0"/>http://localhost:8080markerQUERYxs:stringlimitQUERYxs:intapplication/xml200 203v1:tenantsapplication/json200 203application/xml401v1:unauthorizedapplication/xml403v1:forbiddenapplication/xml400v1:badRequestapplication/xml404v1:itemNotFoundapplication/xml500v1:idmFaultapplication/xml503v1:serviceUnavailableapplication/json400 -401 403 404 500 503http://localhost:8080application/xmlv1:tenantapplication/jsonapplication/xml201v1:tenantapplication/json201application/xml401v1:unauthorizedapplication/xml403v1:forbiddenapplication/xml +401 403 404 500 503<xml-fragment/>http://localhost:8080application/xmlv1:tenantapplication/jsonapplication/xml201v1:tenantapplication/json201application/xml401v1:unauthorizedapplication/xml403v1:forbiddenapplication/xml 409v1:tenantConflictapplication/xml 400v1:badRequestapplication/xml500v1:idmFaultapplication/xml503v1:serviceUnavailableapplication/json401 403 400 409 500 503<xml-fragment/>http://localhost:8080<v1:tenant @@ -1250,4 +1250,6 @@ ns1:Response/ns1:tenant/ns1:id = "JGroup65" and ns1:Response/ns1:tenant/ns1:desc "description" : "A description...", "enabled": "true" } -}400falsefalsebadRequestfalsefalse \ No newline at end of file +}400falsefalsebadRequestfalsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://docs.openstack.org/idm/api/v1.0'; +count(//ns1:tenant)8falsefalse<xml-fragment/>http://localhost:8080declare namespace ns1='http://localhost/v1.0/tenants'; +count(//ns1:e)8falsefalse \ No newline at end of file -- cgit