Commit d357511b authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Version 2013-11-07 16:13

M  src/hostinfo/dhcpd.py
M  src/hostinfo/util.py
M  src/hostinfo/yp.py
parent a42d3838
......@@ -90,15 +90,15 @@ class "pxeclient" {
} else {
filename "pxelinux.0";
}
}
"""
}"""
PXE_DENY="""
authoritative;
class "pxeclient" {
match if substring (option vendor-class-identifier, 0, 9) = "PXEClient";
ignore booting;
}
"""
}"""
def MacOS_NETBOOT(dhcphost):
if not os.path.exists('/local/macos'):
......@@ -152,7 +152,6 @@ def generate(tree, options):
result.append_lines("""
|ddns-update-style none;
|authoritative;
|get-lease-hostnames true;
|use-host-decl-names on;
""")
......@@ -210,7 +209,10 @@ def emit_network(tree, options, subnet, dhcp):
assert first in net, '%s not part of %s' % (first, net)
assert last in net, '%s not part of %s' % (last, net)
if pxeboot == 'no':
result += " range %s %s;" % (first, last)
result.append_lines("""
| pool {
| range %(first)s %(last)s;
| }""" % dict(first=first, last=last))
pass
elif pxeboot == 'only':
result.append_lines("""
......@@ -239,7 +241,6 @@ def emit_subnet_info(subnet):
if subnet.ntp_servers[0]:
result += "option ntp-servers %s;" % (subnet.ntp_servers[0])
pass
result += ''
return result
def emit_hosts(tree, options, networks):
......@@ -248,28 +249,31 @@ def emit_hosts(tree, options, networks):
return filter(lambda n: a in n, networks)
static = {}
never = {}
for ip in tree._host_._interface_._ip_:
# Find all hosts that associated with this network
ethernet = ip.ethernet[0:]
for interface in tree._host_._interface_:
ethernet = interface.ethernet[0:]
if not ethernet:
continue
if ethernet.lower() != ethernet:
raise util.HostinfoException('%s not lower-case' % ethernet)
if ip.never[0]:
if match(util.address(ip.never[0])):
if not ethernet in never:
never[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)
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
if match(util.address(ip)):
if not ethernet in static:
static[ethernet] = []
pass
static[ethernet].append(ip)
continue
pass
pass
def by_name(ether_ip_dict):
result = {}
for e in ether_ip_dict:
......@@ -278,10 +282,11 @@ def emit_hosts(tree, options, networks):
raise util.HostinfoException('Multiple names %s' % name,
where=ether_ip_dict[e])
name = name.pop()
result[name] = (e, ether_ip_dict[e])
key = '%s_%s' % (name, e)
result[key] = (name, e, ether_ip_dict[e])
pass
for name in sorted(result):
ether, ip = result[name]
for key in sorted(result):
name, ether, ip = result[key]
yield name, ether, ip
pass
pass
......@@ -293,8 +298,7 @@ def emit_hosts(tree, options, networks):
| max-lease-time 315360000; # 10 years
|""")
for name, ether, ip in by_name(static):
if ether in never:
never.pop(ether)
if ether in never: never.pop(ether)
result.append_lines("""
| host %(id)s {
| hardware ethernet %(ethernet)s;
......
......@@ -19,6 +19,17 @@ def address(ip):
else:
return None
def subnet(tree, addr):
def match(subnet):
net = network(subnet)
return net and addr in net
result = filter(match, tree._subnet_)
if len(result) > 1:
raise HostinfoException('%s matches multiple networks' % (addr),
where=result)
return result and result[0] or None
def aton(addr):
result = long(0)
for s in addr.split('.'):
......@@ -48,15 +59,13 @@ def fqn(tree, host):
raise Exception('Unexpected tag: %s', host._tag)
if ip_addr:
for s in tree._subnet_:
net = network(s)
if net and ip_addr in net:
return "%s.%s." % (host.name[1:], s.domain[0])
pass
raise Exception("No subnet declaration for '%s' (%s)" %
(host.name[0:], ip_addr))
s = subnet(tree, ip_addr)
if not s or not s.domain[0]:
return None
return "%s.%s." % (host.name[1:], s.domain[0])
else:
raise Exception("'%s' not FQN, but has no ip" % host.name[0:])
raise Exception("'%s' not FQN, but has no ip %s" %
(host.name[0:], host))
pass
def by_ip(a, b):
......
from hostinfo.util import fqn, aton, ntoa, by_ip, by_mac
#from hostinfo.util import fqn, aton, ntoa, by_ip, by_mac
import hostinfo.util as util
def generate(tree, auto_domain):
result = []
......@@ -10,50 +11,35 @@ def generate(tree, auto_domain):
return result
def ypsuffix(tree, ip):
for n in tree._subnet_:
try:
netmask = aton(n.netmask[0])
subnet = aton(n.network[0]) & netmask
ipnet = aton(ip) & netmask
if subnet == ipnet and n.yp_suffix[0:]:
return n.yp_suffix[0:]
pass
except:
pass
pass
return ''
s = util.subnet(tree, util.address(ip))
return s and s.yp_suffix[0:] or ''
def hosts(tree):
result = ""
host = {}
for i in tree._host_._interface_._ip_:
if i.address[0]:
host[i.address[0]] = i.name[0:] + ypsuffix(tree, i.address[0:])
for a in i._alias_:
host[i.address[0]] += " %s" % a.name[0]
key = host.keys()
key.sort(by_ip)
for k in key:
for i,address in [ (i, util.address(i))
for i in tree._host_._interface_._ip_
if util.address(i) ]:
host[address] = i.name[0:] + ypsuffix(tree, i.address[0:])
for a in i._alias_:
host[address] += " %s" % a.name[0]
for k in sorted(host):
result += "%-15s %s\n" % (k, host[k])
return result
def ethers(tree):
result = ""
host = {}
for i in tree._host_._interface_:
if i.ethernet[0]:
host[i.ethernet[0]] = [ i.name[0:] ]
for ip in i._ip_:
try:
host[i.ethernet[0]].append(fqn(tree, ip)[0:-1])
except:
pass
for i in filter(lambda i: i.ethernet[0], tree._host_._interface_):
host[i.ethernet[0]] = [ i.name[0:] ]
for ip in filter(util.address, i._ip_):
fqn = util.fqn(tree, ip)
if fqn:
host[i.ethernet[0]].append(fqn[0:-1])
pass
pass
pass
key = host.keys()
key.sort(by_mac)
for k in key:
for k in sorted(host, cmp=util.by_mac):
for h in host[k]:
result += "%-15s %s\n" % (k, h)
return result
......@@ -95,16 +81,14 @@ def netgroup(tree):
elif m.host[0]:
entry = "(%s,,)" % m.host[0]
pass
try:
netgroup[m.name[1]].append(entry)
pass
except:
netgroup[m.name[1]] = [ entry ]
if not m.name[1] in netgroup:
netgroup[m.name[1]] = [ ]
pass
netgroup[m.name[1]].append(entry)
pass
for g in tree._host_._interface_._netgroup_:
def exclude(ip):
if ip.alias[0] or ip.vlan[0] or ip.never[0]:
if not util.address(ip):
return False
if ip.exclude_netgroups[0]:
if g.name[0] in ip.exclude_netgroups[0].split(','):
......@@ -116,7 +100,7 @@ def netgroup(tree):
if not g.name[0:] in netgroup:
netgroup[g.name[0:]] = [ ]
pass
entry = "(%s,,)" % fqn(tree, ip)[0:-1]
entry = "(%s,,)" % util.fqn(tree, ip)[0:-1]
netgroup[g.name[0:]].append(entry)
pass
pass
......@@ -124,7 +108,7 @@ def netgroup(tree):
for ip in filter(lambda ip: (not ip.alias[0] and not ip.vlan[0] and
not ip.never[0]),
k._parent._ip_):
entry = "(%s,,)" % fqn(tree, ip)[0:-1]
entry = "(%s,,)" % util.fqn(tree, ip)[0:-1]
key = "ks-%s" % k.file[0:]
if not key in netgroup:
netgroup[key] = []
......
Supports Markdown
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