diff -r 51983fcda6b1 -r a76571e27c6f bin/pvl.hosts-reverse --- a/bin/pvl.hosts-reverse Wed Feb 25 15:49:11 2015 +0200 +++ b/bin/pvl.hosts-reverse Wed Feb 25 15:55:23 2015 +0200 @@ -1,6 +1,42 @@ #!/usr/bin/env python +import logging; log = logging.getLogger('pvl.hosts-reverse') +import optparse +import pvl.args +import pvl.hosts import pvl.hosts.zone -import sys -sys.exit(pvl.hosts.zone.reverse_main()) +def main (argv): + """ + Generate bind zonefiles from host definitions. + """ + + parser = optparse.OptionParser(main.__doc__) + parser.add_option_group(pvl.args.parser(parser)) + parser.add_option_group(pvl.hosts.config.optparser(parser)) + + parser.add_option('--reverse-zone', metavar='PREFIX', + help="Generate reverse zone for prefix") + + parser.add_option('--unknown-host', metavar='NAME', + help="Generate records for unused IPs") + + # input + options, args = pvl.args.parse(parser, argv) + + if not options.reverse_zone: + log.fatal("required --reverse-zone") + return 1 + + hosts = pvl.hosts.apply(options, args) + + # process + prefix = pvl.dns.parse_prefix(options.reverse_zone) + + for rr in pvl.hosts.zone.apply_hosts_reverse(options, hosts, prefix): + print unicode(rr) + + return 0 + +if __name__ == '__main__': + pvl.args.main(main)