From decc7517b4757b49fa20a63307c0d1bb3e730803 Mon Sep 17 00:00:00 2001 From: memo Date: Wed, 14 Oct 2015 16:33:06 +0100 Subject: [PATCH] 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 --- freezer_ui/api/api.py | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/freezer_ui/api/api.py b/freezer_ui/api/api.py index cf752b1..20abca2 100644 --- a/freezer_ui/api/api.py +++ b/freezer_ui/api/api.py @@ -17,11 +17,11 @@ 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 - import freezer.apiclient.client from freezer_ui.utils import Action from freezer_ui.utils import ActionJob @@ -35,30 +35,34 @@ 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