summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-09-07 18:55:24 -0500
committerGhe Rivero <ghe.rivero@hp.com>2015-09-15 10:21:23 +0200
commit15c6652dc4bfc5b417bb67df0435935962d71d9c (patch)
tree1e9b6b27e647eb9a486cef140e65fafd3447be7f
parent7a47fedbbe88cb3726f32b872f621e6a5407bdb5 (diff)
downloados-client-config-15c6652dc4bfc5b417bb67df0435935962d71d9c.tar.gz
Return keystoneauth plugins based on auth args
We know all of the things that we need to know to return an appropriate auth plugin from keystoneauth based on the auth parameters. This also introduces a hard-depend on keystoneauth, which should be fine since keystoneauth itself has a very low dependency count. We'll also use ksa to help validate auth parameters when we're doing the config processing. Change-Id: Ia1a1a4adb4dcefed5d7607082e026ca7361f394d
-rw-r--r--os_client_config/cloud_config.py16
-rw-r--r--requirements.txt1
2 files changed, 17 insertions, 0 deletions
diff --git a/os_client_config/cloud_config.py b/os_client_config/cloud_config.py
index f60303b..c9f9f07 100644
--- a/os_client_config/cloud_config.py
+++ b/os_client_config/cloud_config.py
@@ -14,6 +14,8 @@
import warnings
+from keystoneauth1 import loading
+
class CloudConfig(object):
def __init__(self, name, region, config, prefer_ipv6=False):
@@ -106,3 +108,17 @@ class CloudConfig(object):
@property
def prefer_ipv6(self):
return self._prefer_ipv6
+
+ def get_auth(self):
+ """Return a keystoneauth plugin from the auth credentials."""
+ # Re-use the admin_token plugin for the "None" plugin
+ # since it does not look up endpoints or tokens but rather
+ # does a passthrough. This is useful for things like Ironic
+ # that have a keystoneless operational mode, but means we're
+ # still dealing with a keystoneauth Session object, so all the
+ # _other_ things (SSL arg handling, timeout) all work consistently
+ if self.config['auth_type'] in (None, "None", ''):
+ self.config['auth_type'] = 'admin_token'
+ self.config['auth']['token'] = None
+ loader = loading.get_plugin_loader(self.config['auth_type'])
+ return loader.load_from_options(**self.config['auth'])
diff --git a/requirements.txt b/requirements.txt
index 894a70a..db0b635 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -3,3 +3,4 @@
# process, which may cause wedges in the gate later.
PyYAML>=3.1.0
appdirs>=1.3.0
+keystoneauth1>=1.0.0