Merge "swift driver: rely on keystone session for swift connection"

This commit is contained in:
Jenkins 2017-04-13 06:45:22 +00:00 committed by Gerrit Code Review
commit 2c08b34369

View File

@ -88,13 +88,10 @@ class _ClientWrapper(object):
def __init__(self, conf): def __init__(self, conf):
self.conf = conf self.conf = conf
self.parsed_url = urllib.parse.urlparse(conf.uri) self.parsed_url = urllib.parse.urlparse(conf.uri)
self.token = None
self.url = None
self.session = None self.session = None
self.auth = None
def _refresh_auth(self): def _init_auth(self):
self.auth = generic.Password( auth = generic.Password(
username=self.parsed_url.username, username=self.parsed_url.username,
password=self.parsed_url.password, password=self.parsed_url.password,
project_name=self.parsed_url.path[1:], project_name=self.parsed_url.path[1:],
@ -103,18 +100,11 @@ class _ClientWrapper(object):
project_domain_id=self.conf.project_domain_id, project_domain_id=self.conf.project_domain_id,
project_domain_name=self.conf.project_domain_name, project_domain_name=self.conf.project_domain_name,
auth_url=self.conf.auth_url) auth_url=self.conf.auth_url)
self.session = keystone_session.Session(auth=self.auth) self.session = keystone_session.Session(auth=auth)
self.url = self.session.get_endpoint(service_type='object-store')
self.token = self.session.get_token()
def __getattr__(self, attr): def __getattr__(self, attr):
# This part is not thread-safe, but the worst case is having a bunch of if self.session is None:
# useless auth calls, so it should be okay. self._init_auth()
if (self.auth is None or client = swiftclient.Connection(session=self.session,
self.auth.get_auth_ref(self.session).will_expire_soon()): insecure=self.conf.insecure)
self._refresh_auth()
client = swiftclient.Connection(
preauthurl=self.url,
preauthtoken=self.token,
insecure=self.conf.insecure)
return getattr(client, attr) return getattr(client, attr)