deb-sahara/sahara/swift/utils.py
Sergey Reshetnyak 4eade5480e Use keystone service catalog for getting auth urls
Co-Authored-By: Andrey Pavlov <apavlov@mirantis.com>

Change-Id: I6c64f4b975d12ccaca564d248f9ccbb02615e19f
Closes-bug: #1371856
2015-07-21 16:53:50 +03:00

63 lines
2.0 KiB
Python

# Copyright (c) 2013 Red Hat, 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 oslo_config import cfg
import six
from six.moves.urllib import parse as urlparse
from sahara.utils.openstack import base as clients_base
CONF = cfg.CONF
SWIFT_INTERNAL_PREFIX = "swift://"
SWIFT_URL_SUFFIX_START = '.'
SWIFT_URL_SUFFIX = SWIFT_URL_SUFFIX_START + 'sahara'
def retrieve_auth_url():
"""This function returns auth url v2.0 api.
Hadoop Swift library doesn't support keystone v3 api.
"""
auth_url = clients_base.retrieve_auth_url()
info = urlparse.urlparse(auth_url)
if CONF.use_domain_for_proxy_users:
url = 'v3/auth'
else:
url = 'v2.0'
if info.port:
returned_url = '{scheme}://{hostname}:{port}/{url}/'
return returned_url.format(scheme=info.scheme,
hostname=info.hostname,
port=info.port,
url=url)
else:
return '{scheme}://{hostname}/{url}/'.format(scheme=info.scheme,
hostname=info.hostname,
url=url)
def inject_swift_url_suffix(url):
if isinstance(url, six.string_types) and url.startswith("swift://"):
u = urlparse.urlparse(url)
if not u.netloc.endswith(SWIFT_URL_SUFFIX):
return url.replace(u.netloc,
u.netloc + SWIFT_URL_SUFFIX, 1)
return url