--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/pvl.hosts-dhcp Mon Dec 16 19:11:58 2013 +0200
@@ -0,0 +1,54 @@
+#!/usr/bin/env python
+
+import pvl.args
+import pvl.hosts
+
+import configobj
+import logging; log = logging.getLogger('pvl.hosts-dhcp')
+import optparse
+
+def process_hosts (options, hosts) :
+ for host in hosts :
+ if host.owner :
+ yield u"# {owner}".format(owner=host.owner)
+
+ for index, ethernet in enumerate(host.ethernet) :
+ if len(host.ethernet) > 1 :
+ yield "host {host}-{index} {{".format(host=host, index=index)
+ else :
+ yield "host {host} {{".format(host=host)
+
+ yield '\toption host-name "{host}";'.format(host=host)
+ yield "\thardware ethernet {ethernet};".format(ethernet=ethernet)
+
+ if host.ip :
+ yield "\tfixed-address {ip};".format(ip=host.ip)
+
+ yield "}"
+
+ yield ""
+
+def apply_conf (options, lines) :
+ for line in lines :
+ print line
+
+def main (argv) :
+ """
+ Generate DHCP host configs from host definitions.
+ """
+
+ parser = optparse.OptionParser(main.__doc__)
+ parser.add_option_group(pvl.args.parser(parser))
+ parser.add_option_group(pvl.hosts.optparser(parser))
+
+ options, args = parser.parse_args(argv[1:])
+ pvl.args.apply(options)
+
+ # input
+ hosts = pvl.hosts.apply(options, args)
+
+ # process
+ apply_conf(options, process_hosts(options, hosts))
+
+if __name__ == '__main__':
+ pvl.args.main(main)