Updates docs for SR1 with final revision
[genesis.git] / fuel / deploy / transplant_fuel_settings.py
1 ###############################################################################
2 # Copyright (c) 2015 Ericsson AB and others.
3 # szilard.cserey@ericsson.com
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Apache License, Version 2.0
6 # which accompanies this distribution, and is available at
7 # http://www.apache.org/licenses/LICENSE-2.0
8 ###############################################################################
9
10
11 import sys
12 import common
13 import io
14 import yaml
15 from dea import DeploymentEnvironmentAdapter
16
17 check_file_exists = common.check_file_exists
18
19 ASTUTE_YAML = '/etc/fuel/astute.yaml'
20
21
22 def usage():
23     print '''
24     Usage:
25     python transplant_fuel_settings.py <deafile>
26     '''
27
28
29 def parse_arguments():
30     if len(sys.argv) != 2:
31         usage()
32         sys.exit(1)
33     dea_file = sys.argv[-1]
34     check_file_exists(dea_file)
35     return dea_file
36
37
38 def transplant(dea, astute):
39     fuel_conf = dea.get_fuel_config()
40     for key in fuel_conf.iterkeys():
41         if key == 'ADMIN_NETWORK':
42             for skey in fuel_conf[key].iterkeys():
43                 astute[key][skey] = fuel_conf[key][skey]
44         else:
45             astute[key] = fuel_conf[key]
46     return astute
47
48
49 def main():
50     dea_file = parse_arguments()
51     check_file_exists(ASTUTE_YAML)
52     dea = DeploymentEnvironmentAdapter(dea_file)
53     with io.open(ASTUTE_YAML) as stream:
54         astute = yaml.load(stream)
55     transplant(dea, astute)
56     with io.open(ASTUTE_YAML, 'w') as stream:
57         yaml.dump(astute, stream, default_flow_style=False)
58
59
60 if __name__ == '__main__':
61     main()