summaryrefslogtreecommitdiff
path: root/keystoneclient/service_catalog.py
diff options
context:
space:
mode:
authorJamie Lennox <jlennox@redhat.com>2013-08-05 11:03:07 +1000
committerJamie Lennox <jlennox@redhat.com>2013-08-12 17:01:14 +1000
commit881dd2d12b8b0a4699d42b6e0e8647e1a20b38ce (patch)
treed21276d85bf699f6f32f4f44d33ee2cd940cdabe /keystoneclient/service_catalog.py
parent08d0ef8ee87f6899662f96af4c95eb8b7ff8f455 (diff)
downloadpython-keystoneclient-881dd2d12b8b0a4699d42b6e0e8647e1a20b38ce.tar.gz
Add a get_data function to Service Catalog
Service catalog takes as a parameter the entire token. This makes it difficult to extract only the service catalog component without querying the catalog version, which should be unnecessary. Change-Id: I3ad428fcb3279e8aa607f67f58265a085ae63440
Diffstat (limited to 'keystoneclient/service_catalog.py')
-rw-r--r--keystoneclient/service_catalog.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/keystoneclient/service_catalog.py b/keystoneclient/service_catalog.py
index 0fbc18c..9f569a4 100644
--- a/keystoneclient/service_catalog.py
+++ b/keystoneclient/service_catalog.py
@@ -90,6 +90,16 @@ class ServiceCatalog(object):
"""
raise NotImplementedError()
+ def get_data(self):
+ """Get the raw catalog structure.
+
+ Get the version dependant catalog structure as it is presented within
+ the resource.
+
+ :returns: dict containing raw catalog data or None
+ """
+ raise NotImplementedError()
+
class ServiceCatalogV2(ServiceCatalog):
"""An object for encapsulating the service catalog using raw v2 auth token
@@ -107,6 +117,9 @@ class ServiceCatalogV2(ServiceCatalog):
# will not work. Use 'token' attribute instead.
return 'token' in resource_dict
+ def get_data(self):
+ return self.catalog.get('serviceCatalog')
+
def get_token(self):
token = {'id': self.catalog['token']['id'],
'expires': self.catalog['token']['expires']}
@@ -123,7 +136,7 @@ class ServiceCatalogV2(ServiceCatalog):
endpoint_type = endpoint_type + 'URL'
sc = {}
- for service in self.catalog.get('serviceCatalog', []):
+ for service in (self.get_data() or []):
if service_type and service_type != service['type']:
continue
sc[service['type']] = []
@@ -154,7 +167,7 @@ class ServiceCatalogV2(ServiceCatalog):
def url_for(self, attr=None, filter_value=None,
service_type='identity', endpoint_type='publicURL'):
- catalog = self.catalog.get('serviceCatalog', [])
+ catalog = self.get_data()
if not catalog:
raise exceptions.EmptyCatalog('The service catalog is empty.')
@@ -195,6 +208,9 @@ class ServiceCatalogV3(ServiceCatalog):
# will not work. Use 'methods' attribute instead.
return 'methods' in resource_dict
+ def get_data(self):
+ return self.catalog.get('catalog')
+
def get_token(self):
token = {'id': self._auth_token,
'expires': self.catalog['expires_at']}
@@ -215,7 +231,7 @@ class ServiceCatalogV3(ServiceCatalog):
if endpoint_type:
endpoint_type = endpoint_type.rstrip('URL')
sc = {}
- for service in self.catalog.get('catalog', []):
+ for service in (self.get_data() or []):
if service_type and service_type != service['type']:
continue
sc[service['type']] = []
@@ -247,7 +263,7 @@ class ServiceCatalogV3(ServiceCatalog):
def url_for(self, attr=None, filter_value=None,
service_type='identity', endpoint_type='public'):
- catalog = self.catalog.get('catalog', [])
+ catalog = self.get_data()
if not catalog:
raise exceptions.EmptyCatalog('The service catalog is empty.')