pvl/hosts/zone.py
author Tero Marttila <tero.marttila@aalto.fi>
Mon, 02 Mar 2015 13:26:34 +0200
changeset 687 f99f9e3d02cf
parent 686 6416c448a713
child 733 45bedeba92e5
permissions -rw-r--r--
pvl.hosts.zone: make non-CNAME check_conflicts optional
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     1
"""
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     2
    Generate zonefile records from hosts
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     3
"""
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     4
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     5
import ipaddr
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     6
import logging; log = logging.getLogger('pvl.hosts.zone')
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     7
import pvl.dns
487
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
     8
import pvl.hosts.host
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
     9
487
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    10
class HostZoneError(pvl.hosts.host.HostError):
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    11
    pass
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    12
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
    13
# TODO: generate location alias CNAMEs even if host itself is outside origin?
496
530f22575889 pvl.hosts.zone: label=relative() check handles FQDNs
Tero Marttila <tero.marttila@aalto.fi>
parents: 495
diff changeset
    14
def host_forward (host, origin):
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    15
    """
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    16
        Yield ZoneRecords for hosts within the given zone origin
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    17
    """
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    18
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    19
    try:
487
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    20
        label = pvl.dns.relative(origin, host.domain, host.name)
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    21
    except ValueError as error:
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    22
        log.info("%s: skip: %s", host, error)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    23
        return
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    24
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    25
    if host.forward:
463
2cbdb2435487 pvl.hosts.zone: fix pvl.dns.fqdn() and basic tests for host_forward/reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 462
diff changeset
    26
        forward = pvl.dns.fqdn(host.forward)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    27
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    28
        log.info("%s: forward: %s", host, forward)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    29
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    30
        yield pvl.dns.ZoneRecord.CNAME(label, forward)
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    31
    
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    32
    elif host.forward is None:
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    33
        # forward
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    34
        if host.ip :
506
b19104afe1b4 pvl.hosts.zone: better log.info
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    35
            log.info("%s: ip: %s@%s A %s", host, label, origin, host.ip)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    36
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    37
            yield pvl.dns.ZoneRecord.A(label, host.ip)
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    38
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    39
        if host.ip6 :
506
b19104afe1b4 pvl.hosts.zone: better log.info
Tero Marttila <tero.marttila@aalto.fi>
parents: 497
diff changeset
    40
            log.info("%s: ip6: %s@%s AAAA %s", host, label, origin, host.ip6)
467
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    41
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    42
            yield pvl.dns.ZoneRecord.AAAA(label, host.ip6)
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    43
3bb00e5e79d3 pvl.hosts.zone: support combining forward= with alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 466
diff changeset
    44
    else:
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    45
        log.info("%s: skip forward", host)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    46
        return
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    47
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    48
    if host.location:
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    49
        location_alias, location_domain = host.location
471
e4b4458d8061 pvl.hosts: test location domains
Tero Marttila <tero.marttila@aalto.fi>
parents: 470
diff changeset
    50
        
487
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    51
        try:
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    52
            yield pvl.dns.ZoneRecord.CNAME(pvl.dns.relative(origin, location_domain, location_alias), label)
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    53
        except ValueError as error:
920394061b6f pvl.hosts.zone: HostZoneError(HostError), move resolve() to pvl.dns.relative(), and expect HostError's in pvl.hosts-forward/pvl.hosts-reverse
Tero Marttila <tero.marttila@aalto.fi>
parents: 475
diff changeset
    54
            raise HostZoneError(host, error)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    55
466
ad9d512ec1e7 pvl.hosts.zone: test and fix alias=
Tero Marttila <tero.marttila@aalto.fi>
parents: 464
diff changeset
    56
    for alias in host.alias:
495
629fc999cc33 pvl.hosts.zone: alias= labels cannot be out of origin
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    57
        yield pvl.dns.ZoneRecord.CNAME(pvl.dns.relative(origin, host.domain, alias), label)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    58
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    59
    for alias in host.alias4:
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
    60
        if not host.ip:
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
    61
            raise HostZoneError(host, "alias4={host.alias4} without ip=".format(host=host))
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
    62
495
629fc999cc33 pvl.hosts.zone: alias= labels cannot be out of origin
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    63
        yield pvl.dns.ZoneRecord.A(pvl.dns.relative(origin, host.domain, alias), host.ip)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    64
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    65
    for alias in host.alias6:
468
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
    66
        if not host.ip6:
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
    67
            raise HostZoneError(host, "alias6={host.alias6} without ip6=".format(host=host))
3e7cb8dd5708 pvl.hosts.zone: raise HostZoneError on alias4/alias6 without ip/ip6
Tero Marttila <tero.marttila@aalto.fi>
parents: 467
diff changeset
    68
495
629fc999cc33 pvl.hosts.zone: alias= labels cannot be out of origin
Tero Marttila <tero.marttila@aalto.fi>
parents: 489
diff changeset
    69
        yield pvl.dns.ZoneRecord.AAAA(pvl.dns.relative(origin, host.domain, alias), host.ip6)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    70
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    71
def host_reverse (host, prefix) :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    72
    """
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    73
        Yield (ipaddr.IPAddress, ZoneRecord) tuples for host within given prefix's reverse-dns zone.
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    74
    """
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    75
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    76
    if prefix.version == 4 :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    77
        ip = host.ip
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    78
        
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    79
        # reverse= is IPv4-only
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    80
        reverse = host.reverse
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    81
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    82
    elif prefix.version == 6 :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    83
        ip = host.ip6
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    84
        
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    85
        # if reverse= is set, always omit, for lack of reverse6=
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    86
        reverse = None if host.reverse is None else False
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
    87
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    88
    else :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    89
        raise ValueError("%s: unknown ip version: %s" % (prefix, prefix.version))
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    90
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    91
    if not ip :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    92
        log.debug("%s: no ip%d", host, prefix.version)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    93
        return
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    94
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    95
    if ip not in prefix :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    96
        log.debug("%s: %s out of prefix: %s", host, ip, prefix)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    97
        return
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    98
    
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
    99
    # relative label
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   100
    label = pvl.dns.reverse_label(prefix, ip)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   101
   
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   102
    if reverse:
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   103
        alias = pvl.dns.fqdn(reverse)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   104
        
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   105
        log.info("%s %s[%s]: CNAME %s", host, prefix, ip, alias)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   106
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   107
        yield ip, pvl.dns.zone.ZoneRecord.CNAME(label, alias)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   108
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   109
    elif reverse is None :
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   110
        fqdn = host.fqdn()
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   111
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   112
        log.info("%s %s[%s]: PTR %s", host, prefix, ip, fqdn)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   113
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   114
        yield ip, pvl.dns.zone.ZoneRecord.PTR(label, fqdn)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   115
464
f1d3dbf04ca3 pvl.hosts.zone: fix reverse= to be IPv4-only
Tero Marttila <tero.marttila@aalto.fi>
parents: 463
diff changeset
   116
    else:
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   117
        log.info("%s %s[%s]: omit", host, prefix, ip)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   118
 
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   119
def apply_hosts_forward (hosts, origin,
687
f99f9e3d02cf pvl.hosts.zone: make non-CNAME check_conflicts optional
Tero Marttila <tero.marttila@aalto.fi>
parents: 686
diff changeset
   120
        add_origin      = False,
f99f9e3d02cf pvl.hosts.zone: make non-CNAME check_conflicts optional
Tero Marttila <tero.marttila@aalto.fi>
parents: 686
diff changeset
   121
        check_conflicts = False,
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   122
) :
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   123
    """
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   124
        Generate DNS ZoneRecords for for hosts within the given zone origin.
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   125
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   126
        Verifies that there are no overlapping name/type records, or CNAME records from aliases.
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   127
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   128
            hosts: [Host]       - Host's to render
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   129
            origin: str         - generate records relative to given zone origin
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   130
            add_origin: bool    - generate an explicit $ORIGIN directive
687
f99f9e3d02cf pvl.hosts.zone: make non-CNAME check_conflicts optional
Tero Marttila <tero.marttila@aalto.fi>
parents: 686
diff changeset
   131
            check_conflits: bool- raise HostZoneError on dupliate records for the same name/type
f99f9e3d02cf pvl.hosts.zone: make non-CNAME check_conflicts optional
Tero Marttila <tero.marttila@aalto.fi>
parents: 686
diff changeset
   132
                                  overlapping CNAME records will always raise
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   133
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   134
        Yields ZoneRecords in Host-order
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   135
    """
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   136
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   137
    if add_origin:
658
3ecc84d5e779 pvl.hosts.zone: fix add_origin= generated directive
Tero Marttila <terom@paivola.fi>
parents: 506
diff changeset
   138
        yield pvl.dns.ZoneDirective.build('ORIGIN', pvl.dns.fqdn(origin))
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   139
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   140
    by_name = dict()
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   141
    by_name_type = dict()
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   142
    
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   143
    for host in hosts:
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   144
        for rr in host_forward(host, origin) :
472
814cc88c531b pvl.hosts.zone: stricter name/type + name/CNAME -conflict logic
Tero Marttila <tero.marttila@aalto.fi>
parents: 471
diff changeset
   145
            if (rr.name, 'CNAME') in by_name_type:
686
6416c448a713 pvl.hosts.zone: better errors for host forward rr conflicts
Tero Marttila <tero.marttila@aalto.fi>
parents: 658
diff changeset
   146
                raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name_type[rr.name, 'CNAME']))
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   147
            elif rr.type == 'CNAME' and rr.name in by_name:
686
6416c448a713 pvl.hosts.zone: better errors for host forward rr conflicts
Tero Marttila <tero.marttila@aalto.fi>
parents: 658
diff changeset
   148
                raise HostZoneError(host, u"{cname} CNAME conflict with {other}".format(cname=rr.name, other=by_name[rr.name]))
687
f99f9e3d02cf pvl.hosts.zone: make non-CNAME check_conflicts optional
Tero Marttila <tero.marttila@aalto.fi>
parents: 686
diff changeset
   149
            elif check_conflicts and (rr.name, rr.type) in by_name_type:
686
6416c448a713 pvl.hosts.zone: better errors for host forward rr conflicts
Tero Marttila <tero.marttila@aalto.fi>
parents: 658
diff changeset
   150
                raise HostZoneError(host, u"{name} {type} conflict with {other}".format(type=rr.type, name=rr.name, other=by_name_type[rr.name, rr.type]))
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   151
            
686
6416c448a713 pvl.hosts.zone: better errors for host forward rr conflicts
Tero Marttila <tero.marttila@aalto.fi>
parents: 658
diff changeset
   152
            by_name[rr.name] = host
6416c448a713 pvl.hosts.zone: better errors for host forward rr conflicts
Tero Marttila <tero.marttila@aalto.fi>
parents: 658
diff changeset
   153
            by_name_type[rr.name, rr.type] = host
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   154
            
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   155
            # preserve ordering
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   156
            yield rr
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   157
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   158
def apply_hosts_reverse (hosts, prefix,
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   159
        unknown_host    = None,
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   160
        unknown_domain  = None,
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   161
) :
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   162
    """
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   163
        Generate DNS ZoneRecords within the given prefix's reverse-dns zone for hosts.
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   164
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   165
            hosts: [Host]               - Host's to render PTRs for
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   166
            prefix: ipaddr.IPNetwork    - IPv4/IPv6 prefix to render PTRs for within associated in-addr.arpa/ip6.arpa zone
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   167
            unknown_host: str           - render a PTR to the given host @unknown_domain for unassigned IPs within prefix
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   168
            unknown_domain: str         - required if unknown_host is given
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   169
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   170
        Yields ZoneRecords in IPAddress-order
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   171
    """
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   172
        
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   173
    if unknown_host and not unknown_domain:
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   174
        raise ValueError("unknown_host requires unknown_domain=")
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   175
    
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   176
    # collect data for records
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   177
    by_ip = dict()
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   178
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   179
    for host in hosts:
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   180
        for ip, rr in host_reverse(host, prefix) :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   181
            if ip in by_ip :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   182
                raise HostZoneError(host, "{host}: IP {ip} conflict: {other}".format(host=host, ip=ip, other=by_ip[ip]))
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   183
            
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   184
            # do not retain order
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   185
            by_ip[ip] = rr
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   186
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   187
    if unknown_host :
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   188
        # enumerate all of them
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   189
        iter_ips = prefix.iterhosts()
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   190
    else :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   191
        iter_ips = sorted(by_ip)
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   192
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   193
    for ip in iter_ips :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   194
        if ip in by_ip :
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   195
            yield by_ip[ip]
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   196
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   197
        elif unknown_host:
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   198
            # synthesize a record
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   199
            label = pvl.dns.reverse_label(prefix, ip)
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   200
            fqdn = pvl.dns.fqdn(unknown_host, unknown_domain)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   201
489
7f1bd12e0d54 pvl.hosts-reverse: move options out of pvl.hosts.zone
Tero Marttila <tero.marttila@aalto.fi>
parents: 487
diff changeset
   202
            log.info("%s %s[%s]: unused PTR %s", unknown_host, ip, prefix, fqdn)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   203
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   204
            yield pvl.dns.ZoneRecord.PTR(label, fqdn)
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   205
474
51983fcda6b1 pvl.hosts.zone: fix and test --unknown-host
Tero Marttila <tero.marttila@aalto.fi>
parents: 472
diff changeset
   206
        else:
458
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   207
            continue
600ad9eb6f25 pvl.hosts.zone: cleanup and split pvl.hosts-forward and pvl.hosts-reverse from pvl.hosts-dns
Tero Marttila <tero.marttila@aalto.fi>
parents:
diff changeset
   208