Automatic Deployment
[genesis.git] / fuel / deploy / cloud_deploy / cloud / configure_settings.py
1 import common
2 import yaml
3 import io
4
5 N = common.N
6 E = common.E
7 R = common.R
8 RO = common.RO
9 exec_cmd = common.exec_cmd
10 parse = common.parse
11 err = common.err
12 check_file_exists = common.check_file_exists
13 LOG = common.LOG
14
15 class ConfigureSettings(object):
16
17     def __init__(self, yaml_config_dir, env_id, dea):
18         self.yaml_config_dir = yaml_config_dir
19         self.env_id = env_id
20         self.dea = dea
21
22     def download_settings(self):
23         LOG.debug('Download settings for environment %s\n' % self.env_id)
24         r, c = exec_cmd('fuel settings --env %s --download --dir %s'
25                         % (self.env_id, self.yaml_config_dir))
26
27     def upload_settings(self):
28         LOG.debug('Upload settings for environment %s\n' % self.env_id)
29         r, c = exec_cmd('fuel settings --env %s --upload --dir %s'
30                         % (self.env_id, self.yaml_config_dir))
31
32     def config_settings(self):
33         LOG.debug('Configure settings\n')
34         self.download_settings()
35         self.modify_settings()
36         self.upload_settings()
37
38     def modify_settings(self):
39         LOG.debug('Modify settings for environment %s\n' % self.env_id)
40         settings_yaml = (self.yaml_config_dir + '/settings_%s.yaml'
41                          % self.env_id)
42         check_file_exists(settings_yaml)
43
44         settings = self.dea.get_settings()
45
46         with io.open(settings_yaml, 'w') as stream:
47             yaml.dump(settings, stream, default_flow_style=False)