summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDean Troyer <dtroyer@gmail.com>2014-09-22 19:54:57 -0500
committerDean Troyer <dtroyer@gmail.com>2014-09-23 10:44:05 -0500
commit2c2a2953771d6599cbb3b65500c1f55eb44cafe9 (patch)
treebf8c663e3ef6dbcefd42f67959b05f9a60e2361f
parentcb9e5059f6f9557fc9d62e12f4237719fb172e64 (diff)
downloados-client-config-2c2a2953771d6599cbb3b65500c1f55eb44cafe9.tar.gz
Add clouds-public.yaml
Put vendor config outside of the code in clouds-public.yaml. Fall back to vendors.py if clouds-public.yaml not found. The search follows the same rules as clouds.yaml, the file is the same format except the top-level key is 'public-clouds'. Typically only auth_url and region_name are populated.
-rw-r--r--os_client_config/config.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 56992df..6612bff 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -30,6 +30,9 @@ CONFIG_FILES = [
os.path.join(d, 'clouds.yaml') for d in CONFIG_SEARCH_PATH]
BOOL_KEYS = ('insecure', 'cache')
REQUIRED_VALUES = ('auth_url', 'username', 'password', 'project_id')
+VENDOR_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack']
+VENDOR_FILES = [
+ os.path.join(d, 'clouds-public.yaml') for d in VENDOR_SEARCH_PATH]
def get_boolean(value):
@@ -40,8 +43,9 @@ def get_boolean(value):
class OpenStackConfig(object):
- def __init__(self, config_files=None):
+ def __init__(self, config_files=None, vendor_files=None):
self._config_files = config_files or CONFIG_FILES
+ self._vendor_files = vendor_files or VENDOR_FILES
defaults = defaults_dict.DefaultsDict()
defaults.add('username')
@@ -75,6 +79,11 @@ class OpenStackConfig(object):
if os.path.exists(path):
return yaml.load(open(path, 'r'))
+ def _load_vendor_file(self):
+ for path in self._vendor_files:
+ if os.path.exists(path):
+ return yaml.load(open(path, 'r'))
+
def _get_regions(self, cloud):
try:
return self.cloud_config['clouds'][cloud]['region_name']
@@ -100,11 +109,15 @@ class OpenStackConfig(object):
# yes, I know the next line looks silly
if 'cloud' in our_cloud:
- try:
- cloud.update(vendors.CLOUD_DEFAULTS[our_cloud['cloud']])
- except KeyError:
- # Can't find the requested vendor config, go about business
- pass
+ vendor_file = self._load_vendor_file()
+ if our_cloud['cloud'] in vendor_file['public-clouds']:
+ cloud.update(vendor_file['public-clouds'][our_cloud['cloud']])
+ else:
+ try:
+ cloud.update(vendors.CLOUD_DEFAULTS[our_cloud['cloud']])
+ except KeyError:
+ # Can't find the requested vendor config, go about business
+ pass
cloud.update(our_cloud)
if 'cloud' in cloud: