Using a smarter way to get freezer-api URL

By priority:
    - Getting it from the FREEZER_API_URL parameter in the enabled file
    - Getting it from keystone with the provided endpoint type
    - Getting it from keystone with the 'internal' endpoint type
    - Getting it from keystone with the 'public' endpoint type

Resolves bug: 1541933

Change-Id: I7c369ca192f9c3acf551270382abb2bf231abb38
This commit is contained in:
Pierre-Arthur MATHIEU 2016-02-03 16:24:39 +00:00
parent 5bac281fcc
commit da9cbb1968
1 changed files with 19 additions and 22 deletions

View File

@ -53,30 +53,27 @@ def client(request):
@memoized
def _get_service_url(request):
"""Get freezer api url"""
catalog = (getattr(request.user, "service_catalog", None))
if not catalog:
return _get_hardcoded_url()
hardcoded_url = getattr(settings, 'FREEZER_API_URL', None)
if hardcoded_url is not None:
LOG.warn('Using hardcoded FREEZER_API_URL: {0}'.format(hardcoded_url))
return hardcoded_url
for c in catalog:
if c['name'] == 'freezer':
for e in c['endpoints']:
return e['internalURL']
else:
return _get_hardcoded_url()
e_type = getattr(settings, 'OPENSTACK_ENDPOINT_TYPE', '')
endpoint_type_priority = [e_type, ['internal', 'internalURL'], ['public',
'publicURL']]
@memoized
def _get_hardcoded_url():
"""In case freezer is not registered in keystone catalog, look for it in
local_settings.py
:return: freezer_api_url
"""
try:
LOG.warn('Using hardcoded FREEZER_API_URL at {0}'
.format(settings.FREEZER_API_URL))
return getattr(settings, 'FREEZER_API_URL', None)
catalog = (getattr(request.user, "service_catalog", []))
for c in catalog:
if c['name'] == 'freezer':
for endpoint_type in endpoint_type_priority:
for e in c['endpoints']:
if e['interface'] in endpoint_type:
return e['url']
raise ValueError('Could no get FREEZER_API_URL from config'
' or Keystone')
except Exception:
LOG.warn('No FREEZER_API_URL was found in local_settings.py')
LOG.warn('Could no get FREEZER_API_URL from config or Keystone')
raise
@ -351,8 +348,8 @@ class Action(object):
action.get('action_id'),
action['freezer_action'].get('action'),
action['freezer_action'].get('backup_name'),
action['freezer_action'].get('path_to_backup')
or action['freezer_action'].get('restore_abs_path'),
action['freezer_action'].get('path_to_backup') or
action['freezer_action'].get('restore_abs_path'),
action['freezer_action'].get('storage'),
mode=action['freezer_action'].get('mode')
) for action in actions]