From 3ed3b917aa2cc15b92459f8e6f9cbfa8284ef57d Mon Sep 17 00:00:00 2001 From: Anders Blomdell <anders.blomdell@control.lth.se> Date: Fri, 28 Aug 2015 11:02:52 +0200 Subject: [PATCH] Move IPv6 hosts out of dhcpd6 subnet --- src/hostinfo/dhcpd.py | 36 +++++++++++++++++------------------- src/hostinfo/dhcpd_ipv6.py | 13 ++++++++----- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/src/hostinfo/dhcpd.py b/src/hostinfo/dhcpd.py index 492f8b9..54f8b3d 100755 --- a/src/hostinfo/dhcpd.py +++ b/src/hostinfo/dhcpd.py @@ -257,31 +257,29 @@ def emit_hosts(tree, options, networks): return filter(lambda n: a in n, networks) static = {} never = {} - for interface in tree._host_._interface_: - ethernet = interface.ethernet[0:] + for ip in tree._host_._interface_._ip_: + # Find all hosts that associated with this network + ethernet = ip.ethernet[0:] if not ethernet: continue if ethernet.lower() != ethernet: raise util.HostinfoException('%s not lower-case' % ethernet) - for ip in interface._ip_: - # Find all hosts that associated with this network - if ip.never[0]: - if match(util.address(ip.never[0])): - if not ethernet in never: - never[ethernet] = [] - pass - never[ethernet].append(ip) + if ip.never[0]: + if match(util.address(ip.never[0])): + if not ethernet in never: + never[ethernet] = [] pass - continue - if match(util.address(ip)): - if not ethernet in static: - static[ethernet] = [] - pass - static[ethernet].append(ip) - continue - pass + never[ethernet].append(ip) + pass + continue + if match(util.address(ip)): + if not ethernet in static: + static[ethernet] = [] + pass + static[ethernet].append(ip) + continue pass - + def by_name(ether_ip_dict): result = {} for e in ether_ip_dict: diff --git a/src/hostinfo/dhcpd_ipv6.py b/src/hostinfo/dhcpd_ipv6.py index cbda7cf..6116ba0 100755 --- a/src/hostinfo/dhcpd_ipv6.py +++ b/src/hostinfo/dhcpd_ipv6.py @@ -46,8 +46,11 @@ def generate(tree, options): for i in interface: result += emit_interface(tree, options, i) pass + served_networks = map(lambda d: util.network(get_subnet(tree, d._parent)), + dhcp) + result += emit_hosts(tree, options, served_networks) return str(result) - + def emit_interface(tree, options, interface): result = util.StringArray() subnet = dict(map(lambda d: (get_subnet(tree, d._parent), d), @@ -79,7 +82,6 @@ def emit_network(tree, options, subnet, dhcp): result += " range6 %s %s;" % (first, last) pass result += emit_subnet_info(subnet).indent() - result += emit_hosts(tree, options, net).indent() result += '}' return result @@ -98,12 +100,12 @@ def emit_subnet_info(subnet): result += '' return result -def emit_hosts(tree, options, net): +def emit_hosts(tree, options, networks): result = util.StringArray() + def match(a): + return filter(lambda n: a in n, networks) static = {} never = {} - def match(a): - return filter(lambda n: a in n, [net]) for ip in tree._host_._interface_._ipv6_: # Find all hosts that associated with this network ethernet = ip.ethernet[0:] @@ -126,6 +128,7 @@ def emit_hosts(tree, options, net): static[ethernet].append(ip) continue pass + def by_name(ether_ip_dict): result = {} for e in ether_ip_dict: -- GitLab