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:
@@ -53,30 +53,27 @@ def client(request):
|
|||||||
@memoized
|
@memoized
|
||||||
def _get_service_url(request):
|
def _get_service_url(request):
|
||||||
"""Get freezer api url"""
|
"""Get freezer api url"""
|
||||||
catalog = (getattr(request.user, "service_catalog", None))
|
hardcoded_url = getattr(settings, 'FREEZER_API_URL', None)
|
||||||
if not catalog:
|
if hardcoded_url is not None:
|
||||||
return _get_hardcoded_url()
|
LOG.warn('Using hardcoded FREEZER_API_URL: {0}'.format(hardcoded_url))
|
||||||
|
return hardcoded_url
|
||||||
|
|
||||||
|
e_type = getattr(settings, 'OPENSTACK_ENDPOINT_TYPE', '')
|
||||||
|
endpoint_type_priority = [e_type, ['internal', 'internalURL'], ['public',
|
||||||
|
'publicURL']]
|
||||||
|
|
||||||
|
try:
|
||||||
|
catalog = (getattr(request.user, "service_catalog", []))
|
||||||
for c in catalog:
|
for c in catalog:
|
||||||
if c['name'] == 'freezer':
|
if c['name'] == 'freezer':
|
||||||
|
for endpoint_type in endpoint_type_priority:
|
||||||
for e in c['endpoints']:
|
for e in c['endpoints']:
|
||||||
return e['internalURL']
|
if e['interface'] in endpoint_type:
|
||||||
else:
|
return e['url']
|
||||||
return _get_hardcoded_url()
|
raise ValueError('Could no get FREEZER_API_URL from config'
|
||||||
|
' or Keystone')
|
||||||
|
|
||||||
@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)
|
|
||||||
except Exception:
|
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
|
raise
|
||||||
|
|
||||||
|
|
||||||
@@ -351,8 +348,8 @@ class Action(object):
|
|||||||
action.get('action_id'),
|
action.get('action_id'),
|
||||||
action['freezer_action'].get('action'),
|
action['freezer_action'].get('action'),
|
||||||
action['freezer_action'].get('backup_name'),
|
action['freezer_action'].get('backup_name'),
|
||||||
action['freezer_action'].get('path_to_backup')
|
action['freezer_action'].get('path_to_backup') or
|
||||||
or action['freezer_action'].get('restore_abs_path'),
|
action['freezer_action'].get('restore_abs_path'),
|
||||||
action['freezer_action'].get('storage'),
|
action['freezer_action'].get('storage'),
|
||||||
mode=action['freezer_action'].get('mode')
|
mode=action['freezer_action'].get('mode')
|
||||||
) for action in actions]
|
) for action in actions]
|
||||||
|
Reference in New Issue
Block a user