Changeset 10872 in genesis


Ignore:
Timestamp:
May 15, 2012, 11:00:04 PM (13 years ago)
Author:
rick
Message:

Bouw een paar debug trucjes in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10863 r10872  
    9898
    9999def get_yaml(item):
    100   """ Get configuration yaml for 'item'"""
    101   if datadump_cache.has_key(item):
    102     return datadump_cache[item].copy()
    103 
    104   gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
    105 
    106   datadump = {}
    107   f = open(gfile, 'r')
    108   datadump.update(yaml.load(f,Loader=Loader))
    109   if datadump['nodetype'] == 'Hybrid':
    110     # Some values are defined implicitly
    111     if datadump.has_key('rdr_rules') and datadump['rdr_rules'] and not datadump.has_key('service_incoming_rdr'):
    112       datadump['service_incoming_rdr'] = True
    113     # Use some boring defaults
    114     defaults = {
    115       'service_proxy_normal' : False,
    116       'service_proxy_ileiden' : False,
    117       'service_accesspoint' : True,
    118       'service_incoming_rdr' : False
    119     }
    120     for (key,value) in defaults.iteritems():
    121       if not datadump.has_key(key):
    122         datadump[key] = value
    123   f.close()
    124 
    125   # Preformat certain needed variables for formatting and push those into special object
    126   datadump['autogen_iface_keys'] = get_interface_keys(datadump)
    127 
    128   wlan_count=0
    129   for key in datadump['autogen_iface_keys']:
    130     if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']:
    131       datadump[key]['autogen_ifname'] = 'wlan%i' % wlan_count
    132       wlan_count += 1
    133     else:
    134       datadump[key]['autogen_ifname'] = datadump[key]['interface'].split(':')[0]
    135 
    136   dhcp_interfaces = [datadump[key]['autogen_ifname'] for key in datadump['autogen_iface_keys'] if (datadump[key].has_key('dhcp') and datadump[key]['dhcp'])]
    137   datadump['autogen_dhcp_interfaces'] = dhcp_interfaces
    138   datadump['autogen_item'] = item
    139 
    140   datadump['autogen_realname'] = get_realname(datadump)
    141   datadump['autogen_domain'] = datadump['domain'] if datadump.has_key('domain') else 'wleiden.net.'
    142   datadump['autogen_fqdn'] = datadump['autogen_realname'] + '.' + datadump['autogen_domain']
    143   datadump_cache[item] = datadump.copy()
     100  try:
     101    """ Get configuration yaml for 'item'"""
     102    if datadump_cache.has_key(item):
     103      return datadump_cache[item].copy()
     104
     105    gfile = os.path.join(NODE_DIR,item,'wleiden.yaml')
     106
     107    datadump = {}
     108    f = open(gfile, 'r')
     109    datadump.update(yaml.load(f,Loader=Loader))
     110    if datadump['nodetype'] == 'Hybrid':
     111      # Some values are defined implicitly
     112      if datadump.has_key('rdr_rules') and datadump['rdr_rules'] and not datadump.has_key('service_incoming_rdr'):
     113        datadump['service_incoming_rdr'] = True
     114      # Use some boring defaults
     115      defaults = {
     116        'service_proxy_normal' : False,
     117        'service_proxy_ileiden' : False,
     118        'service_accesspoint' : True,
     119        'service_incoming_rdr' : False
     120      }
     121      for (key,value) in defaults.iteritems():
     122        if not datadump.has_key(key):
     123          datadump[key] = value
     124    f.close()
     125
     126    # Preformat certain needed variables for formatting and push those into special object
     127    datadump['autogen_iface_keys'] = get_interface_keys(datadump)
     128
     129    wlan_count=0
     130    try:
     131      for key in datadump['autogen_iface_keys']:
     132        if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']:
     133          datadump[key]['autogen_ifname'] = 'wlan%i' % wlan_count
     134          wlan_count += 1
     135        else:
     136          datadump[key]['autogen_ifname'] = datadump[key]['interface'].split(':')[0]
     137    except Exception as e:
     138      print "# Error while processing interface %s" % key
     139      raise
     140
     141    dhcp_interfaces = [datadump[key]['autogen_ifname'] for key in datadump['autogen_iface_keys'] if (datadump[key].has_key('dhcp') and datadump[key]['dhcp'])]
     142    datadump['autogen_dhcp_interfaces'] = dhcp_interfaces
     143    datadump['autogen_item'] = item
     144
     145    datadump['autogen_realname'] = get_realname(datadump)
     146    datadump['autogen_domain'] = datadump['domain'] if datadump.has_key('domain') else 'wleiden.net.'
     147    datadump['autogen_fqdn'] = datadump['autogen_realname'] + '.' + datadump['autogen_domain']
     148    datadump_cache[item] = datadump.copy()
     149  except Exception as e:
     150    print "# Error while processing %s" % item
     151    raise
    144152  return datadump
    145153
     
    12631271\tstatic [outputdir]           =  Generate all config files and store on disk
    12641272\t                                with format ./<outputdir>/%%NODE%%/%%FILE%% [./static]
    1265 \ttest <node> <file>           =  Receive output of CGI script.
     1273\ttest <node> [<file>]         =  Receive output for certain node [all files].
     1274\ttest-cgi <node> <file>       =  Receive output of CGI script [all files].
    12661275\tlist <status> <items>        =  List systems which have certain status
    12671276
     
    13351344        logger.info("All done goodbye")
    13361345    elif sys.argv[1] == "test":
     1346      # Basic argument validation
     1347      try:
     1348        node = sys.argv[2]
     1349        datadump = get_yaml(node)
     1350      except IndexError:
     1351        print "Invalid argument"
     1352        exit(1)
     1353      except IOError as e:
     1354        print e
     1355        exit(1)
     1356       
     1357
     1358      # Get files to generate
     1359      gen_files = sys.argv[3:] if len(sys.argv) > 3 else files
     1360
     1361      # Actual config generation
     1362      for config in gen_files:
     1363         logger.info("## Generating %s %s", node, config)
     1364         print generate_config(node, config, datadump)
     1365    elif sys.argv[1] == "test-cgi":
    13371366      os.environ['PATH_INFO'] = "/".join(sys.argv[2:])
    13381367      os.environ['SCRIPT_NAME'] = __file__
Note: See TracChangeset for help on using the changeset viewer.