pvl/hosts/zone.py
changeset 733 45bedeba92e5
parent 687 f99f9e3d02cf
child 734 5770ed34c1f0
--- a/pvl/hosts/zone.py	Sat Mar 07 16:31:11 2015 +0200
+++ b/pvl/hosts/zone.py	Mon Mar 09 18:00:18 2015 +0200
@@ -31,15 +31,21 @@
     
     elif host.forward is None:
         # forward
-        if host.ip :
-            log.info("%s: ip: %s@%s A %s", host, label, origin, host.ip)
+        for sublabel, (ip4, ip6) in host.ip.iteritems():
+            if sublabel:
+                sublabel = pvl.dns.join(sublabel, label)
+            else:
+                sublabel = label
+            
+            if ip4:
+                log.info("%s: ip: %s@%s A %s", host, sublabel, origin, ip4)
 
-            yield pvl.dns.ZoneRecord.A(label, host.ip)
+                yield pvl.dns.ZoneRecord.A(sublabel, ip4)
 
-        if host.ip6 :
-            log.info("%s: ip6: %s@%s AAAA %s", host, label, origin, host.ip6)
+            if ip6:
+                log.info("%s: ip6: %s@%s AAAA %s", host, label, origin, ip6)
 
-            yield pvl.dns.ZoneRecord.AAAA(label, host.ip6)
+                yield pvl.dns.ZoneRecord.AAAA(sublabel, ip6)
 
     else:
         log.info("%s: skip forward", host)
@@ -57,10 +63,10 @@
         yield pvl.dns.ZoneRecord.CNAME(pvl.dns.relative(origin, host.domain, alias), label)
 
     for alias in host.alias4:
-        if not host.ip:
-            raise HostZoneError(host, "alias4={host.alias4} without ip=".format(host=host))
+        if not host.ip4:
+            raise HostZoneError(host, "alias4={host.alias4} without ip4=".format(host=host))
 
-        yield pvl.dns.ZoneRecord.A(pvl.dns.relative(origin, host.domain, alias), host.ip)
+        yield pvl.dns.ZoneRecord.A(pvl.dns.relative(origin, host.domain, alias), host.ip4)
 
     for alias in host.alias6:
         if not host.ip6:
@@ -72,50 +78,54 @@
     """
         Yield (ipaddr.IPAddress, ZoneRecord) tuples for host within given prefix's reverse-dns zone.
     """
-
-    if prefix.version == 4 :
-        ip = host.ip
-        
-        # reverse= is IPv4-only
-        reverse = host.reverse
-
-    elif prefix.version == 6 :
-        ip = host.ip6
-        
-        # if reverse= is set, always omit, for lack of reverse6=
-        reverse = None if host.reverse is None else False
-
-    else :
-        raise ValueError("%s: unknown ip version: %s" % (prefix, prefix.version))
-
-    if not ip :
-        log.debug("%s: no ip%d", host, prefix.version)
-        return
+    
+    for sublabel, (ip4, ip6) in host.ip.iteritems():
+        if prefix.version == 4:
+            ip = ip4
+            
+            # reverse= is IPv4-only
+            reverse = host.reverse
 
-    if ip not in prefix :
-        log.debug("%s: %s out of prefix: %s", host, ip, prefix)
-        return
-    
-    # relative label
-    label = pvl.dns.reverse_label(prefix, ip)
-   
-    if reverse:
-        alias = pvl.dns.fqdn(reverse)
-        
-        log.info("%s %s[%s]: CNAME %s", host, prefix, ip, alias)
+        elif prefix.version == 6:
+            ip = ip6
+            
+            # if reverse= is set, always omit, for lack of reverse6=
+            reverse = None if host.reverse is None else False
 
-        yield ip, pvl.dns.zone.ZoneRecord.CNAME(label, alias)
-
-    elif reverse is None :
-        fqdn = host.fqdn()
+        else:
+            raise ValueError("%s: unknown ip version: %s" % (prefix, prefix.version))
 
-        log.info("%s %s[%s]: PTR %s", host, prefix, ip, fqdn)
+        if not ip:
+            log.debug("%s: no ip%d", host, prefix.version)
+            continue
 
-        yield ip, pvl.dns.zone.ZoneRecord.PTR(label, fqdn)
+        if ip not in prefix:
+            log.debug("%s: %s out of prefix: %s", host, ip, prefix)
+            continue
+        
+        # relative label
+        label = pvl.dns.reverse_label(prefix, ip)
+       
+        if reverse:
+            alias = pvl.dns.fqdn(reverse)
+            
+            log.info("%s %s[%s]: CNAME %s", host, prefix, ip, alias)
 
-    else:
-        log.info("%s %s[%s]: omit", host, prefix, ip)
- 
+            yield ip, pvl.dns.zone.ZoneRecord.CNAME(label, alias)
+
+        elif reverse is None:
+            fqdn = host.fqdn()
+
+            if sublabel:
+                fqdn = pvl.dns.join(sublabel, fqdn)
+
+            log.info("%s %s[%s]: PTR %s", host, prefix, ip, fqdn)
+
+            yield ip, pvl.dns.zone.ZoneRecord.PTR(label, fqdn)
+
+        else:
+            log.info("%s %s[%s]: omit", host, prefix, ip)
+     
 def apply_hosts_forward (hosts, origin,
         add_origin      = False,
         check_conflicts = False,