9 exec_cmd = common.exec_cmd
12 check_file_exists = common.check_file_exists
15 class ConfigureNetwork(object):
17 def __init__(self, yaml_config_dir, env_id, dea):
18 self.yaml_config_dir = yaml_config_dir
21 self.required_networks = []
23 def download_network_config(self):
24 log('Download network config for environment %s' % self.env_id)
25 exec_cmd('fuel network --env %s --download --dir %s'
26 % (self.env_id, self.yaml_config_dir))
28 def upload_network_config(self):
29 log('Upload network config for environment %s' % self.env_id)
30 exec_cmd('fuel network --env %s --upload --dir %s'
31 % (self.env_id, self.yaml_config_dir))
33 def config_network(self):
34 log('Configure network')
35 self.download_network_config()
36 self.modify_network_config()
37 self.upload_network_config()
39 def modify_network_config(self):
40 log('Modify network config for environment %s' % self.env_id)
41 network_yaml = ('%s/network_%s.yaml'
42 % (self.yaml_config_dir, self.env_id))
43 check_file_exists(network_yaml)
45 network_config = self.dea.get_property('network')
47 with io.open(network_yaml) as stream:
48 network = yaml.load(stream)
50 net_names = self.dea.get_network_names()
52 for net in network['networks']:
53 if net['name'] in net_names:
54 net_id[net['name']] = {'id': net['id'],
55 'group_id': net['group_id']}
57 for network in network_config['networks']:
58 network.update(net_id[network['name']])
60 with io.open(network_yaml, 'w') as stream:
61 yaml.dump(network_config, stream, default_flow_style=False)