Fixed retrieval of freezer url from keystone catalog
fixed an incorrect placement for when to look for the fallback url which caused to look for FREEZER_API_URL even if it is present on the catalog. Change-Id: I171e80198e6cb91d056a7d3261a34a0f96b10eb4
This commit is contained in:
parent
c68c14d952
commit
018f308f43
|
@ -17,6 +17,7 @@
|
|||
import warnings
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
|
||||
from horizon.utils import functions as utils
|
||||
from horizon.utils.memoized import memoized # noqa
|
||||
|
@ -34,31 +35,34 @@ from freezer_ui.utils import create_dict_action
|
|||
from freezer_ui.utils import create_dummy_id
|
||||
from freezer_ui.utils import assign_value_from_source
|
||||
|
||||
@memoized
|
||||
def get_hardcoded_url():
|
||||
"""Get FREEZER_API_URL from local_settings.py"""
|
||||
try:
|
||||
warnings.warn(_('Using hardcoded FREEZER_API_URL at {0}')
|
||||
.format(settings.FREEZER_API_URL))
|
||||
return getattr(settings, 'FREEZER_API_URL', None)
|
||||
except (AttributeError, TypeError):
|
||||
warnings.warn(_('No FREEZER_API_URL was found in local_settings.py'))
|
||||
raise
|
||||
|
||||
|
||||
@memoized
|
||||
def get_service_url(request):
|
||||
"""Get Freezer API url from keystone catalog.
|
||||
"""Get Freezer API url from keystone catalog or local_settings.py
|
||||
if Freezer is not set in keystone, the fallback will be
|
||||
'FREEZER_API_URL' in local_settings.py
|
||||
"""
|
||||
url = None
|
||||
|
||||
catalog = (getattr(request.user, "service_catalog", None))
|
||||
if not catalog:
|
||||
warnings.warn('Using hardcoded FREEZER_API_URL at {0}'
|
||||
.format(settings.FREEZER_API_URL))
|
||||
return getattr(settings, 'FREEZER_API_URL', None)
|
||||
return get_hardcoded_url()
|
||||
|
||||
for c in catalog:
|
||||
if c['name'] == 'freezer':
|
||||
for e in c['endpoints']:
|
||||
url = e['publicURL']
|
||||
else:
|
||||
warnings.warn('Using hardcoded FREEZER_API_URL at {0}'
|
||||
.format(settings.FREEZER_API_URL))
|
||||
return getattr(settings, 'FREEZER_API_URL', None)
|
||||
|
||||
return url
|
||||
return e['publicURL']
|
||||
else:
|
||||
return get_hardcoded_url()
|
||||
|
||||
|
||||
@memoized
|
||||
|
|
Loading…
Reference in New Issue