Skip to content
Snippets Groups Projects
Commit 064e1825 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Version 2008-06-16 19:22

M  src/hostinfo/dhcpd.py
parent 0f1cddee
No related branches found
No related tags found
No related merge requests found
......@@ -48,44 +48,79 @@ class "AppleNBI-ppc" {
def conf(tree, dhcphost):
#
# A. Check if host is a dhcpserver
# A. Get interfaces to serve
#
emit = False
interface = []
for ds in tree._host_._interface_._dhcpserver_:
if dhcphost in ds.name[0::1]:
# Given host is a dhcpserver
dhcphost = ds.name[0:]
# Host is dhcpserver for this interface
dhcpip = ds.ip[0:]
emit = True
if not emit:
interface.append(ds._parent)
if not interface:
raise Exception("%s is not a dhcpserver" % dhcphost)
#
# B. Emit header
#
result = "ddns-update-style none;\n"
result += "authoritative;\n"
result += MacOS_NETBOOT(dhcpip)
#
# C. Emit subnet declarations for each interface
#
for i in interface:
address = []
if i.ip[0]:
# Main address
address.append(i.ip[0])
for ip in i._ip_:
# Alias addresses
if ip.address[0]:
address.append(ip.address[0])
# Collect subnets for this interface
network = {}
for n in tree._subnet_:
if not n.network[0]:
continue
netmask = aton(n.netmask[0])
subnet = aton(n.network[0]) & netmask
for a in address:
if aton(a) & netmask == subnet:
network[ntoa(subnet)] = n
# Emit subnet declarations
if len(network.keys()) > 1:
# Multiple networks served on this interface
result += 'shared-network "MAC(%s)" {\n\n' % i.ethernet[0]
for n in network.values():
for l in emit_subnet(tree, n, dhcphost).split("\n"):
result += " %s\n" % l
result += "}\n"
else:
result += emit_subnet(tree, network.values()[0], dhcphost)
return result
def emit_subnet(tree, n, dhcphost):
result = ""
netmask = aton(n.netmask[0])
subnet = aton(n.network[0]) & netmask
static = {}
dynamic = {}
emit = None
for i in tree._host_._interface_:
# Find all hosts that belong to this network
if i.ip[0]:
net = aton(i.ip[0]) & netmask
if net == subnet:
if i.name[0:] == dhcphost:
emit = i._dhcpserver_
if i.dynamic[0] == dhcphost:
# Dynamic address served by this host
dynamic[aton(i.ip[0])] = i
else:
static[i.name[0:]] = i
if not emit:
continue
result += "subnet %s netmask %s {\n" % (n.network[0], n.netmask[0])
result += " option subnet-mask %s;\n" % n.netmask[0]
......@@ -96,7 +131,8 @@ def conf(tree, dhcphost):
if n.domain[0]:
result += " option domain-name \"%s\";\n" % n.domain[0]
if n.name_servers[0]:
result += " option domain-name-servers %s;\n" % n.name_servers[0]
result += " option domain-name-servers %s;\n" % (
n.name_servers[0])
#
# Emit dynamic hosts
......@@ -148,5 +184,6 @@ def conf(tree, dhcphost):
result += " }\n"
result += "}\n\n"
result += "}\n"
return result
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment