Changeset 10642 in genesis for tools


Ignore:
Timestamp:
May 1, 2012, 8:55:33 PM (13 years ago)
Author:
rick
Message:

More easy maintenance for static DNS entries.

Q: Why not just use a PLAIN file and store the items just in there?
A: This is not easy parseble by other programs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10627 r10642  
    929929
    930930  # hostname is key, IP is value
    931   wleiden_zone = dict()
     931  wleiden_zone = defaultdict(list)
    932932  wleiden_cname = dict()
    933933
     
    941941      wleiden_cname[datadump['nodename']] = fqdn
    942942
    943     wleiden_zone[fqdn] = datadump['masterip']
     943    wleiden_zone[fqdn].append(datadump['masterip'])
    944944
    945945    # Hacking to get proper DHCP IPs and hostnames
     
    952952        dhcp_part = ".".join(ip.split('.')[0:3])
    953953        if ip != datadump['masterip']:
    954           wleiden_zone["dhcp-gateway-%s.%s" % (iface_name, fqdn)] = ip
     954          wleiden_zone["dhcp-gateway-%s.%s" % (iface_name, fqdn)].append(ip)
    955955        for i in range(int(dhcp_start), int(dhcp_stop) + 1):
    956           wleiden_zone["dhcp-%s-%s.%s" % (i, iface_name, fqdn)] = "%s.%s" % (dhcp_part, i)
     956          wleiden_zone["dhcp-%s-%s.%s" % (i, iface_name, fqdn)].append("%s.%s" % (dhcp_part, i))
    957957      except (AttributeError, ValueError):
    958958        # First push it into a pool, to indentify the counter-part later on
     
    994994    if len(value) == 1:
    995995      (iface_name, fqdn, ip) = value[0]
    996       wleiden_zone["2unused-%s.%s" % (iface_name, fqdn)] = ip
     996      wleiden_zone["2unused-%s.%s" % (iface_name, fqdn)].append(ip)
    997997
    998998      # Device DNS names
    999999      if 'cnode' in fqdn.lower():
    1000         wleiden_zone["d-at-%s.%s" % (iface_name, fqdn)] = showaddr(parseaddr(ip) + 1)
     1000        wleiden_zone["d-at-%s.%s" % (iface_name, fqdn)].append(showaddr(parseaddr(ip) + 1))
    10011001        wleiden_cname["d-at-%s.%s" % (iface_name,sn(fqdn))] = "d-at-%s.%s" % (iface_name, fqdn)
    10021002
     
    10041004      (a_iface_name, a_fqdn, a_ip) = value[0]
    10051005      (b_iface_name, b_fqdn, b_ip) = value[1]
    1006       wleiden_zone["2%s.%s" % (b_fqdn,a_fqdn)] = a_ip
    1007       wleiden_zone["2%s.%s" % (a_fqdn,b_fqdn)] = b_ip
     1006      wleiden_zone["2%s.%s" % (b_fqdn,a_fqdn)].append(a_ip)
     1007      wleiden_zone["2%s.%s" % (a_fqdn,b_fqdn)].append(b_ip)
    10081008
    10091009      # Device DNS names
    10101010      if 'cnode' in a_fqdn.lower() and 'cnode' in b_fqdn.lower():
    1011         wleiden_zone["d-at-%s.%s" % (a_iface_name, a_fqdn)] = showaddr(parseaddr(a_ip) + 1)
    1012         wleiden_zone["d-at-%s.%s" % (b_iface_name, b_fqdn)] = showaddr(parseaddr(b_ip) - 1)
     1011        wleiden_zone["d-at-%s.%s" % (a_iface_name, a_fqdn)].append(showaddr(parseaddr(a_ip) + 1))
     1012        wleiden_zone["d-at-%s.%s" % (b_iface_name, b_fqdn)].append(showaddr(parseaddr(b_ip) - 1))
    10131013        wleiden_cname["d-at-%s.%s" % (a_iface_name,sn(a_fqdn))] = "d-at-%s.%s" % (a_iface_name, a_fqdn)
    10141014        wleiden_cname["d-at-%s.%s" % (b_iface_name,sn(b_fqdn))] = "d-at-%s.%s" % (b_iface_name, b_fqdn)
     
    10211021        (iface_name, fqdn, ip) = item
    10221022        pool_name = "2pool-" + showaddr(key).replace('.','-') + "-" + pool_to_name(fqdn,pool_members)
    1023         wleiden_zone["%s.%s" % (pool_name, fqdn)] = ip
     1023        wleiden_zone["%s.%s" % (pool_name, fqdn)].append(ip)
    10241024
    10251025  # Include static DNS entries
     
    10301030  ## roomburgh=CNodeRoomburgh1
    10311031  ## apkerk1.CNodeVosko=172.17.176.8 ;this as well
    1032   dns = yaml.load(open(os.path.join(NODE_DIR,'../dns/staticDNS.yaml'),'r'))
     1032  dns_list = yaml.load(open(os.path.join(NODE_DIR,'../dns/staticDNS.yaml'),'r'))
    10331033
    10341034  # Hack to allow special entries, for development
    1035   wleiden_raw = dns['raw']
    1036   del dns['raw']
    1037 
    1038   for comment, block in dns.iteritems():
    1039     for k,v in block.iteritems():
    1040       if valid_addr(v):
    1041         wleiden_zone[k] = v
     1035  wleiden_raw = {}
     1036
     1037  for line in dns_list:
     1038    k, items = line.items()[0]
     1039    items = [items] if type(items) == str else items
     1040    for item in items:
     1041      if item.startswith('IN '):
     1042        wleiden_raw[k] = item
     1043      elif valid_addr(item):
     1044        wleiden_zone[k].append(item)
    10421045      else:
    1043         wleiden_cname[k] = v
     1046        wleiden_cname[k] = item
    10441047
    10451048  details = dict()
     
    10701073  f.write(dns_header % details)
    10711074
    1072   for host,ip in wleiden_zone.iteritems():
    1073     if valid_addr(ip):
    1074       f.write("%s.wleiden.net. IN A %s \n" % (host.lower(), ip))
     1075  for host,ips in wleiden_zone.iteritems():
     1076    for ip in ips:
     1077      if valid_addr(ip):
     1078        f.write("%s.wleiden.net. IN A %s \n" % (host.lower(), ip))
    10751079  for source,dest in wleiden_cname.iteritems():
    10761080    f.write("%s.wleiden.net. IN CNAME %s.wleiden.net.\n" % (source.lower(), dest.lower()))
     
    10871091    #XXX: Not effient, fix to proper data structure and do checks at other
    10881092    # stages
    1089     for host,ip in wleiden_zone.iteritems():
    1090       if valid_addr(ip):
    1091         if int(ip.split('.')[1]) == s:
    1092           rev_ip = '.'.join(reversed(ip.split('.')))
    1093           f.write("%s.in-addr.arpa. IN PTR %s.wleiden.net.\n" % (rev_ip.lower(), host.lower()))
     1093    for host,ips in wleiden_zone.iteritems():
     1094      for ip in ips:
     1095        if valid_addr(ip):
     1096          if int(ip.split('.')[1]) == s:
     1097            rev_ip = '.'.join(reversed(ip.split('.')))
     1098            f.write("%s.in-addr.arpa. IN PTR %s.wleiden.net.\n" % (rev_ip.lower(), host.lower()))
    10941099    f.close()
    10951100
Note: See TracChangeset for help on using the changeset viewer.