# HG changeset patch # User Tero Marttila # Date 1387482257 -7200 # Node ID 9b4ee4bad3d141947120e918b8ae5fbd06a87741 # Parent 9d7d40206a7451e5e52ecf7d6b92faec01c2c695 pvl.hosts-import: also import --zone-unused=ufc hosts, and output them as special comments diff -r 9d7d40206a74 -r 9b4ee4bad3d1 bin/pvl.hosts-import --- a/bin/pvl.hosts-import Thu Dec 19 21:12:07 2013 +0200 +++ b/bin/pvl.hosts-import Thu Dec 19 21:44:17 2013 +0200 @@ -146,16 +146,16 @@ host, domain = import_zone_host_name(options, rr.name, rr.origin) - if options.zone_unused and rr.name == options.zone_unused : - log.debug("%s: skip %s", rr.name, rr) - continue - - elif rr.type in ('A', 'AAAA') : + if rr.type in ('A', 'AAAA') : ip, = rr.data + ip = ipaddr.IPAddress(ip) type = { 'A': 'ip', 'AAAA': 'ip6' }[rr.type] - yield (host, domain), type, ipaddr.IPAddress(ip) + if options.zone_unused and rr.name == options.zone_unused : + yield (str(ip), domain), 'ip.unused', ip + else : + yield (host, domain), type, ip, if rr.comment : yield (host, domain), 'comment', rr.comment @@ -496,6 +496,7 @@ for (domain, host), fields in hosts.iteritems() : SINGLE_FIELDS = ( 'ip', + 'ip.unused', 'ip6', 'comment.owner', 'owner', @@ -629,8 +630,10 @@ if ip in by_ip : log.warn("%s: duplicate ip %s: %s", host, ip, by_ip[ip]) + elif ip : + by_ip[ip] = host else : - by_ip[ip] = host + log.warn("%s: no ip", host) yield (host, domain), fields @@ -650,7 +653,7 @@ select_domain = None for (host, domain), fields in hosts : - ip = fields.get(('ip', )) + ip = fields.get(('ip', )) or fields.get(('ip', 'unused')) log.debug("%s@%s: ip=%s", host, domain, ip) @@ -700,6 +703,16 @@ yield u"[{domain}]".format(domain=domain) output_domain = domain + # special handling for "unused" hosts + if ('ip', 'unused') in fields : + yield u"{indent}# {unused} {ip}".format( + indent = '\t' if output_domain else '', + unused = options.zone_unused, + ip = fields[('ip', 'unused')], + ) + yield u"" + continue + # optional host-comments for comment in fields.get(('comment', 'host'), ()): yield u"{indent}# {comment}".format(