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 ###############################################################################
22 class ConfigureSettings(object):
24 def __init__(self, yaml_config_dir, env_id, dea):
25 self.yaml_config_dir = yaml_config_dir
29 def download_settings(self):
30 log('Download settings for environment %s' % self.env_id)
31 exec_cmd('fuel settings --env %s --download --dir %s'
32 % (self.env_id, self.yaml_config_dir))
34 def upload_settings(self):
35 log('Upload settings for environment %s' % self.env_id)
36 exec_cmd('fuel settings --env %s --upload --dir %s'
37 % (self.env_id, self.yaml_config_dir))
39 def config_settings(self):
40 log('Configure settings')
41 self.download_settings()
42 self.modify_settings()
43 self.upload_settings()
45 def modify_settings(self):
46 log('Modify settings for environment %s' % self.env_id)
47 settings_yaml = ('%s/settings_%s.yaml'
48 % (self.yaml_config_dir, self.env_id))
49 check_file_exists(settings_yaml)
51 with io.open(settings_yaml, 'r') as stream:
52 orig_dea = yaml.load(stream)
55 settings = self.dea.get_property('settings')
56 # Copy fuel defined plugin_id's to user defined settings
57 # From Fuel 8.0 chosen_id was added because it is now
58 # possible to install many version of the same plugin
59 # but we will install only one version
60 for plugin in orig_dea['editable']:
61 if 'metadata' in orig_dea['editable'][plugin]:
62 if 'plugin_id' in orig_dea['editable'][plugin]['metadata']:
63 if not plugin in settings['editable']:
64 settings['editable'][plugin] = orig_dea['editable'][plugin]
66 settings['editable'][plugin]["metadata"]["plugin_id"] = orig_dea['editable'][plugin]["metadata"]["plugin_id"]
67 elif 'chosen_id' in orig_dea['editable'][plugin]['metadata']:
68 if not plugin in settings['editable']:
69 settings['editable'][plugin] = orig_dea['editable'][plugin]
71 settings['editable'][plugin]['metadata']['chosen_id'] = orig_dea['editable'][plugin]['metadata']['chosen_id']
72 settings['editable'][plugin]['metadata']['versions'][0]['metadata']['plugin_id'] = orig_dea['editable'][plugin]['metadata']['versions'][0]['metadata']['plugin_id']
74 with io.open(settings_yaml, 'w') as stream:
75 yaml.dump(settings, stream, default_flow_style=False)