okay, i think i fixed the range allocation issue.

This commit is contained in:
brent s. 2020-05-18 08:13:39 -04:00
parent 50fd503ce6
commit 01acb18f5f
Signed by: bts
GPG Key ID: 8C004C2F93481F6B
1 changed files with 9 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import ipaddress
import logging
import re
import socket
##
import netaddr
@ -130,11 +131,16 @@ class Assignment(object):
self.iface_blocks = self.alloc_block.extract_subnet(self.prefix, count = 1)
logger.debug('Allocation blocks for {0}: {1}'.format(self.iface, ','.join([str(i) for i in self.iface_blocks])))
for idx, i in enumerate(self.iface_blocks):
if i.prefixlen > 64:
raise ValueError('Allocation block must be a /64 or larger')
# DHCPv6 range.
_base = '{0}:{1}'.format(str(i.ip).rstrip(':'), idx)
# We need to do some funky things here. Netaddr doesn't have an .exploded().
_base = ipaddress.IPv6Address(str(i.ip))
_base = ipaddress.IPv6Address(re.sub(r'(:0000){4}$', r':dead:beef:cafe::', str(_base.exploded)))
_base = re.sub(r':0$', r'', _base)
logger.debug('Base prefix for {0}: {1}'.format(str(i), _base))
start = '{0}:dead:beef:cafe:0'.format(_base)
stop = '{0}:dead:beef:cafe:ffff'.format(_base)
start = '{0}:0'.format(_base)
stop = '{0}:ffff'.format(_base)
d_range = (start, stop)
self.dhcp6_ranges.append(d_range)
logger.debug('Added range {0} to block {1} for iface {2}'.format(d_range, str(i.ip), self.iface))