diff options
author | Monty Taylor <mordred@inaugust.com> | 2015-11-05 17:00:33 -0500 |
---|---|---|
committer | Monty Taylor <mordred@inaugust.com> | 2015-11-05 17:08:50 -0500 |
commit | 2339243e66b676325c84693e7f8199d476199203 (patch) | |
tree | 13d6d8abeb02d74a2289a04753d598e57fb1e1d3 /os_client_config/cloud_config.py | |
parent | 1b91e007fdeda8703056d50abe431e167afb9e03 (diff) | |
download | os-client-config-2339243e66b676325c84693e7f8199d476199203.tar.gz |
Add method to get a mounted session from config
Getting a session is great, but sometimes you need a thing called
an "adapter" which takes 5 parameters which are all already contained in
the config that you used to get the session.
Change-Id: Id4e418cd04ae81540d9898f7b2e959b974f355d2
Diffstat (limited to 'os_client_config/cloud_config.py')
-rw-r--r-- | os_client_config/cloud_config.py | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py index 8e0b963..7cab1ac 100644 --- a/os_client_config/cloud_config.py +++ b/os_client_config/cloud_config.py @@ -14,6 +14,7 @@ import warnings +from keystoneauth1 import adapter from keystoneauth1 import plugin from keystoneauth1 import session @@ -160,6 +161,28 @@ class CloudConfig(object): timeout=self.config['api_timeout']) return self._keystone_session + def get_session_client(self, service_key): + """Return a prepped requests adapter for a given service. + + This is useful for making direct requests calls against a + 'mounted' endpoint. That is, if you do: + + client = get_session_client('compute') + + then you can do: + + client.get('/flavors') + + and it will work like you think. + """ + + return adapter.Adapter( + session=self.get_session(), + service_type=self.get_service_type(service_key), + service_name=self.get_service_name(service_key), + interface=self.get_interface(service_key), + region_name=self.region) + def get_session_endpoint(self, service_key): """Return the endpoint from config or the catalog. |