Commit 7dfd0401 authored by Xavier Thompson's avatar Xavier Thompson

slapformat: WIP: Improve overlap check

parent a24927cc
......@@ -267,26 +267,33 @@ class Computer(object):
self.checkAddressOverlaps()
def checkAddressOverlaps(self):
def single(ip):
return ipaddress.ip_network((ip.ip, ip.max_prefixlen))
ipv4 = []
ipv6 = []
ipv4_tap_gateways = {}
def network1(ip):
return ipaddress.ip_network((ip.ip, ip.max_prefixlen))
ip_list = ipv5 if self.address.version == 4 else ipv6
ip_list.append((network1(self.address), self.reference))
ipv4_maybe_shared = {}
ipv6_maybe_shared = {}
if self.address.version == 4:
ipv4_maybe_shared[single(self.address)] = self.reference
else:
ipv6_maybe_shared[single(self.address)] = self.reference
for p in self.partitions:
ipv4.extend((network1(a), p.reference + ' ip') for a in p.ipv4_list)
ipv6.extend((network1(a), p.reference + ' ip') for a in p.ipv6_list)
ipv4.extend((single(a), p.reference + ' ip') for a in p.ipv4_list)
ipv6.extend((single(a), p.reference + ' ip') for a in p.ipv6_list)
if p.ipv6_range:
ipv6.append((p.ipv6_range, p.reference + ' ipv6 range'))
if p.tap:
dev = p.tap.name
if p.tap.ipv4_address:
ipv4.append((p.tap.ipv4_address.network, dev))
ipv4_tap_gateways[network1(p.tap.ipv4_gateway)] = dev + ' gateway'
ipv4_maybe_shared[single(p.tap.ipv4_gateway)] = dev + ' gateway'
if p.tap.ipv6_gateway:
ipv6.append((p.tap.ipv6_gateway.network, dev))
ipv4.extend(ipv4_tap_gateways.items())
ipv6_address = p.tap.ipv6_address
if ipv6_address.ip not in p.tap.ipv6_gateway.network:
ipv6_maybe_shared[single(ipv6_address.network)] = dev + ' address'
ipv4.extend(ipv4_maybe_shared.items())
ipv6.extend(ipv6_maybe_shared.items())
for range_list in (ipv4, ipv6):
range_list.sort()
it = iter(range_list)
......
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