Updates docs for SR1 with final revision
[genesis.git] / fuel / deploy / cloud / configure_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 import common
11 import yaml
12 import io
13
14 N = common.N
15 E = common.E
16 R = common.R
17 RO = common.RO
18 exec_cmd = common.exec_cmd
19 parse = common.parse
20 err = common.err
21 check_file_exists = common.check_file_exists
22 log = common.log
23 backup = common.backup
24
25
26 class ConfigureSettings(object):
27
28     def __init__(self, yaml_config_dir, env_id, dea):
29         self.yaml_config_dir = yaml_config_dir
30         self.env_id = env_id
31         self.dea = dea
32
33     def download_settings(self):
34         log('Download settings for environment %s' % self.env_id)
35         exec_cmd('fuel settings --env %s --download --dir %s'
36                  % (self.env_id, self.yaml_config_dir))
37
38     def upload_settings(self):
39         log('Upload settings for environment %s' % self.env_id)
40         exec_cmd('fuel settings --env %s --upload --dir %s'
41                  % (self.env_id, self.yaml_config_dir))
42
43     def config_settings(self):
44         log('Configure settings')
45         self.download_settings()
46         self.modify_settings()
47         self.upload_settings()
48
49     def modify_settings(self):
50         log('Modify settings for environment %s' % self.env_id)
51         settings_yaml = ('%s/settings_%s.yaml'
52                          % (self.yaml_config_dir, self.env_id))
53         check_file_exists(settings_yaml)
54         backup(settings_yaml)
55
56         settings = self.dea.get_property('settings')
57
58         with io.open(settings_yaml, 'w') as stream:
59             yaml.dump(settings, stream, default_flow_style=False)