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

Added rudimantary check functionality

parent e00055f1
......@@ -190,6 +190,10 @@ if __name__ == '__main__':
optParser.add_argument("hostinfo_xml", nargs='?',
default="/etc/hostinfo.xml",
help="hostinfo file")
optParser.add_argument("--check",
default=False,
action="store_true",
help="Sanity check hostinfo file")
optParser.add_argument("--host",
default=os.uname()[1].split('.')[0],
action="store",
......@@ -265,6 +269,13 @@ if __name__ == '__main__':
file = {}
symlink = {}
if options.check:
hostinfo.named.generate(tree, options),
hostinfo.dhcpd.generate(tree, options),
hostinfo.dhcpd_ipv6.generate(tree, options),
sys.exit(0)
if options.dfs:
for (f, c) in hostinfo.samba.msdfs(tree):
symlink["%s/%s" % (options.dfs, f)] = c
......
......@@ -152,9 +152,9 @@ def generate(tree, options):
result = util.StringArray()
dhcp = set([d for d
in tree._host_._interface_._ip_._dhcpserver_
if options.host in d.name[0::1]])
if options.check or options.host in d.name[0::1]])
assert dhcp, '%s is not a dhcp server' % options.host
pxeboot = get_pxeboot(dhcp)
pxeboot = get_pxeboot(dhcp, options)
result.append_lines("""
|ddns-update-style none;
......@@ -191,7 +191,7 @@ def emit_interface(tree, options, interface):
for ethernet in util.ethernets(interface.ethernet[0]):
result += 'shared-network "MAC(%s)" {' % ethernet
for sn,dhcp in [ (n, subnet[n]) for n
in sorted(subnet, key=lambda s: s.network[0]) ]:
in sorted(subnet, key=lambda s: s.network[0] or '') ]:
result += emit_network(tree, options, sn, dhcp).indent()
pass
result += "}"
......@@ -201,7 +201,7 @@ def emit_interface(tree, options, interface):
def emit_network(tree, options, subnet, dhcp):
result = util.StringArray()
net = util.network(subnet)
pxeboot = get_pxeboot(dhcp)
pxeboot = get_pxeboot(dhcp, options)
result.append_lines("""
|subnet %(network)s netmask %(netmask)s {
| option subnet-mask %(netmask)s;
......@@ -349,21 +349,23 @@ def get_subnet(tree, ip):
s = util.network(subnet)
return s and a in s
subnet = [ s for s in tree._subnet_ if match(s) ]
assert len(subnet) == 1, '%s matches multiple networks %s' % (a, subnet)
if len(subnet) != 1:
util.HostinfoException('%s matches multiple networks %s' % (a, subnet),
where=ip)
return subnet[0]
def get_pxeboot(dhcp):
try:
p = set([ d.pxeboot[0] or 'no' for d in dhcp ])
if len(p) != 1:
raise util.HostinfoException("Mixed pxeboot not allowed (%s)" %
','.join(p),
where=dhcp)
result = p.pop()
pass
except TypeError:
result = dhcp.pxeboot[0] or 'no'
pass
allowed = [ 'no', 'only' ]
assert result in allowed,"pxeboot ('%s') shold be in %s" % (result, allowed)
return result
def get_pxeboot(dhcp, options):
result = set()
result.update(set([ d.pxeboot[0] or 'no' for d in dhcp ]))
allowed = set(['no', 'only'])
if result.difference(allowed):
raise util.HostinfoException("pxeboot (%s) shold be in %s" %
(result, allowed), where=dhcp)
if options.check:
return 'check'
elif len(result) != 1:
raise util.HostinfoException("Mixed pxeboot not allowed (%s)" %
','.join(result),
where=dhcp)
else:
return result.pop()
......@@ -71,7 +71,7 @@ def generate(tree, options):
result = util.StringArray()
dhcp = set([d for d
in tree._host_._interface_._ipv6_._dhcpserver_
if options.host in d.name[0::1]])
if options.check or options.host in d.name[0::1]])
assert dhcp, '%s is not a dhcp6 server' % options.host
pxeboot = get_pxeboot(dhcp)
......
......@@ -19,7 +19,7 @@ def generate(tree, options):
#
emit = False
for ns in tree._host_._interface_._nameserver_:
if ns.name[0:] == options.host:
if options.check or ns.name[0:] == options.host:
# Given host is a nameserver
emit = True
pass
......
Markdown is supported
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