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
This commit is contained in:
Xing Zhang 2017-09-01 15:52:33 +08:00
parent a51944b2b4
commit aeee17c10c

View File

@ -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