bin/pvl.dns-hosts
changeset 264 ce29be46f705
parent 263 5ee3bcd5b4b5
child 265 5f2807999222
equal deleted inserted replaced
263:5ee3bcd5b4b5 264:ce29be46f705
   130                 log.warn("host %s: ignore unknown option: %s", host, option)
   130                 log.warn("host %s: ignore unknown option: %s", host, option)
   131         else :
   131         else :
   132             log.warn("host %s: ignore unknown item: %s", host, item)
   132             log.warn("host %s: ignore unknown item: %s", host, item)
   133 
   133 
   134     # determine hostname
   134     # determine hostname
   135     if hostname :
   135     suffix = None
   136         pass
   136 
   137     elif fixed_address and not re.match(r'\d+\.\d+\.\d+.\d+', fixed_address) :
   137     if '-' in host :
   138         hostname, domain = fixed_address.split('.', 1)
       
   139     elif '-' in host :
       
   140         hostname, suffix = host.rsplit('-', 1)
   138         hostname, suffix = host.rsplit('-', 1)
   141     else :
   139     else :
   142         log.warn("%s: guess hostname: %s", host, host)
       
   143         hostname = host
   140         hostname = host
   144 
   141 
   145     if hostname :
   142     if fixed_address and not re.match(r'\d+\.\d+\.\d+.\d+', fixed_address) :
       
   143         hostname, domain = fixed_address.split('.', 1)
       
   144 
       
   145     #if suffix :
       
   146     #    yield hostname, 'ethernet:{suffix}'.format(suffix=suffix), ethernet
       
   147     if hostname and ethernet :
   146         yield hostname, 'ethernet', ethernet
   148         yield hostname, 'ethernet', ethernet
       
   149     else :
       
   150         log.warn("%s: no hostname/ethernet: %s/%s", host, hostname, ethernet)
   147 
   151 
   148 def import_dhcp_hosts (options, blocks) :
   152 def import_dhcp_hosts (options, blocks) :
   149     """
   153     """
   150         Process hosts from a parsed block
   154         Process hosts from a parsed block
   151     """
   155     """
   267     """
   271     """
   268         Return (owner, comment) for host based on info, or None.
   272         Return (owner, comment) for host based on info, or None.
   269     """
   273     """
   270 
   274 
   271     if info.get('owner').lower() in NONE_OWNERS :
   275     if info.get('owner').lower() in NONE_OWNERS :
   272         return
   276         return False
   273     
   277     
   274     # from ldap?
   278     # from ldap?
   275     for ldap in process_host_owner_ldap(options, host, info) :
   279     for ldap in process_host_owner_ldap(options, host, info) :
   276         user, group = ldap
   280         user, group = ldap
   277         
   281         
   293 
   297 
   294     log.debug("%s: %s", host, info)
   298     log.debug("%s: %s", host, info)
   295     
   299     
   296     owner = process_host_owner(options, host, info) 
   300     owner = process_host_owner(options, host, info) 
   297 
   301 
   298     if owner :
   302     if owner is False :
       
   303         # do not mark any owner
       
   304         pass
       
   305 
       
   306     elif owner :
   299         owner, comment = owner
   307         owner, comment = owner
   300         
   308         
   301         log.info("%s: %s (%s)", host, owner, comment)
   309         log.info("%s: %s (%s)", host, owner, comment)
   302         
   310         
   303         yield 'owner-comment', comment
   311         yield 'owner-comment', comment
   304         yield 'owner', owner,
   312         yield 'owner', owner,
       
   313 
   305     else :
   314     else :
   306         log.warn("%s: no owner: %s", host, info)
   315         log.warn("%s: unknown owner: %s", host, info)
       
   316         yield 'comment', "owner: {group} / {owner}".format(
       
   317                 group   = info.get('group', ''),
       
   318                 owner   = info.get('owner', ''),
       
   319         )
   307     
   320     
   308     if info.get('host') :
   321     if info.get('host') :
   309         yield 'comment', info['host']
   322         yield 'comment', info['host']
   310 
   323 
   311 def process_hosts_comments (options, import_hosts) :
   324 def process_hosts_comments (options, import_hosts) :