summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMonty Taylor <mordred@inaugust.com>2015-05-05 14:27:40 -0600
committerMonty Taylor <mordred@inaugust.com>2015-05-07 11:20:40 -0600
commitdc8d21db11da1c80ad13f5626bbea63fdd649628 (patch)
tree9f9f1b80c01479f8c1f4d9333899e162a2feeec2
parent912af15b522423ee8f91d8b8861c4d4a090ef793 (diff)
downloados-client-config-dc8d21db11da1c80ad13f5626bbea63fdd649628.tar.gz
Also accept .yml as a suffix
The ansible world uses .yml suffixes, which brings people to try to use that suffix on clouds.yaml files. It's easy enough to accept it as a possibility. Change-Id: Iba05eab9cf4406833afafe8143794461b656b548
-rw-r--r--os_client_config/config.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/os_client_config/config.py b/os_client_config/config.py
index 8d687ef..f2ddd48 100644
--- a/os_client_config/config.py
+++ b/os_client_config/config.py
@@ -31,15 +31,22 @@ CONFIG_HOME = os.path.join(os.path.expanduser(
os.environ.get('XDG_CONFIG_HOME', os.path.join('~', '.config'))),
'openstack')
CONFIG_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack']
+YAML_SUFFIXES = ('.yaml', '.yml')
CONFIG_FILES = [
- os.path.join(d, 'clouds.yaml') for d in CONFIG_SEARCH_PATH]
+ os.path.join(d, 'clouds' + s)
+ for d in CONFIG_SEARCH_PATH
+ for s in YAML_SUFFIXES
+]
CACHE_PATH = os.path.join(os.path.expanduser(
os.environ.get('XDG_CACHE_PATH', os.path.join('~', '.cache'))),
'openstack')
BOOL_KEYS = ('insecure', 'cache')
VENDOR_SEARCH_PATH = [os.getcwd(), CONFIG_HOME, '/etc/openstack']
VENDOR_FILES = [
- os.path.join(d, 'clouds-public.yaml') for d in VENDOR_SEARCH_PATH]
+ os.path.join(d, 'clouds-public' + s)
+ for d in VENDOR_SEARCH_PATH
+ for s in YAML_SUFFIXES
+]
def set_default(key, value):
@@ -126,14 +133,13 @@ class OpenStackConfig(object):
'arguments', self._cache_arguments)
def _load_config_file(self):
- for path in self._config_files:
- if os.path.exists(path):
- with open(path, 'r') as f:
- return yaml.safe_load(f)
- return dict(clouds=dict())
+ return self._load_yaml_file(self._config_files)
def _load_vendor_file(self):
- for path in self._vendor_files:
+ return self._load_yaml_file(self._vendor_files)
+
+ def _load_yaml_file(self, filelist):
+ for path in filelist:
if os.path.exists(path):
with open(path, 'r') as f:
return yaml.safe_load(f)