Make glanceclient accept a session object

To make this work we create a different HTTPClient that extends the
basic keystoneclient Adapter. The Adapter is a standard set of
parameters that all clients should know how to use like region_name and
user_agent. We extend this with the glance specific response
manipulation like loading and sending iterables.

Implements: bp session-objects
Change-Id: Ie8eb4bbf7d1a037099a6d4b272cab70525fbfc85
This commit is contained in:
Jamie Lennox
2014-11-25 13:25:12 +10:00
committed by Flavio Percoco
parent db6420b447
commit 5ce9c7dc96
7 changed files with 205 additions and 93 deletions
+30 -17
View File
@@ -18,31 +18,44 @@ import warnings
from glanceclient.common import utils
def Client(version=None, endpoint=None, *args, **kwargs):
def Client(version=None, endpoint=None, session=None, *args, **kwargs):
"""Client for the OpenStack Images API.
Generic client for the OpenStack Images API. See version classes
for specific details.
:param string version: The version of API to use. Note this is
deprecated and should be passed as part of the URL
(http://$HOST:$PORT/v$VERSION_NUMBER).
:param string version: The version of API to use.
:param session: A keystoneclient session that should be used for transport.
:type session: keystoneclient.session.Session
"""
if version is not None:
warnings.warn(("`version` keyword is being deprecated. Please pass the"
" version as part of the URL. "
"http://$HOST:$PORT/v$VERSION_NUMBER"),
DeprecationWarning)
# FIXME(jamielennox): Add a deprecation warning if no session is passed.
# Leaving it as an option until we can ensure nothing break when we switch.
if session:
if endpoint:
kwargs.setdefault('endpoint_override', endpoint)
endpoint, url_version = utils.strip_version(endpoint)
if not version:
__, version = utils.strip_version(endpoint)
if not url_version and not version:
msg = ("Please provide either the version or an url with the form "
"http://$HOST:$PORT/v$VERSION_NUMBER")
raise RuntimeError(msg)
if not version:
msg = ("You must provide a client version when using session")
raise RuntimeError(msg)
version = int(version or url_version)
else:
if version is not None:
warnings.warn(("`version` keyword is being deprecated. Please pass"
" the version as part of the URL. "
"http://$HOST:$PORT/v$VERSION_NUMBER"),
DeprecationWarning)
module = utils.import_versioned_module(version, 'client')
endpoint, url_version = utils.strip_version(endpoint)
version = version or url_version
if not version:
msg = ("Please provide either the version or an url with the form "
"http://$HOST:$PORT/v$VERSION_NUMBER")
raise RuntimeError(msg)
module = utils.import_versioned_module(int(version), 'client')
client_class = getattr(module, 'Client')
return client_class(endpoint, *args, **kwargs)
return client_class(endpoint, *args, session=session, **kwargs)