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.debug('Download network config for environment %s\n' % 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.debug('Upload network config for environment %s\n' % 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.debug('Configure network\n')
35 self.download_network_config()
36 self.modify_network_config()
37 self.upload_network_config()
39 def modify_network_config(self):
40 LOG.debug('Modify network config for environment %s\n' % self.env_id)
41 network_yaml = (self.yaml_config_dir + '/network_%s.yaml'
43 check_file_exists(network_yaml)
45 network_config = self.dea.get_networks()
48 with io.open(network_yaml) as stream:
49 network = yaml.load(stream)
51 net_names = self.dea.get_network_names()
53 for net in network['networks']:
54 if net['name'] in net_names:
55 net_id[net['name']] = {'id': net['id'],
56 'group_id': net['group_id']}
58 for network in network_config['networks']:
59 network.update(net_id[network['name']])
61 with io.open(network_yaml, 'w') as stream:
62 yaml.dump(network_config, stream, default_flow_style=False)