Changeset 13328 in genesis for tools/gformat.py


Ignore:
Timestamp:
Jul 28, 2015, 9:37:33 AM (9 years ago)
Author:
rick
Message:

Adding support for devices like repeaters which are specified in _extraX_ blocks

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r13327 r13328  
    212212    wlan_count=0
    213213    try:
    214       for key in datadump['autogen_iface_keys']:
     214      for key in get_interface_keys(datadump, True):
    215215        datadump[key]['autogen_ifbase'] = key.split('_')[1]
    216216        datadump[key]['autogen_gateway'] = datadump[key]['ip'].split('/')[0]
     
    278278    datadump = get_yaml(host)
    279279    try:
    280       for iface_key in datadump['autogen_iface_keys']:
     280      for iface_key in get_interface_keys(datadump):
    281281        net_addr = network(datadump[iface_key]['ip'])
    282282        poel[net_addr] += [(host,datadump[iface_key].copy())]
     
    515515
    516516  dhcp_out = defaultdict(list)
    517   for iface_key in datadump['autogen_iface_keys']:
     517  for iface_key in get_interface_keys(datadump):
    518518    ifname = datadump[iface_key]['autogen_ifname']
    519519    if not datadump[iface_key].has_key('comment'):
     
    578578\n""").render(datadump)
    579579
    580   for iface_key in datadump['autogen_iface_keys']:
     580  for iface_key in get_interface_keys(datadump):
    581581    if not datadump[iface_key].has_key('comment'):
    582582      datadump[iface_key]['comment'] = None
     
    613613
    614614  masterip_used = False
    615   for iface_key in datadump['autogen_iface_keys']:
     615  for iface_key in get_interface_keys(datadump):
    616616    if datadump[iface_key]['ip'].startswith(datadump['masterip']):
    617617      masterip_used = True
     
    620620    addrs_list['lo0'].append((datadump['masterip'] + "/32", 'Master IP Not used in interface'))
    621621
    622   for iface_key in datadump['autogen_iface_keys']:
     622  for iface_key in get_interface_keys(datadump):
    623623    ifacedump = datadump[iface_key]
    624624    ifname = ifacedump['autogen_ifname']
     
    892892
    893893
    894 def get_interface_keys(config):
     894def get_interface_keys(config, extra=False):
    895895  """ Quick hack to get all interface keys, later stage convert this to a iterator """
    896   return sorted([elem for elem in config.keys() if (elem.startswith('iface_') and not "lo0" in elem)])
     896  elems = sorted([elem for elem in config.keys() if (elem.startswith('iface_') and not "lo0" in elem)])
     897  if extra == False:
     898    return filter(lambda x: not "extra" in x, elems)
     899  else:
     900    return elems
    897901
    898902
     
    902906    for config in configs:
    903907      ip_list.append(config['masterip'])
    904       for iface_key in get_interface_keys(config):
     908      for iface_key in get_interface_keys(config, True):
    905909        l = config[iface_key]['ip']
    906910        addr, mask = l.split('/')
     
    10681072"""
    10691073  table = []
    1070   for iface_key in datadump['autogen_iface_keys']:
     1074  for iface_key in get_interface_keys(datadump, True):
     1075    # Quick to avoid listing ath(4) interface as attached device
     1076    if 'ath0' in iface_key:
     1077      continue
    10711078    ifacedump = datadump[iface_key]
    10721079    if ifacedump.has_key('ns_ip'):
    10731080      x_ip = ifacedump['ns_ip'].split('/')[0]
    1074       x_proto = 'https' if 'M' in ifacedump['bridge_type'] else 'http'
    1075       table.append((ifacedump['autogen_ifname'], ifacedump['mode'], "%s://%s" % (x_proto, x_ip)))
     1081    else:
     1082      x_ip = ifacedump['ip'].split('/')[0]
     1083
     1084    if 'mode' in ifacedump:
     1085      x_mode = ifacedump['mode']
     1086    else:
     1087      x_mode = 'unknown'
     1088
     1089    if 'bridge_type' in ifacedump:
     1090      device_type = ifacedump['bridge_type']
     1091    else:
     1092      device_type = 'Unknown'
     1093
     1094    table.append((ifacedump['autogen_ifname'], x_mode, "http://%s" % x_ip, device_type))
    10761095
    10771096  output += make_table(table)
     
    15041523  print """Usage: %(prog)s <argument>
    15051524Argument:
     1525\tcleanup                      =  Cleanup all YAML files to specified format
    15061526\tstandalone [port]            =  Run configurator webserver [8000]
    15071527\tdns [outputdir]              =  Generate BIND compliant zone files in dns [./dns]
     
    17151735        datadump = get_yaml(host)
    17161736        ip2host[datadump['masterip']] = datadump['autogen_fqdn']
    1717         for iface in datadump['autogen_iface_keys']:
     1737        for iface in get_interface_keys(datadump):
    17181738          ip2host[datadump[iface]['autogen_gateway']] = datadump['autogen_fqdn']
    17191739
     
    19721992            datadump['nodename'] = datadump['nodename'].lower()
    19731993
    1974           for iface_key in datadump['autogen_iface_keys']:
     1994          for iface_key in get_interface_keys(datadump):
    19751995            try:
    19761996              # All our normal wireless cards are normal APs now
     
    20912111          datadump = get_yaml(system)
    20922112          ips = [datadump['masterip']]
    2093           for ifkey in datadump['autogen_iface_keys']:
     2113          for ifkey in get_interface_keys(datadump):
    20942114            ips.append(datadump[ifkey]['ip'].split('/')[0])
    20952115          print system, ' '.join(ips)
Note: See TracChangeset for help on using the changeset viewer.