Changeset 13403 in genesis for tools/gformat.py


Ignore:
Timestamp:
Sep 20, 2015, 7:02:20 PM (9 years ago)
Author:
rick
Message:

Innitial support for vlan configurations, while here get rid of a) deprecated
ipv4_addrs_ notation and b) make debugging more easy on test runs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r13398 r13403  
    214214      for key in get_interface_keys(datadump, True):
    215215        datadump[key]['autogen_ifbase'] = key.split('_')[1]
     216        datadump[key]['autogen_vlan'] = False
     217
    216218        datadump[key]['autogen_gateway'] = datadump[key]['ip'].split('/')[0]
    217219        if datadump[key]['type'] in ['11a', '11b', '11g', 'wireless']:
     
    219221          wlan_count += 1
    220222        else:
    221           datadump[key]['autogen_ifname'] = datadump[key]['autogen_ifbase']
     223          datadump[key]['autogen_ifname'] = '_'.join(key.split('_')[1:])
     224          if len(key.split('_')) > 2 and key.split('_')[2].isdigit():
     225            datadump[key]['autogen_vlan'] = key.split('_')[2]
     226
    222227        datadump[key]['autogen_bridge'] = datadump[key]['autogen_ifbase'].startswith('bridge')
    223228        if datadump[key]['autogen_bridge'] and not 'alias' in key:
    224229          datadump[key]['autogen_bridge_interfaces'] = datadump[key]['members'].split()
    225     except Exception as e:
     230    except Exception:
    226231      print "# Error while processing interface %s" % key
    227232      raise
     
    230235      if dhcp_type(datadump[key]) == DHCP_SERVER]
    231236
    232     datadump['autogen_dhcp_interfaces'] = dhcp_interfaces
     237    datadump['autogen_dhcp_interfaces'] = [x.replace('_','.') for x in dhcp_interfaces]
    233238    datadump['autogen_item'] = item
    234239
     
    237242    datadump['autogen_fqdn'] = datadump['autogen_realname'] + '.' + datadump['autogen_domain']
    238243    datadump_cache[item] = datadump.copy()
    239   except Exception as e:
     244  except Exception:
    240245    print "# Error while processing %s" % item
    241246    raise
     
    607612  #   least one interface, so if not used assign to lo0
    608613  addrs_list = { 'lo0' : [("127.0.0.1/8", "LocalHost"), ("172.31.255.1/32","Proxy IP")] }
     614  vlan_list = defaultdict(list)
    609615  dhclient_if = {'lo0' : False}
    610616
     
    623629    ifacedump = datadump[iface_key]
    624630    ifname = ifacedump['autogen_ifname']
     631
     632    # If defined as vlan interface
     633    if ifacedump['autogen_vlan']:
     634      vlan_list[ifacedump['autogen_ifbase']].append(ifacedump['autogen_vlan'])
    625635
    626636    # Flag dhclient is possible
     
    675685      assert False, "Unknown type " + ifacedump['type']
    676686
    677   store = (addrs_list, dhclient_if, output)
     687  store = (addrs_list, vlan_list, dhclient_if, output)
    678688  interface_list_cache[datadump['autogen_item']] = store
    679689  return(store)
     
    866876""")
    867877
    868   (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
    869   output += extra_ouput.strip() + "\n"
     878  (addrs_list, vlan_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
     879  for iface, vlans in vlan_list.items():
     880    output += 'vlans_%s="%s"\n' % (iface, ' '.join(vlans))
     881
     882  # Details like SSID
     883  if extra_ouput:
     884    output += extra_ouput.strip() + "\n"
    870885
    871886  # Print IP address which needs to be assigned over here
     
    886901        cmp=lambda x,y: cmp(1 if x == '172' else 0, 1 if y == '172' else 0)
    887902      )
    888     addr_str = " ".join([x[0] for x in addrs])
    889     output += "ipv4_addrs_%s='%s'\n\n" % (iface, addr_str)
     903    output += "ifconfig_%s='inet %s'\n" % (iface, addrs[0][0])
     904    for idx, addr in enumerate(addrs[1:]):
     905      output += "ifconfig_%s_alias%s='inet %s'\n" % (iface, idx, addr[0])
     906    output += "\n"
    890907
    891908  rc_conf_local_cache[datadump['autogen_item']] = output
    892909  return output
    893 
    894910
    895911
     
    947963
    948964def get_neighbours(datadump):
    949   (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
     965  (addrs_list, _, dhclient_if, extra_ouput) = make_interface_list(datadump)
    950966
    951967  (poel, errors) = make_relations()
     
    11151131        return lines
    11161132
    1117   (addrs_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
     1133  (addrs_list, vlan_list, dhclient_if, extra_ouput) = make_interface_list(datadump)
    11181134  table = []
    11191135  for iface,addrs in sorted(addrs_list.iteritems()):
     
    12011217          output += "  %-11s: %s\n" % (key, format_yaml_value(datadump[iface_key][key]))
    12021218      output += "\n\n"
    1203     except Exception as e:
     1219    except Exception:
    12041220      print "# Error while processing interface %s" % iface_key
    12051221      raise
     
    16731689      try:
    16741690        node = sys.argv[2]
    1675         datadump = get_yaml(node)
    16761691      except IndexError:
    16771692        print "Invalid argument"
     
    16801695        print e
    16811696        exit(1)
     1697
     1698      datadump = get_yaml(node)
    16821699       
    16831700
     
    20922109                datadump['monitoring_group'] = 'wleiden'
    20932110
    2094             except Exception as e:
     2111            except Exception:
    20952112              print "# Error while processing interface %s" % iface_key
    20962113              raise
    20972114          store_yaml(datadump)
    2098         except Exception as e:
     2115        except Exception:
    20992116          print "# Error while processing %s" % host
    21002117          raise
Note: See TracChangeset for help on using the changeset viewer.