diff options
| author | Andrey Kurilin <akurilin@mirantis.com> | 2016-06-17 14:45:55 +0300 |
|---|---|---|
| committer | Andrey Kurilin <akurilin@mirantis.com> | 2016-12-16 12:56:10 +0000 |
| commit | 8409e006c5f362922baae9470f14c12e0443dd70 (patch) | |
| tree | 175aa7894263b9ec865597389f0cf7e037e48ba8 /novaclient/client.py | |
| parent | e4dc84e0f6ebaefeed114d4ac1663d35730629a4 (diff) | |
| download | python-novaclient-8409e006c5f362922baae9470f14c12e0443dd70.tar.gz | |
Create keystone session instance if not present
Since all authentication plugins should be stored in Keystone, there is no
need to share responsibility for authentication stuff with Keystone team.
Let's use convinient and the right way to use keystone - keystone sessions.
We have own adapter for it - novaclient.client.Session which can be used in
100% cases of novaclient usage. Let's create session object if it is not
transmitted via arguments and get rid of novaclient.client.HTTPClient
implementation.
NOTE: novaclient.client.HTTPClient and all related code will be removed
separately.
Co-Authored-By: Clenimar Filemon <clenimar@lsd.ufcg.edu.br>
Change-Id: Ibb99fdafbf02b3e92f1a5d04d168151b3400b901
Diffstat (limited to 'novaclient/client.py')
| -rw-r--r-- | novaclient/client.py | 82 |
1 files changed, 37 insertions, 45 deletions
diff --git a/novaclient/client.py b/novaclient/client.py index 8a840afc..7780c9a6 100644 --- a/novaclient/client.py +++ b/novaclient/client.py @@ -30,7 +30,8 @@ import re import warnings from keystoneauth1 import adapter -from keystoneauth1 import session +from keystoneauth1 import identity +from keystoneauth1 import session as ksession from oslo_utils import importutils from oslo_utils import netutils import pkg_resources @@ -65,7 +66,7 @@ class _ClientConnectionPool(object): def get(self, url): """Store and reuse HTTP adapters per Service URL.""" if url not in self._adapters: - self._adapters[url] = session.TCPKeepAliveAdapter() + self._adapters[url] = ksession.TCPKeepAliveAdapter() return self._adapters[url] @@ -705,6 +706,7 @@ def _construct_http_client(api_version=None, endpoint_type='publicURL', http_log_debug=False, insecure=False, + logger=None, os_cache=False, password=None, project_domain_id=None, @@ -724,49 +726,39 @@ def _construct_http_client(api_version=None, username=None, volume_service_name=None, **kwargs): - # TODO(mordred): If not session, just make a Session, then return - # SessionClient always - if session: - return SessionClient(api_version=api_version, - auth=auth, - endpoint_override=endpoint_override, - interface=endpoint_type, - region_name=region_name, - service_name=service_name, - service_type=service_type, - session=session, - timings=timings, - user_agent=user_agent, - **kwargs) - else: - # FIXME(jamielennox): username and password are now optional. Need - # to test that they were provided in this mode. - logger = kwargs.get('logger') - return HTTPClient(username, - password, - user_id=user_id, - # NOTE(andreykurilin): HTTPClient will be replaced - # fully by SessionClient soon, so there are no - # reasons to spend time renaming projectid variable - # to tenant_name/project_name. - projectid=project_name, - tenant_id=project_id, - auth_url=auth_url, - auth_token=auth_token, - insecure=insecure, - timeout=timeout, - region_name=region_name, - endpoint_type=endpoint_type, - service_type=service_type, - service_name=service_name, - volume_service_name=volume_service_name, - timings=timings, - bypass_url=endpoint_override, - os_cache=os_cache, - http_log_debug=http_log_debug, - cacert=cacert, - api_version=api_version, - logger=logger) + if not session: + if not auth and auth_token: + auth = identity.Token(auth_url=auth_url, + token=auth_token) + elif not auth: + auth = identity.Password(username=username, + user_id=user_id, + password=password, + project_id=project_id, + project_name=project_name, + auth_url=auth_url, + project_domain_id=project_domain_id, + project_domain_name=project_domain_name, + user_domain_id=user_domain_id, + user_domain_name=user_domain_name) + session = ksession.Session(auth=auth, + verify=(cacert or not insecure), + timeout=timeout, + cert=cert, + user_agent=user_agent) + + return SessionClient(api_version=api_version, + auth=auth, + endpoint_override=endpoint_override, + interface=endpoint_type, + logger=logger, + region_name=region_name, + service_name=service_name, + service_type=service_type, + session=session, + timings=timings, + user_agent=user_agent, + **kwargs) def discover_extensions(version, only_contrib=False): |
