Merge "Support regionless/global services"
This commit is contained in:
@@ -74,7 +74,7 @@ class ServiceCatalog(object):
|
||||
if not filtration.match_service_name(service.get('name')):
|
||||
continue
|
||||
for endpoint in service.get('endpoints', []):
|
||||
if not filtration.match_region(endpoint.get('region')):
|
||||
if not filtration.match_region(endpoint.get('region', None)):
|
||||
continue
|
||||
if not filtration.match_visibility(endpoint.get('interface')):
|
||||
continue
|
||||
@@ -136,6 +136,18 @@ class ServiceCatalog(object):
|
||||
|
||||
class ServiceCatalogV2(ServiceCatalog):
|
||||
"""The V2 service catalog from Keystone."""
|
||||
|
||||
def _extract_details(self, endpoint, interface):
|
||||
value = {
|
||||
'interface': interface,
|
||||
'url': endpoint['%sURL' % interface]
|
||||
}
|
||||
region = endpoint.get('region', None)
|
||||
if region:
|
||||
value['region'] = region
|
||||
|
||||
return value
|
||||
|
||||
def _normalize(self):
|
||||
"""Handle differences in the way v2 and v3 catalogs specify endpoints.
|
||||
|
||||
@@ -145,21 +157,9 @@ class ServiceCatalogV2(ServiceCatalog):
|
||||
eps = []
|
||||
for endpoint in service['endpoints']:
|
||||
if 'publicURL' in endpoint:
|
||||
eps += [{
|
||||
'interface': 'public',
|
||||
'region': endpoint['region'],
|
||||
'url': endpoint['publicURL'],
|
||||
}]
|
||||
eps += [self._extract_details(endpoint, "public")]
|
||||
if 'internalURL' in endpoint:
|
||||
eps += [{
|
||||
'interface': 'internal',
|
||||
'region': endpoint['region'],
|
||||
'url': endpoint['internalURL'],
|
||||
}]
|
||||
eps += [self._extract_details(endpoint, "internal")]
|
||||
if 'adminURL' in endpoint:
|
||||
eps += [{
|
||||
'interface': 'admin',
|
||||
'region': endpoint['region'],
|
||||
'url': endpoint['adminURL'],
|
||||
}]
|
||||
eps += [self._extract_details(endpoint, "admin")]
|
||||
service['endpoints'] = eps
|
||||
|
||||
@@ -27,6 +27,14 @@ TEST_USER_ID = 'youid'
|
||||
|
||||
TEST_SERVICE_CATALOG_V2 = [
|
||||
{
|
||||
"endpoints": [{
|
||||
"adminURL": "http://compute.region0.admin/v1.1/",
|
||||
"internalURL": "http://compute.region0.internal/v1.1/",
|
||||
"publicURL": "http://compute.region0.public/v1.1/",
|
||||
}],
|
||||
"type": "compute",
|
||||
"name": "nova0"
|
||||
}, {
|
||||
"endpoints": [{
|
||||
"adminURL": "http://compute.region2.admin/v1/",
|
||||
"region": "RegionTwo",
|
||||
@@ -74,6 +82,22 @@ TEST_SERVICE_CATALOG_V2 = [
|
||||
}]
|
||||
TEST_SERVICE_CATALOG_NORMALIZED = [
|
||||
{
|
||||
"endpoints": [{
|
||||
"interface": "public",
|
||||
"url": "http://compute.region0.public/%(version)s",
|
||||
'version': 'v1.1',
|
||||
}, {
|
||||
"interface": "internal",
|
||||
"url": "http://compute.region0.internal/%(version)s",
|
||||
'version': 'v1.1',
|
||||
}, {
|
||||
"interface": "admin",
|
||||
"url": "http://compute.region0.admin/%(version)s",
|
||||
'version': 'v1.1',
|
||||
}],
|
||||
"type": "compute",
|
||||
"name": "nova0"
|
||||
}, {
|
||||
"endpoints": [{
|
||||
"interface": "public",
|
||||
"region": "RegionTwo",
|
||||
@@ -185,6 +209,19 @@ TEST_RESPONSE_DICT_V2 = {
|
||||
|
||||
TEST_SERVICE_CATALOG_V3 = [
|
||||
{
|
||||
"endpoints": [{
|
||||
"url": "http://compute.region0.public/v1.1/",
|
||||
"interface": "public"
|
||||
}, {
|
||||
"url": "http://compute.region0.internal/v1.1/",
|
||||
"interface": "internal"
|
||||
}, {
|
||||
"url": "http://compute.region0.admin/v1.1/",
|
||||
"interface": "admin"
|
||||
}],
|
||||
"type": "compute",
|
||||
"name": "nova0",
|
||||
}, {
|
||||
"endpoints": [{
|
||||
"url": "http://compute.region2.public/v1/",
|
||||
"region": "RegionTwo",
|
||||
|
||||
@@ -26,7 +26,8 @@ from openstack.tests.auth import common
|
||||
class TestServiceCatalog(testtools.TestCase):
|
||||
def get_urls(self, sot):
|
||||
sf = service_filter.ServiceFilter(service_type='compute')
|
||||
exp = ["http://compute.region2.public/v1",
|
||||
exp = ["http://compute.region0.public/v1.1",
|
||||
"http://compute.region2.public/v1",
|
||||
"http://compute.region1.public/v2.0"]
|
||||
self.assertEqual(exp, sot.get_urls(sf))
|
||||
sf = service_filter.ServiceFilter(service_type='image')
|
||||
@@ -130,7 +131,7 @@ class TestServiceCatalogV3(TestServiceCatalog):
|
||||
def test_get_versions(self):
|
||||
sot = catalog.ServiceCatalog(common.TEST_SERVICE_CATALOG_V3)
|
||||
service = compute_service.ComputeService()
|
||||
self.assertEqual(['v1', 'v2.0'], sot.get_versions(service))
|
||||
self.assertEqual(['v1.1', 'v1', 'v2.0'], sot.get_versions(service))
|
||||
service = identity_service.IdentityService()
|
||||
self.assertEqual(['v1.1'], sot.get_versions(service))
|
||||
service = image_service.ImageService()
|
||||
|
||||
Reference in New Issue
Block a user