summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2016-09-01 18:08:15 -0500
committerMonty Taylor <mordred@inaugust.com>2016-09-01 18:08:15 -0500
commit86b100e400ad9dbda018d4be7f97ce4582737fe7 (patch)
tree2b514ae0edc5f44b01f368016a9f3df170171450
parent42885dc94176eecca1619d7e9c33b5ab3d9a2c0a (diff)
downloados-client-config-86b100e400ad9dbda018d4be7f97ce4582737fe7.tar.gz
Add ability to configure Session constructor
Sometimes it's useful to wrapp the keystoneauth.Session object. OSC has a KeystoneSession object that injects timing data. shade is considering one that wraps external calls in shade's TaskManager. Allow for passing in a callable that will return a Session. Almost no people will want to use this - it's a super advanced kind of thing. Change-Id: Ib64260916695e9fbea437862cd669a4fb85ec9e4
-rw-r--r--os_client_config/cloud_config.py5
-rw-r--r--os_client_config/config.py6
2 files changed, 7 insertions, 4 deletions
diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py
index 1846f54..ae5da3a 100644
--- a/os_client_config/cloud_config.py
+++ b/os_client_config/cloud_config.py
@@ -70,7 +70,7 @@ def _make_key(key, service_type):
class CloudConfig(object):
def __init__(self, name, region, config,
force_ipv4=False, auth_plugin=None,
- openstack_config=None):
+ openstack_config=None, session_constructor=None):
self.name = name
self.region = region
self.config = config
@@ -79,6 +79,7 @@ class CloudConfig(object):
self._auth = auth_plugin
self._openstack_config = openstack_config
self._keystone_session = None
+ self._session_constructor = session_constructor or session.Session
def __getattr__(self, key):
"""Return arbitrary attributes."""
@@ -196,7 +197,7 @@ class CloudConfig(object):
" since verify=False".format(
cloud=self.name, region=self.region))
requestsexceptions.squelch_warnings(insecure_requests=not verify)
- self._keystone_session = session.Session(
+ self._keystone_session = self._session_constructor(
auth=self._auth,
verify=verify,
cert=cert,
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 6eed0f0..0c11230 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -174,8 +174,9 @@ class OpenStackConfig(object):
def __init__(self, config_files=None, vendor_files=None,
override_defaults=None, force_ipv4=None,
envvar_prefix=None, secure_files=None,
- pw_func=None):
+ pw_func=None, session_constructor=None):
self.log = _log.setup_logging(__name__)
+ self._session_constructor = session_constructor
self._config_files = config_files or CONFIG_FILES
self._secure_files = secure_files or SECURE_FILES
@@ -1127,7 +1128,8 @@ class OpenStackConfig(object):
config=self._normalize_keys(config),
force_ipv4=force_ipv4,
auth_plugin=auth_plugin,
- openstack_config=self
+ openstack_config=self,
+ session_constructor=self._session_constructor,
)
def get_one_cloud_osc(