bin/pvl.hosts-dns
changeset 273 c8deaa9a2746
parent 272 5755f9c54135
child 278 2db1a5323f92
--- a/bin/pvl.hosts-dns	Mon Dec 16 19:27:22 2013 +0200
+++ b/bin/pvl.hosts-dns	Mon Dec 16 19:32:40 2013 +0200
@@ -8,9 +8,9 @@
 import logging; log = logging.getLogger('pvl.hosts-dns')
 import optparse
 
-def process_hosts_forward (options, hosts, domain) :
+def process_hosts_names (options, hosts, domain) :
     """
-        Generate DNS ZoneRecords for the given domain's zone for hosts.
+        Yield ZoneRecords for the given domain's hosts.
     """
 
     for host in hosts :
@@ -23,6 +23,22 @@
         for alias in host.alias :
             yield pvl.dns.zone.ZoneRecord.CNAME(alias, host)
 
+def process_hosts_forward (options, hosts, domain) :
+    """
+        Generate DNS ZoneRecords for the given domain's zone for hosts.
+    """
+
+    by_name = dict()
+
+    for rr in process_hosts_names(options, hosts, domain) :
+        if rr.name in by_name :
+            raise ValueError("%s: duplicate name: %s: %s" % (rr.name, rr, by_name[rr.name]))
+        else :
+            by_name[rr.name] = rr
+        
+        # preserve ordering
+        yield rr
+
 def process_hosts_ips (options, hosts, prefix) :
     """
         Yield (ip, fqnd) for hosts within given prefix.