let's see what i just fucked up.
This commit is contained in:
parent
e589e00100
commit
cd422fc7d6
@ -26,18 +26,19 @@ enable-ra
|
|||||||
# {{ assignment.iface }} assignment
|
# {{ assignment.iface }} assignment
|
||||||
# Assignment blocks:
|
# Assignment blocks:
|
||||||
{%- for b in assignment.iface_blocks %}
|
{%- for b in assignment.iface_blocks %}
|
||||||
# * {{ b|string }} {{ assignment.dhcp6_ranges[assign_loop.index0] }}
|
# * {{ b|string }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- if do_listen %}
|
{%- if do_listen %}
|
||||||
listen-address = {{ assignment.iface_ll }}
|
listen-address = {{ assignment.iface_ll }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
ra-param = {{ assignment.iface }}, mtu:{{ common_opts.mtu }}, high, {{ common_opts.min_delay }}, {{ common_opts.lifetime }}
|
ra-param = {{ assignment.iface }}, mtu:{{ common_opts.mtu }}, high, {{ common_opts.min_delay }}, {{ common_opts.lifetime }}
|
||||||
{%- if assignment.ra_dhcp %}
|
{%- if assignment.ra_dhcp %}
|
||||||
{%- for block in assignment.iface_blocks %}
|
{%- for block in assignment.assign_objs %}
|
||||||
|
{%- set dhcp_range = block.dhcp6_range|join(', ') -%}
|
||||||
{%- if loop.index0 == 0 %}
|
{%- if loop.index0 == 0 %}
|
||||||
dhcp-range = {{ id_set }}, {{ assignment.dhcp6_ranges[assign_loop.index0]|join(', ') }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
|
dhcp-range = {{ id_set }}, {{ dhcp_range }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
|
||||||
{%- else %}
|
{%- else %}
|
||||||
dhcp-range = {{ identifier }}, {{ assignment.dhcp6_ranges[assign_loop.index0]|join(', ') }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
|
dhcp-range = {{ identifier }}, {{ dhcp_range }}, {{ ra_opts|join(', ') }}, {{ common_opts.lease_life }}
|
||||||
{%- endif %}
|
{%- endif %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- else %}
|
{%- else %}
|
||||||
|
@ -84,7 +84,7 @@ class Assignment(object):
|
|||||||
self.iface_ll = None
|
self.iface_ll = None
|
||||||
self.iface_idx = None
|
self.iface_idx = None
|
||||||
self.iface_blocks = []
|
self.iface_blocks = []
|
||||||
self.dhcp6_ranges = []
|
self.assign_objs = []
|
||||||
self.alloc = None # This must be set externally to a mapped Allocation instance
|
self.alloc = None # This must be set externally to a mapped Allocation instance
|
||||||
self.alloc_id = None
|
self.alloc_id = None
|
||||||
self.prefix = None
|
self.prefix = None
|
||||||
@ -128,25 +128,30 @@ class Assignment(object):
|
|||||||
|
|
||||||
def parse_alloc(self):
|
def parse_alloc(self):
|
||||||
self.alloc_block = self.alloc.ip.alloc_block
|
self.alloc_block = self.alloc.ip.alloc_block
|
||||||
self.iface_blocks = self.alloc_block.extract_subnet(self.prefix, count = 1)
|
for block in self.alloc_block.extract_subnet(self.prefix, count = 1):
|
||||||
|
self.iface_blocks.append(block)
|
||||||
|
self.assign_objs.append(AsssignmentBlock(block))
|
||||||
logger.debug('Allocation blocks for {0}: {1}'.format(self.iface, ','.join([str(i) for i in self.iface_blocks])))
|
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.
|
|
||||||
# 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'', str(_base))
|
|
||||||
logger.debug('Base prefix for {0}: {1}'.format(str(i), _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))
|
|
||||||
return(None)
|
return(None)
|
||||||
|
|
||||||
|
|
||||||
|
class AsssignmentBlock(object):
|
||||||
|
def __init__(self, net_net):
|
||||||
|
self.ip, self.prefix = str(net_net).split('/')
|
||||||
|
self.prefix = int(self.prefix)
|
||||||
|
self.ip = IP6(self.ip, self.prefix)
|
||||||
|
if self.prefix > 64:
|
||||||
|
raise ValueError('Allocation/Assignment block must be a /64 or larger (i.e. a smaller prefix)')
|
||||||
|
# DHCPv6 range.
|
||||||
|
# We need to do some funky things here.
|
||||||
|
_base = self.ip.ip
|
||||||
|
_base = ipaddress.IPv6Address(re.sub(r'(:0000){4}$', r':dead:beef:cafe::', str(_base.exploded)))
|
||||||
|
self.base = re.sub(r':0$', r'', str(_base))
|
||||||
|
start = '{0}:0'.format(self.base)
|
||||||
|
stop = '{0}:ffff'.format(self.base)
|
||||||
|
self.dhcp6_range = (start, stop)
|
||||||
|
|
||||||
|
|
||||||
class Allocation(object):
|
class Allocation(object):
|
||||||
def __init__(self, alloc_net):
|
def __init__(self, alloc_net):
|
||||||
_ip, _prefix = alloc_net.split('/')
|
_ip, _prefix = alloc_net.split('/')
|
||||||
|
Loading…
Reference in New Issue
Block a user