pvl/hosts/zone.py
changeset 740 74352351d6f5
parent 734 5770ed34c1f0
equal deleted inserted replaced
739:5149c39f3dfc 740:74352351d6f5
     1 """
     1 """
     2     Generate zonefile records from hosts
     2     Generate zonefile records from hosts
     3 """
     3 """
     4 
     4 
     5 import ipaddr
       
     6 import logging; log = logging.getLogger('pvl.hosts.zone')
     5 import logging; log = logging.getLogger('pvl.hosts.zone')
     7 import pvl.dns
     6 import pvl.dns
     8 import pvl.hosts.host
     7 import pvl.hosts.host
     9 
     8 
    10 class HostZoneError(pvl.hosts.host.HostError):
     9 class HostZoneError(pvl.hosts.host.HostError):
    77 
    76 
    78         yield pvl.dns.ZoneRecord.AAAA(pvl.dns.relative(origin, host.domain, alias), host.ip6)
    77         yield pvl.dns.ZoneRecord.AAAA(pvl.dns.relative(origin, host.domain, alias), host.ip6)
    79 
    78 
    80 def host_reverse (host, prefix) :
    79 def host_reverse (host, prefix) :
    81     """
    80     """
    82         Yield (ipaddr.IPAddress, ZoneRecord) tuples for host within given prefix's reverse-dns zone.
    81         Yield (ipaddress.IPAddress, ZoneRecord) tuples for host within given prefix's reverse-dns zone.
    83     """
    82     """
    84     
    83     
    85     for sublabel, ip in host.addresses():
    84     for sublabel, ip in host.addresses():
    86         if ip.version != prefix.version:
    85         if ip.version != prefix.version:
    87             continue
    86             continue
   166 ) :
   165 ) :
   167     """
   166     """
   168         Generate DNS ZoneRecords within the given prefix's reverse-dns zone for hosts.
   167         Generate DNS ZoneRecords within the given prefix's reverse-dns zone for hosts.
   169 
   168 
   170             hosts: [Host]               - Host's to render PTRs for
   169             hosts: [Host]               - Host's to render PTRs for
   171             prefix: ipaddr.IPNetwork    - IPv4/IPv6 prefix to render PTRs for within associated in-addr.arpa/ip6.arpa zone
   170             prefix: ipaddress.IPNetwork - IPv4/IPv6 prefix to render PTRs for within associated in-addr.arpa/ip6.arpa zone
   172             unknown_host: str           - render a PTR to the given host @unknown_domain for unassigned IPs within prefix
   171             unknown_host: str           - render a PTR to the given host @unknown_domain for unassigned IPs within prefix
   173             unknown_domain: str         - required if unknown_host is given
   172             unknown_domain: str         - required if unknown_host is given
   174 
   173 
   175         Yields ZoneRecords in IPAddress-order
   174         Yields ZoneRecords in IPAddress-order
   176     """
   175     """
   189             # do not retain order
   188             # do not retain order
   190             by_ip[ip] = rr
   189             by_ip[ip] = rr
   191 
   190 
   192     if unknown_host :
   191     if unknown_host :
   193         # enumerate all of them
   192         # enumerate all of them
   194         iter_ips = prefix.iterhosts()
   193         iter_ips = prefix.hosts()
   195     else :
   194     else :
   196         iter_ips = sorted(by_ip)
   195         iter_ips = sorted(by_ip)
   197 
   196 
   198     for ip in iter_ips :
   197     for ip in iter_ips :
   199         if ip in by_ip :
   198         if ip in by_ip :