bin/pvl.hosts-import
changeset 279 1b72f1e0cdbe
parent 275 4dc5cc30a278
child 280 8118854bfa6f
equal deleted inserted replaced
278:2db1a5323f92 279:1b72f1e0cdbe
    89 def import_zone_hosts (options, file) :
    89 def import_zone_hosts (options, file) :
    90     """
    90     """
    91         Yield host info from zonefile records.
    91         Yield host info from zonefile records.
    92     """
    92     """
    93 
    93 
    94     for rr in pvl.dns.zone.ZoneRecord.load(file) :
    94     for rr in pvl.dns.zone.ZoneRecord.load(file,
       
    95             # generated hosts need to imported by hand...
       
    96             expand_generate = False,
       
    97     ) :
    95         if options.zone_unused and rr.name == options.zone_unused :
    98         if options.zone_unused and rr.name == options.zone_unused :
    96             log.debug("%s: skip %s", rr.name, rr)
    99             log.debug("%s: skip %s", rr.name, rr)
    97             continue
   100             continue
    98 
   101 
    99         elif rr.type in ('A', 'AAAA') :
   102         elif rr.type in ('A', 'AAAA') :
   219     for regex in ZONE_COMMENTS :
   222     for regex in ZONE_COMMENTS :
   220         match = regex.match(comment)
   223         match = regex.match(comment)
   221 
   224 
   222         if match :
   225         if match :
   223             matches = match.groupdict()
   226             matches = match.groupdict()
       
   227 
       
   228             log.info("%s: matched comment: %s", hostname, comment)
   224             break
   229             break
   225     else :
   230     else :
   226         if options.zone_comments_default :
   231         if options.zone_comments_default :
   227             log.warn("%s: default comment: %s", hostname, comment)
   232             log.info("%s: default comment: %s", hostname, comment)
   228             matches = { options.zone_comments_default: comment }
   233             matches = { options.zone_comments_default: comment }
   229         else :
   234         else :
   230             log.warn("%s: unknown comment: %s", hostname, comment)
   235             log.warn("%s: unknown comment: %s", hostname, comment)
   231             return
   236             return
   232     
   237     
   325         log.info("%s: %s (%s)", host, owner, comment)
   330         log.info("%s: %s (%s)", host, owner, comment)
   326         
   331         
   327         yield 'comment-owner', comment
   332         yield 'comment-owner', comment
   328         yield 'owner', owner,
   333         yield 'owner', owner,
   329 
   334 
   330     else :
   335     elif 'group' in info or 'owner' in info :
   331         log.warn("%s: unknown owner: %s", host, info)
   336         log.warn("%s: unknown owner: %s", host, info)
   332         yield 'comment-owner', "{group} / {owner}".format(
   337         yield 'comment-owner', "{group} / {owner}".format(
   333                 group   = info.get('group', ''),
   338                 group   = info.get('group', ''),
   334                 owner   = info.get('owner', ''),
   339                 owner   = info.get('owner', ''),
   335         )
   340         )