from common import * def gen_dhcpd_conf(node): dhcpd_conf = gen_header('dhcpd.conf') + """ option domain-name "wLeiden.NET"; default-lease-time 7200; max-lease-time 2592000; ddns-update-style none; # Hack for the WET11 always-broadcast on; option domain-name-servers %s; """ % (showaddr(node.master_ip)) for link in node.links: if link.type != 'public': continue; mask = int(link.mask) (network, broadcast) = decode_mask(link.ip, mask) if not link.__dict__.has_key('dhcp'): continue (range_begin, range_end) = link.dhcp.split('-') range_begin = node.master_ip - 1 + int(range_begin) range_end = node.master_ip - 1 + int(range_end) # bouw een string voor eventuele statische dhcp entries statics = [] for static in link.dhcp_statics: statics.append("host %s{hardware ethernet %s; fixed-address %s;}" % (static.name, static.mac, static.addr)) statics = "\n\t".join(statics) s = """\n# # %s %s # subnet %s netmask %s { authoritative; range %s %s; option broadcast-address %s; option subnet-mask %s; option routers %s; %s }""" % (link.iface.iface, link.desc, showaddr(network), showmask(mask), showaddr(range_begin), showaddr(range_end), showaddr(broadcast), showmask(mask), showaddr(link.ip), statics) dhcpd_conf = dhcpd_conf + s return dhcpd_conf if __name__ == "__main__": nodes = xml_to_obj_hierarchy(sys.argv[1]) ready_nodes_dtd_hierarchy(nodes) node = findnode(nodes, sys.argv[2]) print gen_dhcpd_conf(node)