Changeset 10881 in genesis for tools


Ignore:
Timestamp:
May 16, 2012, 7:26:42 PM (13 years ago)
Author:
rick
Message:

Make the interface keys wat meer standaard.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10880 r10881  
    158158  gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
    159159
     160  output = generate_wleiden_yaml(datadump, header)
     161
    160162  f = open(gfile, 'w')
    161   f.write(generate_wleiden_yaml(datadump, header))
     163  f.write(output)
    162164  f.close()
    163165
     
    930932  output += "\n\n"
    931933
    932   key_order = [ 'comment', 'interface', 'ip', 'sdesc', 'mode', 'type',
    933     'extra_type', 'channel', 'ssid', 'dhcp' ]
     934  # Format (key, required)
     935  key_order = (
     936    ('comment', True),
     937    ('interface', True),
     938    ('ip', True),
     939    ('desc', True),
     940    ('sdesc', True),
     941    ('mode', True),
     942    ('type', True),
     943    ('extra_type', False),
     944    ('channel', False),
     945    ('ssid', False),
     946    ('dhcp', True),
     947    ('dhcpclient', False),
     948    ('compass', False),
     949    ('distance', False),
     950    ('ns_ip', False),
     951    ('bullet2_ip', False),
     952    ('ns_mac', False),
     953    ('bullet2_mac', False),
     954    ('ns_ssid', False),
     955    ('ns_type', False),
     956    ('status', True),
     957  )
    934958
    935959  for iface_key in sorted(iface_keys):
    936     output += "%s:\n" % iface_key
    937     for key in key_order + list(sorted(set(datadump[iface_key].keys()) - set(key_order))):
    938       if datadump[iface_key].has_key(key):
    939         output += "  %-11s: %s\n" % (key, format_yaml_value(datadump[iface_key][key]))
    940     output += "\n\n"
     960    try:
     961      remainder = set(datadump[iface_key].keys()) - set([x[0] for x in key_order])
     962      if remainder:
     963        raise KeyError("invalid keys: %s" % remainder)
     964
     965      output += "%s:\n" % iface_key
     966      for key,required in key_order:
     967        if datadump[iface_key].has_key(key):
     968          output += "  %-11s: %s\n" % (key, format_yaml_value(datadump[iface_key][key]))
     969      output += "\n\n"
     970    except Exception as e:
     971      print "# Error while processing interface %s" % iface_key
     972      raise
    941973
    942974  return output
     
    14341466
    14351467      for host,datadump in datadumps.iteritems():
    1436         # Convert all yes and no to boolean values
    1437         def fix_boolean(dump):
    1438           for key in dump.keys():
    1439             if type(dump[key]) == dict:
    1440               dump[key] = fix_boolean(dump[key])
    1441             elif str(dump[key]).lower() in ["yes", "true"]:
    1442               dump[key] = True
    1443             elif str(dump[key]).lower() in ["no", "false"]:
    1444               # Compass richting no (Noord Oost) is valid input
    1445               if key != "compass": dump[key] = False
    1446           return dump
    1447         datadump = fix_boolean(datadump)
    1448 
    1449         if datadump['rdnap_x'] and datadump['rdnap_y']:
    1450           datadump['latitude'], datadump['longitude'] = rdnap.rd2etrs(datadump['rdnap_x'], datadump['rdnap_y'])
    1451         elif datadump['latitude'] and datadump['longitude']:
    1452           datadump['rdnap_x'], datadump['rdnap_y'] = rdnap.etrs2rd(datadump['latitude'], datadump['longitude'])
    1453 
    1454         if datadump['nodename'].startswith('Proxy'):
    1455           datadump['nodename'] = datadump['nodename'].lower()
    1456 
    1457         for iface_key in datadump['autogen_iface_keys']:
    1458           # All our normal wireless cards are normal APs now
    1459           if datadump[iface_key]['type'] in ['11a', '11b', '11g', 'wireless']:
    1460             datadump[iface_key]['mode'] = 'ap'
    1461           # Wireless Leiden SSID have an consistent lowercase/uppercase
    1462           if datadump[iface_key].has_key('ssid'):
    1463             ssid = datadump[iface_key]['ssid']
    1464             prefix = 'ap-WirelessLeiden-'
    1465             if ssid.lower().startswith(prefix.lower()):
    1466               datadump[iface_key]['ssid'] = prefix + ssid[len(prefix)].upper() + ssid[len(prefix) + 1:]
    1467           if datadump[iface_key].has_key('ns_ip') and not datadump[iface_key].has_key('mode'):
    1468             datadump[iface_key]['mode'] = 'autogen-FIXME'
    1469           if not datadump[iface_key].has_key('comment'):
    1470             datadump[iface_key]['comment'] = 'autogen-FIXME'
    1471           # Set the compass value based on the angle between the poels
    1472           if datadump[iface_key].has_key('ns_ip'):
    1473             my_pool = poel[network(datadump[iface_key]['ip'])]
    1474             remote_hosts = list(set([x[0] for x in my_pool]) - set([host]))
    1475             if remote_hosts:
    1476               compass_target = remote_hosts[0]
    1477               datadump[iface_key]['compass'] = cd_between_hosts(host, compass_target, datadumps)
    1478            
    1479         store_yaml(datadump)
     1468        try:
     1469          # Convert all yes and no to boolean values
     1470          def fix_boolean(dump):
     1471            for key in dump.keys():
     1472              if type(dump[key]) == dict:
     1473                dump[key] = fix_boolean(dump[key])
     1474              elif str(dump[key]).lower() in ["yes", "true"]:
     1475                dump[key] = True
     1476              elif str(dump[key]).lower() in ["no", "false"]:
     1477                # Compass richting no (Noord Oost) is valid input
     1478                if key != "compass": dump[key] = False
     1479            return dump
     1480          datadump = fix_boolean(datadump)
     1481
     1482          if datadump['rdnap_x'] and datadump['rdnap_y']:
     1483            datadump['latitude'], datadump['longitude'] = rdnap.rd2etrs(datadump['rdnap_x'], datadump['rdnap_y'])
     1484          elif datadump['latitude'] and datadump['longitude']:
     1485            datadump['rdnap_x'], datadump['rdnap_y'] = rdnap.etrs2rd(datadump['latitude'], datadump['longitude'])
     1486
     1487          if datadump['nodename'].startswith('Proxy'):
     1488            datadump['nodename'] = datadump['nodename'].lower()
     1489
     1490          for iface_key in datadump['autogen_iface_keys']:
     1491            # All our normal wireless cards are normal APs now
     1492            if datadump[iface_key]['type'] in ['11a', '11b', '11g', 'wireless']:
     1493              datadump[iface_key]['mode'] = 'ap'
     1494            # Wireless Leiden SSID have an consistent lowercase/uppercase
     1495            if datadump[iface_key].has_key('ssid'):
     1496              ssid = datadump[iface_key]['ssid']
     1497              prefix = 'ap-WirelessLeiden-'
     1498              if ssid.lower().startswith(prefix.lower()):
     1499                datadump[iface_key]['ssid'] = prefix + ssid[len(prefix)].upper() + ssid[len(prefix) + 1:]
     1500            if datadump[iface_key].has_key('ns_ip') and not datadump[iface_key].has_key('mode'):
     1501              datadump[iface_key]['mode'] = 'autogen-FIXME'
     1502            if not datadump[iface_key].has_key('comment'):
     1503              datadump[iface_key]['comment'] = 'autogen-FIXME'
     1504            # Set the compass value based on the angle between the poels
     1505            if datadump[iface_key].has_key('ns_ip'):
     1506              my_pool = poel[network(datadump[iface_key]['ip'])]
     1507              remote_hosts = list(set([x[0] for x in my_pool]) - set([host]))
     1508              if remote_hosts:
     1509                compass_target = remote_hosts[0]
     1510                datadump[iface_key]['compass'] = cd_between_hosts(host, compass_target, datadumps)
     1511             
     1512          store_yaml(datadump)
     1513        except Exception as e:
     1514          print "# Error while processing %s" % host
     1515          raise
    14801516    elif sys.argv[1] == "list":
    14811517      use_fqdn = False
Note: See TracChangeset for help on using the changeset viewer.