Cache OS_CLOUD on import

Older versions of os-client-config pop OS_CLOUD from the environment
when make_client is called.  This has been fixed in [1], but to
support older versions as well, let's cache it on import so even if
someone messes with os.environ later we still have the right value.

1: 990cfa3ce2
This commit is contained in:
Ben Nemec 2017-06-05 13:04:38 -05:00
parent 1bef041283
commit 857b532d21
2 changed files with 11 additions and 6 deletions

View File

@ -19,6 +19,12 @@ from keystoneclient.v2_0 import client as keystone_client
from keystoneclient.v3 import client as keystone_v3_client
# Older versions of os-client-config pop this from the environment when
# make_client is called. Cache it on import so we know what the original
# value was, regardless of any funny business that happens later.
OS_CLOUD = os.environ.get('OS_CLOUD')
def _validate_auth_parameters(username, password, tenant, auth_url,
project, user_domain, project_domain):
"""Validate that the necessary auth parameters are set
@ -50,10 +56,9 @@ def _create_auth_parameters():
os_tenant, os_auth_url, os_project, os_user_domain,
os_project_domain.
"""
cloud = os.environ.get('OS_CLOUD')
if cloud:
if OS_CLOUD:
import os_client_config
config = os_client_config.OpenStackConfig().get_one_cloud(cloud)
config = os_client_config.OpenStackConfig().get_one_cloud(OS_CLOUD)
auth = config.config['auth']
username = auth['username']
password = auth['password']

View File

@ -135,10 +135,10 @@ def _validate_env(args, env_path):
'different baremetal_prefix or role name.')
def _get_heat_client():
cloud = os.environ.get('OS_CLOUD')
if cloud:
if auth.OS_CLOUD:
import os_client_config
return os_client_config.make_client('orchestration', cloud=cloud)
return os_client_config.make_client('orchestration',
cloud=auth.OS_CLOUD)
else:
token_id, heat_endpoint = auth._get_token_and_endpoint('heat')
return heat_client.Client('1', endpoint=heat_endpoint, token=token_id)