--- a/bin/pvl.hosts-import Thu Dec 19 03:06:51 2013 +0200
+++ b/bin/pvl.hosts-import Thu Dec 19 17:38:08 2013 +0200
@@ -125,13 +125,17 @@
origin = options.import_zone_origin or os.path.basename(file.name)
- for rr in pvl.dns.zone.ZoneRecord.load(file,
+ for line, rr in pvl.dns.zone.ZoneLine.load(file,
# used to determine domain
origin = origin,
- # generated hosts need to imported by hand...
- expand_generate = False,
+ # lazy-import generated hosts on demand
+ expand_generate = True,
) :
+ if not rr :
+ log.warn("%s: skip non-rr line: %s", line, line.line)
+ continue
+
host, domain = import_zone_host_name(options, rr.name, rr.origin)
if options.zone_unused and rr.name == options.zone_unused :
@@ -148,6 +152,10 @@
if rr.comment :
yield (host, domain), 'comment', rr.comment
+ if line.parts[0] == '$GENERATE' :
+ # only import as host if used for other purposes as well
+ yield (host, domain), 'lazy-import', True
+
elif rr.type == 'CNAME' :
alias, = rr.data
alias_host, alias_domain = import_zone_host_name(options, alias, rr.origin)
@@ -523,6 +531,16 @@
log.debug("%s@%s: %s.*: %s", host, domain, field_prefix, value)
host_fields[field_prefix] = values
+ lazy_import = fields.get(tuple('lazy-import'.split('.')))
+
+ if not lazy_import :
+ pass
+ elif set(host_fields) == set([('ip', )]) :
+ log.info("%s: omit lazy-import with fields: %s", host, ' '.join('.'.join(field) for field in host_fields))
+ continue
+ else :
+ log.info("%s: import lazy-import with fields: %s", host, ' '.join('.'.join(field) for field in host_fields))
+
yield (host, domain), host_fields
def apply_import_hosts (options) :