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
This commit is contained in:
parent
8419ae30db
commit
419910655c
@ -90,6 +90,16 @@ class ServiceCatalog(object):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
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):
|
class ServiceCatalogV2(ServiceCatalog):
|
||||||
"""An object for encapsulating the service catalog using raw v2 auth token
|
"""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.
|
# will not work. Use 'token' attribute instead.
|
||||||
return 'token' in resource_dict
|
return 'token' in resource_dict
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
return self.catalog.get('serviceCatalog')
|
||||||
|
|
||||||
def get_token(self):
|
def get_token(self):
|
||||||
token = {'id': self.catalog['token']['id'],
|
token = {'id': self.catalog['token']['id'],
|
||||||
'expires': self.catalog['token']['expires']}
|
'expires': self.catalog['token']['expires']}
|
||||||
@ -123,7 +136,7 @@ class ServiceCatalogV2(ServiceCatalog):
|
|||||||
endpoint_type = endpoint_type + 'URL'
|
endpoint_type = endpoint_type + 'URL'
|
||||||
|
|
||||||
sc = {}
|
sc = {}
|
||||||
for service in self.catalog.get('serviceCatalog', []):
|
for service in (self.get_data() or []):
|
||||||
if service_type and service_type != service['type']:
|
if service_type and service_type != service['type']:
|
||||||
continue
|
continue
|
||||||
sc[service['type']] = []
|
sc[service['type']] = []
|
||||||
@ -154,7 +167,7 @@ class ServiceCatalogV2(ServiceCatalog):
|
|||||||
|
|
||||||
def url_for(self, attr=None, filter_value=None,
|
def url_for(self, attr=None, filter_value=None,
|
||||||
service_type='identity', endpoint_type='publicURL'):
|
service_type='identity', endpoint_type='publicURL'):
|
||||||
catalog = self.catalog.get('serviceCatalog', [])
|
catalog = self.get_data()
|
||||||
|
|
||||||
if not catalog:
|
if not catalog:
|
||||||
raise exceptions.EmptyCatalog('The service catalog is empty.')
|
raise exceptions.EmptyCatalog('The service catalog is empty.')
|
||||||
@ -195,6 +208,9 @@ class ServiceCatalogV3(ServiceCatalog):
|
|||||||
# will not work. Use 'methods' attribute instead.
|
# will not work. Use 'methods' attribute instead.
|
||||||
return 'methods' in resource_dict
|
return 'methods' in resource_dict
|
||||||
|
|
||||||
|
def get_data(self):
|
||||||
|
return self.catalog.get('catalog')
|
||||||
|
|
||||||
def get_token(self):
|
def get_token(self):
|
||||||
token = {'id': self._auth_token,
|
token = {'id': self._auth_token,
|
||||||
'expires': self.catalog['expires_at']}
|
'expires': self.catalog['expires_at']}
|
||||||
@ -215,7 +231,7 @@ class ServiceCatalogV3(ServiceCatalog):
|
|||||||
if endpoint_type:
|
if endpoint_type:
|
||||||
endpoint_type = endpoint_type.rstrip('URL')
|
endpoint_type = endpoint_type.rstrip('URL')
|
||||||
sc = {}
|
sc = {}
|
||||||
for service in self.catalog.get('catalog', []):
|
for service in (self.get_data() or []):
|
||||||
if service_type and service_type != service['type']:
|
if service_type and service_type != service['type']:
|
||||||
continue
|
continue
|
||||||
sc[service['type']] = []
|
sc[service['type']] = []
|
||||||
@ -247,7 +263,7 @@ class ServiceCatalogV3(ServiceCatalog):
|
|||||||
|
|
||||||
def url_for(self, attr=None, filter_value=None,
|
def url_for(self, attr=None, filter_value=None,
|
||||||
service_type='identity', endpoint_type='public'):
|
service_type='identity', endpoint_type='public'):
|
||||||
catalog = self.catalog.get('catalog', [])
|
catalog = self.get_data()
|
||||||
|
|
||||||
if not catalog:
|
if not catalog:
|
||||||
raise exceptions.EmptyCatalog('The service catalog is empty.')
|
raise exceptions.EmptyCatalog('The service catalog is empty.')
|
||||||
|
Loading…
Reference in New Issue
Block a user