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 ###############################################################################
19 exec_cmd = common.exec_cmd
22 check_file_exists = common.check_file_exists
24 backup = common.backup
27 class ConfigureNetwork(object):
29 def __init__(self, yaml_config_dir, env_id, dea):
30 self.yaml_config_dir = yaml_config_dir
33 self.required_networks = []
35 def download_network_config(self):
36 log('Download network config for environment %s' % self.env_id)
37 exec_cmd('fuel network --env %s --download --dir %s'
38 % (self.env_id, self.yaml_config_dir))
40 def upload_network_config(self):
41 log('Upload network config for environment %s' % self.env_id)
42 exec_cmd('fuel network --env %s --upload --dir %s'
43 % (self.env_id, self.yaml_config_dir))
45 def config_network(self):
46 log('Configure network')
47 self.download_network_config()
48 self.modify_network_config()
49 self.upload_network_config()
51 def modify_network_config(self):
52 log('Modify network config for environment %s' % self.env_id)
53 network_yaml = ('%s/network_%s.yaml'
54 % (self.yaml_config_dir, self.env_id))
55 check_file_exists(network_yaml)
58 network_config = self.dea.get_property('network')
60 with io.open(network_yaml) as stream:
61 network = yaml.load(stream)
63 net_names = self.dea.get_network_names()
65 for net in network['networks']:
66 if net['name'] in net_names:
67 net_id[net['name']] = {'id': net['id'],
68 'group_id': net['group_id']}
70 for network in network_config['networks']:
71 network.update(net_id[network['name']])
73 with io.open(network_yaml, 'w') as stream:
74 yaml.dump(network_config, stream, default_flow_style=False)