Make discovery of version for KS catalog smarter.

Instead of relying on the configuration file for determining how
the catalog should be parsed, make it flexible by inspecting the
structure of the service catalog passed to it.

Fixes bug 1180486

Change-Id: I0c8caf4c8365bf25377ab3a249ac280d8add0f17
This commit is contained in:
Lin Hua Cheng 2013-05-15 12:45:34 -07:00
parent 13b8c8fdeb
commit 3fd58f9f14

View File

@ -180,9 +180,14 @@ def get_service_from_catalog(catalog, service_type):
return None
# TODO: Use API discovery to determine the version, for now read the settings
IDENTITY_VERSION = getattr(settings, APIVersionManager.SETTINGS_KEY, {}).\
get('identity', 2.0)
def get_version_from_service(service):
if service:
endpoint = service['endpoints'][0]
if 'interface' in endpoint:
return 3
else:
return 2.0
return 2.0
# Mapping of V2 Catalog Endpoint_type to V3 Catalog Interfaces
@ -199,11 +204,12 @@ def url_for(request, service_type, admin=False, endpoint_type=None):
'publicURL')
catalog = request.user.service_catalog
service = get_service_from_catalog(catalog, service_type)
identity_version = get_version_from_service(service)
if admin:
endpoint_type = 'adminURL'
if service:
try:
if IDENTITY_VERSION < 3:
if identity_version < 3:
return service['endpoints'][0][endpoint_type]
else:
interface = ENDPOINT_TYPE_TO_INTERFACE.get(endpoint_type, '')