equal
deleted
inserted
replaced
123 Yield host info from zonefile records. |
123 Yield host info from zonefile records. |
124 """ |
124 """ |
125 |
125 |
126 origin = options.import_zone_origin or os.path.basename(file.name) |
126 origin = options.import_zone_origin or os.path.basename(file.name) |
127 |
127 |
128 for rr in pvl.dns.zone.ZoneRecord.load(file, |
128 for line, rr in pvl.dns.zone.ZoneLine.load(file, |
129 # used to determine domain |
129 # used to determine domain |
130 origin = origin, |
130 origin = origin, |
131 |
131 |
132 # generated hosts need to imported by hand... |
132 # lazy-import generated hosts on demand |
133 expand_generate = False, |
133 expand_generate = True, |
134 ) : |
134 ) : |
|
135 if not rr : |
|
136 log.warn("%s: skip non-rr line: %s", line, line.line) |
|
137 continue |
|
138 |
135 host, domain = import_zone_host_name(options, rr.name, rr.origin) |
139 host, domain = import_zone_host_name(options, rr.name, rr.origin) |
136 |
140 |
137 if options.zone_unused and rr.name == options.zone_unused : |
141 if options.zone_unused and rr.name == options.zone_unused : |
138 log.debug("%s: skip %s", rr.name, rr) |
142 log.debug("%s: skip %s", rr.name, rr) |
139 continue |
143 continue |
145 |
149 |
146 yield (host, domain), type, ipaddr.IPAddress(ip) |
150 yield (host, domain), type, ipaddr.IPAddress(ip) |
147 |
151 |
148 if rr.comment : |
152 if rr.comment : |
149 yield (host, domain), 'comment', rr.comment |
153 yield (host, domain), 'comment', rr.comment |
|
154 |
|
155 if line.parts[0] == '$GENERATE' : |
|
156 # only import as host if used for other purposes as well |
|
157 yield (host, domain), 'lazy-import', True |
150 |
158 |
151 elif rr.type == 'CNAME' : |
159 elif rr.type == 'CNAME' : |
152 alias, = rr.data |
160 alias, = rr.data |
153 alias_host, alias_domain = import_zone_host_name(options, alias, rr.origin) |
161 alias_host, alias_domain = import_zone_host_name(options, alias, rr.origin) |
154 |
162 |
521 |
529 |
522 elif field == field_prefix : |
530 elif field == field_prefix : |
523 log.debug("%s@%s: %s.*: %s", host, domain, field_prefix, value) |
531 log.debug("%s@%s: %s.*: %s", host, domain, field_prefix, value) |
524 host_fields[field_prefix] = values |
532 host_fields[field_prefix] = values |
525 |
533 |
|
534 lazy_import = fields.get(tuple('lazy-import'.split('.'))) |
|
535 |
|
536 if not lazy_import : |
|
537 pass |
|
538 elif set(host_fields) == set([('ip', )]) : |
|
539 log.info("%s: omit lazy-import with fields: %s", host, ' '.join('.'.join(field) for field in host_fields)) |
|
540 continue |
|
541 else : |
|
542 log.info("%s: import lazy-import with fields: %s", host, ' '.join('.'.join(field) for field in host_fields)) |
|
543 |
526 yield (host, domain), host_fields |
544 yield (host, domain), host_fields |
527 |
545 |
528 def apply_import_hosts (options) : |
546 def apply_import_hosts (options) : |
529 """ |
547 """ |
530 Import hosts. |
548 Import hosts. |