Skip to content

Commit

Permalink
Cache OS_CLOUD on import
Browse files Browse the repository at this point in the history
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: openstack/os-client-config@990cfa3
  • Loading branch information
cybertron committed Jun 5, 2017
1 parent 1bef041 commit 857b532
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 8 additions & 3 deletions openstack_virtual_baremetal/auth.py
Expand Up @@ -19,6 +19,12 @@
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
Expand Down Expand Up @@ -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']
Expand Down
6 changes: 3 additions & 3 deletions openstack_virtual_baremetal/deploy.py
Expand Up @@ -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)
Expand Down

0 comments on commit 857b532

Please sign in to comment.