11 exec_cmd = common.exec_cmd
15 P1 = re.compile('!\s.*')
17 class ConfigureNetwork(object):
19 def __init__(self, yaml_config_dir, network_yaml, env_id, dea):
20 self.yaml_config_dir = yaml_config_dir
21 self.network_yaml = network_yaml
25 def download_settings(self):
26 exec_cmd('fuel network --env %s --download --dir %s'
27 % (self.env_id, self.yaml_config_dir))
29 def upload_settings(self):
30 exec_cmd('fuel network --env %s --upload --dir %s'
31 % (self.env_id, self.yaml_config_dir))
33 def config_network(self):
35 self.download_settings()
37 self.apply_network_config()
39 self.upload_settings()
43 def apply_network_config(self):
45 with io.open(self.network_yaml) as stream:
46 network_config = yaml.load(stream)
47 networks = network_config['networks']
49 net = self.dea.get_networks()
50 net['fuelweb_admin'] = net['management']
51 if 'vlan' in net['fuelweb_admin']:
52 del net['fuelweb_admin']['vlan']
54 net_names = [n for n in net.iterkeys()]
56 for i in range(len(networks)):
57 if networks[i]['name'] == 'management':
58 networks = networks[:i] + networks[i+1:]
59 network_config['networks'] = networks
62 for network in networks:
63 name = network['name']
65 if ('vlan' in net[name] and net[name]['vlan'] is not None):
66 network['vlan_start'] = net[name]['vlan']
67 network['cidr'] = net[name]['cidr']
68 network['ip_ranges'][0][0] = net[name]['start']
69 network['ip_ranges'][0][1] = net[name]['end']
71 with io.open(self.network_yaml, 'w') as stream:
72 yaml.dump(network_config, stream, default_flow_style=False)
75 ret = exec_cmd('mktemp -d')
76 temp_dir = ret.splitlines()[0]
78 exec_cmd('fuel network --env %s --download --dir %s'
79 % (self.env_id, temp_dir))
81 ret = exec_cmd('diff -C0 %s %s'
83 temp_dir + '/network_%s.yaml' % self.env_id))
85 for l in ret.splitlines():
87 if m and '_vip' not in l:
90 err('Uploaded network yaml rejected by Fuel\n')