diff options
| author | Jamie Lennox <jamielennox@redhat.com> | 2013-12-11 07:38:46 +1000 |
|---|---|---|
| committer | Jamie Lennox <jamielennox@redhat.com> | 2014-02-03 13:42:53 +1000 |
| commit | 1263bd7c3a8ccded3cef7c799a2f8c744fb79aa2 (patch) | |
| tree | a7c5a2a16174e2233246984c8d98afd518361cb6 /keystoneclient/client.py | |
| parent | 456afa153d0fd831686a50c19cc195da2820a6dd (diff) | |
| download | python-keystoneclient-1263bd7c3a8ccded3cef7c799a2f8c744fb79aa2.tar.gz | |
Provide a conversion function for creating session
Session.construct will create a session based upon the kwargs that used
to be passed to a client __init__ function. This will allow clients an
easy path to providing compatibility with deprecated arguments.
Make use of the function throughout discovery. Discovery was initially
released prior to the session object being completed and was therefore
handled with the same arguments as a client. Instead we should use a
session object so use the conversion function to convert those kwargs
into a session object if one is not provided.
Change-Id: I8dc1e0810ea6ebc6ea648ec37d7881825c566676
Diffstat (limited to 'keystoneclient/client.py')
| -rw-r--r-- | keystoneclient/client.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/keystoneclient/client.py b/keystoneclient/client.py index 832e3fa..cb9b76c 100644 --- a/keystoneclient/client.py +++ b/keystoneclient/client.py @@ -14,13 +14,14 @@ from keystoneclient import discover from keystoneclient import httpclient +from keystoneclient import session as client_session # Using client.HTTPClient is deprecated. Use httpclient.HTTPClient instead. HTTPClient = httpclient.HTTPClient -def Client(version=None, unstable=False, **kwargs): +def Client(version=None, unstable=False, session=None, **kwargs): """Factory function to create a new identity service client. :param tuple version: The required version of the identity API. If @@ -29,6 +30,9 @@ def Client(version=None, unstable=False, **kwargs): at least the specified minor version. For example to specify the 3.1 API use (3, 1). :param bool unstable: Accept endpoints not marked as 'stable'. (optional) + :param Session session: A session object to be used for communication. If + one is not provided it will be constructed from the + provided kwargs. (optional) :param kwargs: Additional arguments are passed through to the client that is being created. :returns: New keystone client object @@ -37,6 +41,8 @@ def Client(version=None, unstable=False, **kwargs): :raises: DiscoveryFailure if the server's response is invalid :raises: VersionNotAvailable if a suitable client cannot be found. """ + if not session: + session = client_session.Session.construct(kwargs) - return discover.Discover(**kwargs).create_client(version=version, - unstable=unstable) + d = discover.Discover(session=session, **kwargs) + return d.create_client(version=version, unstable=unstable) |
