Init smaug client for smaug-dashboard
We will change it to python-smaugclient after the requirements patch has been merged. https://review.openstack.org/#/c/302512/ This patch may take some time because it is the release time of OpenStack now. But we could use the python-smaugclient master to avoid the CI error in development. Change-Id: Ic04ff306752d70766a86f319c3d006264362545c Closes-Bug: #1557889
This commit is contained in:
parent
b1b787097a
commit
022e40c846
|
@ -0,0 +1,55 @@
|
|||
# Copyright (c) 2016 Huawei, Inc.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
# not use this file except in compliance with the License. You may obtain
|
||||
# a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
from __future__ import absolute_import
|
||||
import logging
|
||||
import six.moves.urllib.parse as urlparse
|
||||
|
||||
from django.conf import settings
|
||||
from horizon import exceptions
|
||||
from horizon.utils.memoized import memoized
|
||||
from openstack_dashboard.api import base
|
||||
from smaugclient.v1 import client as smaug_client
|
||||
|
||||
LOG = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_smaug_endpoint(request):
|
||||
endpoint = ""
|
||||
try:
|
||||
endpoint = base.url_for(request, "data-protect")
|
||||
parts = urlparse.urlparse(endpoint)
|
||||
if parts.scheme and parts.netloc:
|
||||
endpoint = '%s://%s' % (parts.scheme, parts.netloc)
|
||||
except exceptions.ServiceCatalogException:
|
||||
endpoint = 'http://localhost:8799'
|
||||
LOG.warning('Smaug API location could not be found in Service '
|
||||
'Catalog, using default: {0}'.format(endpoint))
|
||||
return endpoint
|
||||
|
||||
|
||||
@memoized
|
||||
def smaugclient(request):
|
||||
endpoint = get_smaug_endpoint(request)
|
||||
LOG.debug('smaugclient connection created using the token "%s" and url'
|
||||
'"%s"' % (request.user.token.id, endpoint))
|
||||
c = smaug_client.Client(endpoint=endpoint,
|
||||
auth_url=getattr(settings,
|
||||
'OPENSTACK_KEYSTONE_URL'),
|
||||
token=request.user.token.id,
|
||||
username=request.user.username,
|
||||
project_id=request.user.tenant_id,
|
||||
auth_plugin='token',
|
||||
)
|
||||
return c
|
|
@ -26,3 +26,8 @@ testtools>=1.4.0 # MIT
|
|||
xvfbwrapper>=0.1.3 #license: MIT
|
||||
# Include horizon as test requirement
|
||||
http://tarballs.openstack.org/horizon/horizon-master.tar.gz#egg=horizon
|
||||
# We will change it to python-smaugclient after the requirements patch has been merged.
|
||||
# https://review.openstack.org/#/c/302512/
|
||||
# This patch may take some time because it is the release time of OpenStack now.
|
||||
# But we could use the python-smaugclient master to avoid the CI error in development.
|
||||
http://tarballs.openstack.org/python-smaugclient/python-smaugclient-master.tar.gz#egg=python-smaugclient
|
||||
|
|
Loading…
Reference in New Issue