pvl.hosts-import: do not import $GENERATE hosts; fix warnings on missing owner comments
authorTero Marttila <terom@paivola.fi>
Mon, 16 Dec 2013 20:25:32 +0200
changeset 279 1b72f1e0cdbe
parent 278 2db1a5323f92
child 280 8118854bfa6f
pvl.hosts-import: do not import $GENERATE hosts; fix warnings on missing owner comments
bin/pvl.hosts-import
pvl/dns/zone.py
--- a/bin/pvl.hosts-import	Mon Dec 16 20:21:30 2013 +0200
+++ b/bin/pvl.hosts-import	Mon Dec 16 20:25:32 2013 +0200
@@ -91,7 +91,10 @@
         Yield host info from zonefile records.
     """
 
-    for rr in pvl.dns.zone.ZoneRecord.load(file) :
+    for rr in pvl.dns.zone.ZoneRecord.load(file,
+            # generated hosts need to imported by hand...
+            expand_generate = False,
+    ) :
         if options.zone_unused and rr.name == options.zone_unused :
             log.debug("%s: skip %s", rr.name, rr)
             continue
@@ -221,10 +224,12 @@
 
         if match :
             matches = match.groupdict()
+
+            log.info("%s: matched comment: %s", hostname, comment)
             break
     else :
         if options.zone_comments_default :
-            log.warn("%s: default comment: %s", hostname, comment)
+            log.info("%s: default comment: %s", hostname, comment)
             matches = { options.zone_comments_default: comment }
         else :
             log.warn("%s: unknown comment: %s", hostname, comment)
@@ -327,7 +332,7 @@
         yield 'comment-owner', comment
         yield 'owner', owner,
 
-    else :
+    elif 'group' in info or 'owner' in info :
         log.warn("%s: unknown owner: %s", host, info)
         yield 'comment-owner', "{group} / {owner}".format(
                 group   = info.get('group', ''),
--- a/pvl/dns/zone.py	Mon Dec 16 20:21:30 2013 +0200
+++ b/pvl/dns/zone.py	Mon Dec 16 20:25:32 2013 +0200
@@ -162,7 +162,7 @@
     data = None # list of data fields
     
     @classmethod
-    def load (cls, file, ttl=None, origin=None, **opts) :
+    def load (cls, file, ttl=None, origin=None, expand_generate=True, **opts) :
         """
             Parse ZoneRecord items from the given zonefile, ignoring non-record lines.
         """
@@ -190,11 +190,14 @@
                     log.info("%s: ttl: %s", line, ttl)
                 
                 elif directive == 'GENERATE' :
-                    # process...
-                    log.info("%s: generate: %s", line, args)
+                    if expand_generate :
+                        # process...
+                        log.info("%s: generate: %s", line, args)
 
-                    for record in process_generate(line, origin, args) :
-                        yield record
+                        for record in process_generate(line, origin, args) :
+                            yield record
+                    else :
+                        log.warn("%s: skip generate: %s", line, args)
 
                 elif directive == 'INCLUDE' :
                     include, = args