From aeee17c10cc506d368c45ebfffac29e078841aac Mon Sep 17 00:00:00 2001 From: Xing Zhang Date: Fri, 1 Sep 2017 15:52:33 +0800 Subject: [PATCH] Update and refactor zunclient I do two things on this patch: [1] update params in zunclient [2] refactor params in zunclient by usingi memoized_with_request python-zunclient v1 api refactor client and remove or rename parameters: removed zun_url by using endpoint_override instead input_auth_token was renamed to auth_token and zun-ui was using the old params, listing images and containers on horizon will raise error like: MissingRequiredOptions: Auth plugin requires parameters which were not given: auth_url Change-Id: I6e54981057bad877317ca19d049b8b071394f556 Depends-On: Ie9be389495e2f13454f1f8d1c1d66b22d813a9ec --- zun_ui/api/client.py | 39 +++++++++++++++++++++++++++++---------- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/zun_ui/api/client.py b/zun_ui/api/client.py index 737faa1..afb42aa 100644 --- a/zun_ui/api/client.py +++ b/zun_ui/api/client.py @@ -12,7 +12,7 @@ from horizon import exceptions -from horizon.utils.memoized import memoized +from horizon.utils.memoized import memoized_with_request import logging from openstack_dashboard.api import base from zunclient.common import utils @@ -25,21 +25,40 @@ CONTAINER_CREATE_ATTRS = zun_client.containers.CREATION_ATTRIBUTES IMAGE_PULL_ATTRS = zun_client.images.PULL_ATTRIBUTES -@memoized -def zunclient(request): - zun_url = "" +def get_auth_params_from_request(request): + """Extracts properties needed by zunclient call from the request object. + + These will be used to memoize the calls to zunclient. + """ + endpoint_override = "" try: - zun_url = base.url_for(request, 'container') + endpoint_override = base.url_for(request, 'container') except exceptions.ServiceCatalogException: LOG.debug('No Container Management service is configured.') return None + return ( + request.user.username, + request.user.token.id, + request.user.tenant_id, + endpoint_override + ) + + +@memoized_with_request(get_auth_params_from_request) +def zunclient(request_auth_params): + ( + username, + token_id, + project_id, + endpoint_override + ) = request_auth_params LOG.debug('zunclient connection created using the token "%s" and url' - '"%s"' % (request.user.token.id, zun_url)) - c = zun_client.Client(username=request.user.username, - project_id=request.user.tenant_id, - input_auth_token=request.user.token.id, - zun_url=zun_url) + ' "%s"' % (token_id, endpoint_override)) + c = zun_client.Client(username=username, + project_id=project_id, + auth_token=token_id, + endpoint_override=endpoint_override) return c