Merge "Refactor Foreman install guide reStructuredText"
[genesis.git] / fuel / deploy / transplant_fuel_settings.py
1 import sys
2 import common
3 import io
4 import yaml
5 from dea import DeploymentEnvironmentAdapter
6
7 check_file_exists = common.check_file_exists
8
9 def usage():
10     print '''
11     Usage:
12     python transplant_fuel_settings.py <deafile>
13     '''
14
15 def parse_arguments():
16     if len(sys.argv) != 2:
17         usage()
18         sys.exit(1)
19     dea_file = sys.argv[-1]
20     check_file_exists(dea_file)
21     return dea_file
22
23 def transplant(dea, astute):
24     fuel_conf = dea.get_fuel_config()
25     for key in fuel_conf.iterkeys():
26         if key == 'ADMIN_NETWORK':
27             for skey in fuel_conf[key].iterkeys():
28                 astute[key][skey] = fuel_conf[key][skey]
29         else:
30             astute[key] = fuel_conf[key]
31     return astute
32
33 def main():
34     dea_file = parse_arguments()
35     astute_yaml = '/etc/fuel/astute.yaml'
36     check_file_exists(astute_yaml)
37     dea = DeploymentEnvironmentAdapter(dea_file)
38     with io.open(astute_yaml) as stream:
39         astute = yaml.load(stream)
40     transplant(dea, astute)
41     with io.open(astute_yaml, 'w') as stream:
42         yaml.dump(astute, stream, default_flow_style=False)
43
44
45 if __name__ == '__main__':
46     main()