2
from __future__ import print_function
4
from argparse import ArgumentParser
7
from textwrap import dedent
11
from jujuconfig import get_environments
15
from tests.test_jujupy import fake_juju_client
18
def write_new_config(env, out):
19
client = fake_juju_client(env=env)
20
out.write('# cloud/region: {}\n'.format(client.get_cloud_region(
21
client.env.get_cloud(), client.env.get_region())))
22
config = client.make_model_config()
23
if 'agent-version' in env.config:
24
config['agent-version'] = env.config['agent-version']
26
config.pop('agent-version', None)
27
yaml.dump(config, out, default_flow_style=False)
31
parser = ArgumentParser(
32
description=dedent('''\
33
Convert environments.yaml to 2.0 format.
35
environments.yaml from JUJU_HOME will be used.
36
Existing configs in the output directory will be overwritten.
38
Does not support configs of type 'local'.
40
parser.add_argument('config_dir', metavar='OUTPUT_DIR',
41
help='Directory to write updated configs to.')
42
args = parser.parse_args()
43
clouds_credentials = JujuData('', {})
44
clouds_credentials.load_yaml()
45
for environment, config in get_environments().items():
46
if config['type'] == 'local':
48
env = JujuData(environment, config)
49
env.clouds = clouds_credentials.clouds
50
env.credentials = clouds_credentials.credentials
53
out_path = os.path.join(args.config_dir,
54
'{}.yaml'.format(environment))
55
with open(out_path, 'w') as out_file:
56
write_new_config(env, out_file)
59
if __name__ == '__main__':