Allow searching a catalog on service or endpoint id
endpoint_id and service_id are parts of both the v2 and v3 tokens. We should allow finding urls for them in the same way as other attributes. Change-Id: I22b5f4bd44e9a493017de89e14a705699df24280changes/67/210267/3
parent
5bc8e4804b
commit
2aa4d8384d
|
@ -55,8 +55,10 @@ class ServiceCatalog(object):
|
|||
"""
|
||||
return endpoint_type
|
||||
|
||||
@utils.positional()
|
||||
def get_endpoints(self, service_type=None, endpoint_type=None,
|
||||
region_name=None, service_name=None):
|
||||
region_name=None, service_name=None,
|
||||
service_id=None, endpoint_id=None):
|
||||
"""Fetch and filter endpoints for the specified service(s).
|
||||
|
||||
Returns endpoints for the specified service (or all) containing
|
||||
|
@ -94,6 +96,12 @@ class ServiceCatalog(object):
|
|||
if service_name != sn:
|
||||
continue
|
||||
|
||||
# NOTE(jamielennox): there is no such thing as a service_id in v2
|
||||
# similarly to service_name we'll have to skip this check if it's
|
||||
# not available.
|
||||
if service_id and 'id' in service and service_id != service['id']:
|
||||
continue
|
||||
|
||||
endpoints = sc.setdefault(st, [])
|
||||
|
||||
for endpoint in service.get('endpoints', []):
|
||||
|
@ -103,6 +111,8 @@ class ServiceCatalog(object):
|
|||
if (region_name and
|
||||
region_name != self._get_endpoint_region(endpoint)):
|
||||
continue
|
||||
if (endpoint_id and endpoint_id != endpoint.get('id')):
|
||||
continue
|
||||
endpoints.append(endpoint)
|
||||
|
||||
return sc
|
||||
|
@ -110,7 +120,8 @@ class ServiceCatalog(object):
|
|||
@abc.abstractmethod
|
||||
@utils.positional()
|
||||
def get_urls(self, service_type=None, endpoint_type='public',
|
||||
region_name=None, service_name=None):
|
||||
region_name=None, service_name=None,
|
||||
service_id=None, endpoint_id=None):
|
||||
"""Fetch endpoint urls from the service catalog.
|
||||
|
||||
Fetch the endpoints from the service catalog for a particular
|
||||
|
@ -124,6 +135,8 @@ class ServiceCatalog(object):
|
|||
adminURL
|
||||
:param string region_name: Region of the endpoint.
|
||||
:param string service_name: The assigned name of the service.
|
||||
:param string service_id: The identifier of a service.
|
||||
:param string endpoint_id: The identifier of an endpoint.
|
||||
|
||||
:returns: tuple of urls or None (if no match found)
|
||||
"""
|
||||
|
@ -131,7 +144,8 @@ class ServiceCatalog(object):
|
|||
|
||||
@utils.positional()
|
||||
def url_for(self, service_type=None, endpoint_type='public',
|
||||
region_name=None, service_name=None):
|
||||
region_name=None, service_name=None,
|
||||
service_id=None, endpoint_id=None):
|
||||
"""Fetch an endpoint from the service catalog.
|
||||
|
||||
Fetch the specified endpoint from the service catalog for
|
||||
|
@ -146,7 +160,8 @@ class ServiceCatalog(object):
|
|||
:param string endpoint_type: Type of endpoint.
|
||||
:param string region_name: Region of the endpoint.
|
||||
:param string service_name: The assigned name of the service.
|
||||
|
||||
:param string service_id: The identifier of a service.
|
||||
:param string endpoint_id: The identifier of an endpoint.
|
||||
"""
|
||||
if not self._catalog:
|
||||
raise exceptions.EmptyCatalog('The service catalog is empty.')
|
||||
|
@ -154,7 +169,9 @@ class ServiceCatalog(object):
|
|||
urls = self.get_urls(service_type=service_type,
|
||||
endpoint_type=endpoint_type,
|
||||
region_name=region_name,
|
||||
service_name=service_name)
|
||||
service_name=service_name,
|
||||
service_id=service_id,
|
||||
endpoint_id=endpoint_id)
|
||||
|
||||
try:
|
||||
return urls[0]
|
||||
|
@ -212,13 +229,16 @@ class ServiceCatalogV2(ServiceCatalog):
|
|||
|
||||
@utils.positional()
|
||||
def get_urls(self, service_type=None, endpoint_type='publicURL',
|
||||
region_name=None, service_name=None):
|
||||
region_name=None, service_name=None,
|
||||
service_id=None, endpoint_id=None):
|
||||
endpoint_type = self.normalize_endpoint_type(endpoint_type)
|
||||
|
||||
sc_endpoints = self.get_endpoints(service_type=service_type,
|
||||
endpoint_type=endpoint_type,
|
||||
region_name=region_name,
|
||||
service_name=service_name)
|
||||
service_name=service_name,
|
||||
service_id=service_id,
|
||||
endpoint_id=endpoint_id)
|
||||
|
||||
try:
|
||||
endpoints = sc_endpoints[service_type]
|
||||
|
@ -255,11 +275,14 @@ class ServiceCatalogV3(ServiceCatalog):
|
|||
|
||||
@utils.positional()
|
||||
def get_urls(self, service_type=None, endpoint_type='publicURL',
|
||||
region_name=None, service_name=None):
|
||||
region_name=None, service_name=None,
|
||||
service_id=None, endpoint_id=None):
|
||||
sc_endpoints = self.get_endpoints(service_type=service_type,
|
||||
endpoint_type=endpoint_type,
|
||||
region_name=region_name,
|
||||
service_name=service_name)
|
||||
service_name=service_name,
|
||||
service_id=service_id,
|
||||
endpoint_id=endpoint_id)
|
||||
|
||||
try:
|
||||
endpoints = sc_endpoints[service_type]
|
||||
|
|
|
@ -211,3 +211,41 @@ class ServiceCatalogTest(utils.TestCase):
|
|||
region_name='region-1')
|
||||
|
||||
self.assertEqual(('public-1', ), urls)
|
||||
|
||||
def test_service_catalog_endpoint_id(self):
|
||||
token = fixture.V2Token()
|
||||
token.set_scope()
|
||||
endpoint_id = uuid.uuid4().hex
|
||||
public_url = uuid.uuid4().hex
|
||||
|
||||
s = token.add_service('compute')
|
||||
s.add_endpoint(public=public_url, id=endpoint_id)
|
||||
s.add_endpoint(public=uuid.uuid4().hex)
|
||||
|
||||
auth_ref = access.create(body=token)
|
||||
|
||||
# initially assert that we get back all our urls for a simple filter
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_type='public')
|
||||
self.assertEqual(2, len(urls))
|
||||
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_id=endpoint_id,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual((public_url, ), urls)
|
||||
|
||||
# with bad endpoint_id nothing should be found
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_id=uuid.uuid4().hex,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual(0, len(urls))
|
||||
|
||||
# we ignore a service_id because v2 doesn't know what it is
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_id=endpoint_id,
|
||||
service_id=uuid.uuid4().hex,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual((public_url, ), urls)
|
||||
|
|
|
@ -321,3 +321,50 @@ class ServiceCatalogV3Test(ServiceCatalogTest):
|
|||
region_name='region-1')
|
||||
|
||||
self.assertEqual(('public-1', ), urls)
|
||||
|
||||
def test_service_catalog_endpoint_id(self):
|
||||
token = fixture.V3Token()
|
||||
token.set_project_scope()
|
||||
|
||||
service_id = uuid.uuid4().hex
|
||||
endpoint_id = uuid.uuid4().hex
|
||||
public_url = uuid.uuid4().hex
|
||||
|
||||
s = token.add_service('compute', id=service_id)
|
||||
s.add_endpoint('public', public_url, id=endpoint_id)
|
||||
s.add_endpoint('public', uuid.uuid4().hex)
|
||||
|
||||
auth_ref = access.create(body=token)
|
||||
|
||||
# initially assert that we get back all our urls for a simple filter
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_type='public')
|
||||
self.assertEqual(2, len(urls))
|
||||
|
||||
# with bad endpoint_id nothing should be found
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_id=uuid.uuid4().hex,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual(0, len(urls))
|
||||
|
||||
# with service_id we get back both public endpoints
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
service_id=service_id,
|
||||
endpoint_type='public')
|
||||
self.assertEqual(2, len(urls))
|
||||
|
||||
# with service_id and endpoint_id we get back the url we want
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
service_id=service_id,
|
||||
endpoint_id=endpoint_id,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual((public_url, ), urls)
|
||||
|
||||
# with service_id and endpoint_id we get back the url we want
|
||||
urls = auth_ref.service_catalog.get_urls(service_type='compute',
|
||||
endpoint_id=endpoint_id,
|
||||
endpoint_type='public')
|
||||
|
||||
self.assertEqual((public_url, ), urls)
|
||||
|
|
Loading…
Reference in New Issue