pvl/hosts/zone.py
changeset 489 7f1bd12e0d54
parent 487 920394061b6f
child 495 629fc999cc33
--- a/pvl/hosts/zone.py	Thu Feb 26 15:26:26 2015 +0200
+++ b/pvl/hosts/zone.py	Thu Feb 26 15:29:03 2015 +0200
@@ -125,16 +125,22 @@
     else:
         log.info("%s %s[%s]: omit", host, prefix, ip)
  
-def apply_hosts_forward (options, hosts, origin) :
+def apply_hosts_forward (hosts, origin,
+        add_origin  = False,
+) :
     """
         Generate DNS ZoneRecords for for hosts within the given zone origin.
 
         Verifies that there are no overlapping name/type records, or CNAME records from aliases.
 
+            hosts: [Host]       - Host's to render
+            origin: str         - generate records relative to given zone origin
+            add_origin: bool    - generate an explicit $ORIGIN directive
+
         Yields ZoneRecords in Host-order
     """
 
-    if options.add_origin :
+    if add_origin:
         yield pvl.dns.ZoneDirective.build(None, 'ORIGIN', origin)
 
     by_name = dict()
@@ -158,15 +164,23 @@
             # preserve ordering
             yield rr
 
-def apply_hosts_reverse (options, hosts, prefix) :
+def apply_hosts_reverse (hosts, prefix,
+        unknown_host    = None,
+        unknown_domain  = None,
+) :
     """
         Generate DNS ZoneRecords within the given prefix's reverse-dns zone for hosts.
 
+            hosts: [Host]               - Host's to render PTRs for
+            prefix: ipaddr.IPNetwork    - IPv4/IPv6 prefix to render PTRs for within associated in-addr.arpa/ip6.arpa zone
+            unknown_host: str           - render a PTR to the given host @unknown_domain for unassigned IPs within prefix
+            unknown_domain: str         - required if unknown_host is given
+
         Yields ZoneRecords in IPAddress-order
     """
         
-    if options.unknown_host and not options.hosts_domain:
-        raise Exception("--unknown-host requires --hosts-domain")
+    if unknown_host and not unknown_domain:
+        raise ValueError("unknown_host requires unknown_domain=")
     
     # collect data for records
     by_ip = dict()
@@ -179,7 +193,7 @@
             # do not retain order
             by_ip[ip] = rr
 
-    if options.unknown_host :
+    if unknown_host :
         # enumerate all of them
         iter_ips = prefix.iterhosts()
     else :
@@ -189,12 +203,12 @@
         if ip in by_ip :
             yield by_ip[ip]
 
-        elif options.unknown_host:
+        elif unknown_host:
             # synthesize a record
             label = pvl.dns.reverse_label(prefix, ip)
-            fqdn = pvl.dns.fqdn(options.unknown_host, options.hosts_domain)
+            fqdn = pvl.dns.fqdn(unknown_host, unknown_domain)
 
-            log.info("%s %s[%s]: unused PTR %s", options.unknown_host, ip, prefix, fqdn)
+            log.info("%s %s[%s]: unused PTR %s", unknown_host, ip, prefix, fqdn)
 
             yield pvl.dns.ZoneRecord.PTR(label, fqdn)