summaryrefslogtreecommitdiff
path: root/glanceclient/client.py
diff options
context:
space:
mode:
authorJamie Lennox <jamielennox@redhat.com>2014-11-25 13:25:12 +1000
committerFlavio Percoco <fpercoco@redhat.com>2015-06-11 13:11:56 +0000
commit5ce9c7dc964be0b3e8f9f273169b77ada85cd8ec (patch)
treec02ac042c63cb3f474c32bd56677d15188ea451e /glanceclient/client.py
parentdb6420b44779411d6d1f238f6b887f83f1988986 (diff)
downloadpython-glanceclient-5ce9c7dc964be0b3e8f9f273169b77ada85cd8ec.tar.gz
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
Diffstat (limited to 'glanceclient/client.py')
-rw-r--r--glanceclient/client.py55
1 files changed, 34 insertions, 21 deletions
diff --git a/glanceclient/client.py b/glanceclient/client.py
index 4c1e7b8..db2a4f7 100644
--- a/glanceclient/client.py
+++ b/glanceclient/client.py
@@ -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)
-
- endpoint, url_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)
-
- version = int(version or url_version)
-
- module = utils.import_versioned_module(version, 'client')
+ # 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)
+
+ if not version:
+ __, version = utils.strip_version(endpoint)
+
+ if not version:
+ msg = ("You must provide a client version when using session")
+ raise RuntimeError(msg)
+
+ 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)
+
+ 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)