Fix noha virtual deployment templates for Erisson blade
[fuel.git] / 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 io
13 import yaml
14 from dea import DeploymentEnvironmentAdapter
15
16 from common import (
17     check_file_exists,
18 )
19
20 ASTUTE_YAML = '/etc/fuel/astute.yaml'
21
22
23 def usage():
24     print '''
25     Usage:
26     python transplant_fuel_settings.py <deafile>
27     '''
28
29
30 def parse_arguments():
31     if len(sys.argv) != 2:
32         usage()
33         sys.exit(1)
34     dea_file = sys.argv[-1]
35     check_file_exists(dea_file)
36     return dea_file
37
38
39 def transplant(dea, astute):
40     fuel_conf = dea.get_fuel_config()
41     for key in fuel_conf.iterkeys():
42         if key == 'ADMIN_NETWORK':
43             for skey in fuel_conf[key].iterkeys():
44                 astute[key][skey] = fuel_conf[key][skey]
45         else:
46             astute[key] = fuel_conf[key]
47     return astute
48
49
50 def main():
51     dea_file = parse_arguments()
52     check_file_exists(ASTUTE_YAML)
53     dea = DeploymentEnvironmentAdapter(dea_file)
54     with io.open(ASTUTE_YAML) as stream:
55         astute = yaml.load(stream)
56     transplant(dea, astute)
57     with io.open(ASTUTE_YAML, 'w') as stream:
58         yaml.dump(astute, stream, default_flow_style=False)
59
60
61 if __name__ == '__main__':
62     main()