From f503d1b0e7fb9fe77e6fd1e71e08ca2d43427578 Mon Sep 17 00:00:00 2001 From: Ben Nemec Date: Tue, 31 May 2016 11:47:10 -0500 Subject: Support config dir for env generator input files We're not going to want to list every single sample environment in a single file, so let's also take a directory and just read every yaml file in it. This commit adds support for that as well as some initial environments to demonstrate its use. Change-Id: If2c608f2a61fc5e16784ab594d23f1fa335e1d3c --- tripleo_heat_templates/environment_generator.py | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) (limited to 'tripleo_heat_templates') diff --git a/tripleo_heat_templates/environment_generator.py b/tripleo_heat_templates/environment_generator.py index e2f48720..659a7d57 100755 --- a/tripleo_heat_templates/environment_generator.py +++ b/tripleo_heat_templates/environment_generator.py @@ -165,24 +165,32 @@ def _generate_environment(input_env, parent_env=None): _generate_environment(e, env) -def generate_environments(config_file): - with open(config_file) as f: - config = yaml.safe_load(f) - for env in config['environments']: - _generate_environment(env) +def generate_environments(config_path): + if os.path.isdir(config_path): + config_files = os.listdir(config_path) + config_files = [os.path.join(config_path, i) for i in config_files + if os.path.splitext(i)[1] == '.yaml'] + else: + config_files = [config_path] + for config_file in config_files: + print('Reading environment definitions from %s' % config_file) + with open(config_file) as f: + config = yaml.safe_load(f) + for env in config['environments']: + _generate_environment(env) def usage(exit_code=1): - print('Usage: %s ' % sys.argv[0]) + print('Usage: %s [ | ]' % sys.argv[0]) sys.exit(exit_code) def main(): try: - config_file = sys.argv[1] + config_path = sys.argv[1] except IndexError: usage() - generate_environments(config_file) + generate_environments(config_path) if __name__ == '__main__': -- cgit 1.2.3-korg