Changeset 8598 in genesis


Ignore:
Timestamp:
Oct 30, 2010, 11:07:39 PM (14 years ago)
Author:
rick
Message:

Little hack to generate DNS entries again.

XXX: Should more to a more proper location.

Location:
nodes
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • nodes/gformat.py

    r8588 r8598  
    545545def make_dns():
    546546  items = dict()
     547
    547548  # hostname is key, IP is value
    548549  wleiden_zone = dict()
    549550  wleiden_cname = dict()
     551
    550552  pool = dict()
    551553  for node in get_hostlist():
     
    559561    wleiden_zone[fqdn] = datadump['masterip']
    560562
    561     #items['node'] = node
    562     #items['wdir'] = "./static/%(node)s" % items
    563     #if not os.path.isdir(items['wdir']):
    564     #  os.makedirs(items['wdir'])
     563    # Hacking to get proper DHCP IPs and hostnames
    565564    for iface_key in get_interface_keys(datadump):
    566       iface_name = datadump[iface_key]['interface'].replace(':',"_alias_")
     565      iface_name = datadump[iface_key]['interface'].replace(':',"-alias-")
    567566      (ip, netmask) = datadump[iface_key]['ip'].split('/')
    568567      try:
     
    585584        continue
    586585
    587   # wleiden_zone["2%s-%s.%s" % ("unused", iface_name, fqdn)] = ip
    588   # #XXX: automatic naming convention namely 2 + remote.lower()
     586  # Automatic naming convention of interlinks namely 2 + remote.lower()
    589587  for (key,value) in pool.iteritems():
    590588    if len(value) == 1:
     
    600598      for item in value:
    601599        (iface_name, fqdn, ip) = item
    602         pool_name = "2pool-" + showaddr(key).replace('.','-') + "-" + "_".join(sorted(list(set(pool_members) - set([fqdn]))))
     600        pool_name = "2pool-" + showaddr(key).replace('.','-') + "-" + "-".join(sorted(list(set(pool_members) - set([fqdn]))))
    603601        wleiden_zone["%s.%s" % (pool_name, fqdn)] = ip
     602
     603  # Include static DNS entries
     604  # XXX: Should they override the autogenerated results?
     605  # XXX: Convert input to yaml more useable.
     606  # Format:
     607  ##; this is a comment
     608  ## roomburgh=CNodeRoomburgh1
     609  ## apkerk1.CNodeVosko=172.17.176.8 ;this as well
     610  f = open('../dns/staticDNS.conf','r')
     611  for l in f.readlines():
     612    # Get rid of comments
     613    l = l.strip().split(';')[0].strip()
     614    if l:
     615      k,v = l.split('=')
     616      if valid_addr(v):
     617        wleiden_zone[k] = v
     618      else:
     619        wleiden_cname[k] = v
     620  f.close()
    604621     
     622  details = dict()
     623  # 24 updates a day allowed
     624  details['serial'] = time.strftime('%Y%m%d%H')
     625
     626  dns_header = '''
     627$TTL 3h
     628%(zone)s. SOA sunny.wleiden.net. beheer.lijst.wirelessleiden.nl. ( %(serial)s 1d 12h 1w 3h )
     629        ; Serial, Refresh, Retry, Expire, Neg. cache TTL
     630
     631        NS      sunny.wleiden.net.
     632  \n'''
     633
    605634   
    606   f = open("db.wleiden.net", "w")
     635  if not os.path.isdir('dns'):
     636    os.makedirs('dns')
     637  details['zone'] = 'wleiden.net'
     638  f = open("dns/db." + details['zone'], "w")
     639  f.write(dns_header % details)
     640
    607641  for host,ip in wleiden_zone.iteritems():
    608     f.write("%s.wleiden.net. A %s ~\n" % (host, ip))
     642    if valid_addr(ip):
     643      f.write("%s.wleiden.net. IN A %s \n" % (host, ip))
    609644  for source,dest in wleiden_cname.iteritems():
    610     f.write("%s.wleiden.net. CNAME %s.wleiden.net. ~\n" % (source, dest))
     645    f.write("%s.wleiden.net. IN CNAME %s.wleiden.net.\n" % (source, dest))
    611646  f.close()
    612   f = open("db.172.in-addr.arpa", "w")
    613   for host,ip in wleiden_zone.iteritems():
    614     rev_ip = '.'.join(reversed(ip.split('.')))
    615     f.write("%s.in-addr.arpa. PTR %s.wleiden.net. ~\n" % (rev_ip, host))
    616   f.close()
     647 
     648  # Create whole bunch of specific sub arpa zones. To keep it compliant
     649  for s in range(16,32):
     650    details['zone'] = '%i.172.in-addr.arpa' % s
     651    f = open("dns/db." + details['zone'], "w")
     652    f.write(dns_header % details)
     653
     654    #XXX: Not effient, fix to proper data structure and do checks at other
     655    # stages
     656    for host,ip in wleiden_zone.iteritems():
     657      if valid_addr(ip):
     658        if int(ip.split('.')[1]) == s:
     659          rev_ip = '.'.join(reversed(ip.split('.')))
     660          f.write("%s.in-addr.arpa. IN PTR %s.wleiden.net.\n" % (rev_ip, host))
     661    f.close()
    617662
    618663
    619664def usage():
    620   print """Usage: %s <standalone [port] |test [test arguments]|static>
     665  print """Usage: %s <standalone [port] |test [test arguments]|static|dns>
    621666Examples:
     667\tdns                          =  Generate BIND compliant zone files in dns.
    622668\tstandalone                   =  Run configurator webserver [default port=8000]
    623669\tstatic                       =  Generate all config files and store on disk
Note: See TracChangeset for help on using the changeset viewer.