Commit fb696fbb authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Cleanup gateway handling

parent eb8606f1
......@@ -151,16 +151,34 @@ class Network(object):
return result
def gateway(self, ip):
result = None
for i in filter(None, [ util.address(i) for i in ip ]):
for g in filter(None, [ v.gateway[0]
for (k,v) in self._networks.items()
if i in k ]):
result = g
result = []
for i in ip:
a = util.address(i)
if not a:
continue
if i.defroute[0] == 'no':
# No defroute through this address
continue
if i.gateway[0]:
# Use specified address as gateway
result.append(i.gateway[0])
continue
for (n,s) in self._networks.items():
if a in n and s.gateway[0]:
g = s.gateway[0]
if util.address(g) == a:
# Never route to ourselves
continue
result.append(g)
pass
pass
pass
return result
if len(result) == 0:
return None
elif len(result) == 1:
return result[0]
raise Exception('Only one gateway allowed', list(ip))
pass
network = Network()
......@@ -259,20 +277,20 @@ def configure_networking(connection, interface, settings=None):
update['ipv4', 'never-default'] = None
update['ipv6', 'never-default'] = None
pass
ipv4gw = list(filter(None, [ ip.gateway[0] for ip in interface._ip_]))
if ipv4gw:
if len(ipv4gw) != 1:
raise Exception('Only one gateway allowed')
update['ipv4', 'gateway'] = ipv4gw[0]
update['ipv4', 'never-default'] = None
pass
ipv6gw = list(filter(None, [ ip.gateway[0] for ip in interface._ipv6_]))
if ipv6gw:
if len(ipv6gw) != 1:
raise Exception('Only one gateway allowed')
update['ipv6', 'gateway'] = ipv6gw[0]
update['ipv6', 'never-default'] = None
pass
# ipv4gw = list(filter(None, [ ip.gateway[0] for ip in interface._ip_]))
# if ipv4gw:
# if len(ipv4gw) != 1:
# raise Exception('Only one gateway allowed')
# update['ipv4', 'gateway'] = ipv4gw[0]
# update['ipv4', 'never-default'] = None
# pass
# ipv6gw = list(filter(None, [ ip.gateway[0] for ip in interface._ipv6_]))
# if ipv6gw:
# if len(ipv6gw) != 1:
# raise Exception('Only one gateway allowed')
# update['ipv6', 'gateway'] = ipv6gw[0]
# update['ipv6', 'never-default'] = None
# pass
pass
if interface.bridge[0]:
# (stp == 'no') -> False, else None
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment