summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-09-30 17:27:22 -0400
committerMonty Taylor <mordred@inaugust.com>2015-09-30 17:27:22 -0400
commit723b893f22fc3db74761dc64e5296360e5739147 (patch)
treedec4f880bd17583b9d2d6015843a0c6435e46ba8
parent79637b12cfebb3ab80c781b1217755832ab069c4 (diff)
downloados-client-config-723b893f22fc3db74761dc64e5296360e5739147.tar.gz
Handle OS_CLOUD and OS_REGION_NAME friendly-like
If you're using os-client-config and ansible and python-openstackclient, the envvar override support can get tricky if you've set OS_CLOUD to select a cloud for python-openstackclient, leading you to have an empty cloud called envvars when you were not actually trying to create one. Special-case pull both out, treating OS_CLOUD as a default value for get_one_cloud() and only creating an envvars cloud if OS_REGION_NAME is not the only env var provided. Change-Id: I2a5235c18f9be1e5dfc019888a0c187ef40074bc
-rw-r--r--os_client_config/config.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index fcca30a..2cea7ee 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -86,7 +86,10 @@ def _get_os_environ():
and not k.startswith('OS_TEST') # infra CI var
and not k.startswith('OS_STD') # infra CI var
]
- if not environkeys:
+ # If the only environ key is region name, don't make a cloud, because
+ # it's being used as a cloud selector
+ if not environkeys or (
+ len(environkeys) == 1 and 'OS_REGION_NAME' in environkeys):
return None
for k in environkeys:
newkey = k[3:].lower()
@@ -147,6 +150,9 @@ class OpenStackConfig(object):
' either your environment based cloud, or one of your'
' file-based clouds.'.format(self.config_filename,
self.envvar_key))
+ # Pull out OS_CLOUD so that if it's the only thing set, do not
+ # make an envvars cloud
+ self.default_cloud = os.environ.pop('OS_CLOUD', None)
envvars = _get_os_environ()
if envvars:
@@ -523,6 +529,9 @@ class OpenStackConfig(object):
on missing required auth parameters
"""
+ if cloud is None and self.default_cloud:
+ cloud = self.default_cloud
+
if cloud is None and self.envvar_key in self.get_cloud_names():
cloud = self.envvar_key