--- a/bin/pvl.hosts-forward Thu Feb 26 18:54:15 2015 +0200
+++ b/bin/pvl.hosts-forward Thu Feb 26 18:58:32 2015 +0200
@@ -2,6 +2,7 @@
import logging; log = logging.getLogger('pvl.hosts-forward')
import optparse
+import os.path
import pvl.args
import pvl.hosts
import pvl.hosts.zone
@@ -15,24 +16,38 @@
parser.add_option_group(pvl.args.parser(parser))
parser.add_option_group(pvl.hosts.config.optparser(parser))
- parser.add_option('--forward-zone', metavar='DOMAIN',
- help="Generate forward zone for domain")
+ parser.add_option('--zone-origin', metavar='DOMAIN',
+ help="Generated records for given zone origin")
+
+ parser.add_option('--root-zone', action='store_const', dest='zone_origin', const='.',
+ help="Generate root zone")
parser.add_option('--add-origin', action='store_true',
help="Include $ORIGIN directive in zone")
# input
options, args = pvl.args.parse(parser, argv)
-
- if not options.forward_zone:
- log.fatal("required --forward-zone")
+
+ if options.zone_origin:
+ origin = options.zone_origin
+
+ log.info("using given zone origin: %s", origin)
+
+ elif len(args) == 1:
+ path, = args
+ origin = os.path.basename(path.rstrip('/'))
+
+ log.info("using given hostpath for zone origin: %s", origin)
+
+ else:
+ log.fatal("--zone-origin is required if passing multiple hostfiles")
return 1
hosts = pvl.hosts.apply(options, args)
# process
try:
- for rr in pvl.hosts.zone.apply_hosts_forward(hosts, options.forward_zone,
+ for rr in pvl.hosts.zone.apply_hosts_forward(hosts, origin,
add_origin = options.add_origin,
):
print unicode(rr)