pvl.hosts-dns: implement --add-origin
authorTero Marttila <terom@paivola.fi>
Thu, 19 Dec 2013 19:30:35 +0200
changeset 324 9b9c662f36b2
parent 323 9b3cbd8687eb
child 325 9be2b216e87c
pvl.hosts-dns: implement --add-origin
bin/pvl.hosts-dns
--- a/bin/pvl.hosts-dns	Thu Dec 19 19:30:23 2013 +0200
+++ b/bin/pvl.hosts-dns	Thu Dec 19 19:30:35 2013 +0200
@@ -7,7 +7,7 @@
 import fnmatch
 import ipaddr
 import logging; log = logging.getLogger('pvl.hosts-dns')
-import optparse
+import optparse 
 
 def process_hosts_alias (options, origin, host_domain, alias, host) :
     """
@@ -68,18 +68,21 @@
         for alias6 in host.alias6 :
             yield process_hosts_alias(options, origin, host.domain,  alias6, host.ALIAS6_FMT.format(host=label))
 
-def process_hosts_forward (options, hosts, domain) :
+def process_hosts_forward (options, hosts, origin) :
     """
-        Generate DNS ZoneRecords for the given domain's zone for hosts.
+        Generate DNS ZoneRecords for for hosts within the given zone origin.
     """
 
+    if options.add_origin :
+        yield pvl.dns.zone.ZoneDirective.build(None, 'ORIGIN', origin)
+
     by_name = dict()
     by_name_type = dict()
     
     # list of types thare are allowed to be present for a host
     MULTI_TYPES = ('A', 'AAAA')
 
-    for rr in process_hosts_names(options, hosts, domain) :
+    for rr in process_hosts_names(options, hosts, origin) :
         if (rr.name, rr.type) in by_name_type :
             raise ValueError("%s: duplicate name/type: %s: %s" % (rr.name, rr, by_name_type[(rr.name, rr.type)]))
         elif rr.type in MULTI_TYPES :
@@ -228,6 +231,9 @@
     parser.add_option_group(pvl.args.parser(parser))
     parser.add_option_group(pvl.hosts.optparser(parser))
 
+    parser.add_option('--add-origin',           action='store_true',
+            help="Include $ORIGIN directive in zone")
+
     parser.add_option('--forward-zone',         metavar='DOMAIN',
             help="Generate forward zone for domain")