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 ConfigureNetwork(object):
24 def __init__(self, yaml_config_dir, env_id, dea):
25 self.yaml_config_dir = yaml_config_dir
28 self.required_networks = []
30 def download_network_config(self):
31 log('Download network config for environment %s' % self.env_id)
32 exec_cmd('fuel network --env %s --download --dir %s'
33 % (self.env_id, self.yaml_config_dir))
35 def upload_network_config(self):
36 log('Upload network config for environment %s' % self.env_id)
37 exec_cmd('fuel network --env %s --upload --dir %s'
38 % (self.env_id, self.yaml_config_dir))
40 def config_network(self):
41 log('Configure network')
42 self.download_network_config()
43 self.modify_network_config()
44 self.upload_network_config()
46 def modify_network_config(self):
47 log('Modify network config for environment %s' % self.env_id)
48 network_yaml = ('%s/network_%s.yaml'
49 % (self.yaml_config_dir, self.env_id))
50 check_file_exists(network_yaml)
53 network_config = self.dea.get_property('network')
55 with io.open(network_yaml) as stream:
56 network = yaml.load(stream)
58 net_names = self.dea.get_network_names()
60 for net in network['networks']:
61 if net['name'] in net_names:
62 net_id[net['name']] = {'id': net['id'],
63 'group_id': net['group_id']}
65 for network in network_config['networks']:
66 network.update(net_id[network['name']])
68 with io.open(network_yaml, 'w') as stream:
69 yaml.dump(network_config, stream, default_flow_style=False)