Changeset 13324 in genesis


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

Starting listing configured neighbours in motd message to make debugging more
easy when logging in.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r13320 r13324  
    123123rc_conf_local_cache = {}
    124124nameservers_cache = []
     125relations_cache = None
    125126def clear_cache():
    126127  ''' Poor mans cache implementation '''
     
    132133  normal_proxies = []
    133134  nameservers_cache = []
     135  relations_cache = None
    134136
    135137NO_DHCP = 0
     
    263265
    264266
    265 def make_relations(datadumps=dict()):
     267def make_relations():
    266268  """ Process _ALL_ yaml files to get connection relations """
     269  global relations_cache
     270
     271  if relations_cache:
     272    return relations_cache
     273
    267274  errors = []
    268275  poel = defaultdict(list)
    269276
    270   if not datadumps:
    271     for host in get_hostlist():
    272       datadumps[host] = get_yaml(host)
    273 
    274   for host, datadump in datadumps.iteritems():
     277  for host in get_hostlist():
     278    datadump = get_yaml(host)
    275279    try:
    276280      for iface_key in datadump['autogen_iface_keys']:
    277281        net_addr = network(datadump[iface_key]['ip'])
    278         poel[net_addr] += [(host,datadump[iface_key])]
     282        poel[net_addr] += [(host,datadump[iface_key].copy())]
    279283    except (KeyError, ValueError), e:
    280284      errors.append("[FOUT] in '%s' interface '%s' (%s)" % (host,iface_key, e))
    281285      continue
    282   return (poel, errors)
     286
     287  relations_cache = (poel, errors)
     288  return relations_cache
    283289
    284290
     
    10611067  if not has_item:
    10621068    output += " - none\n"
     1069
     1070  output += '\n'
     1071  output += """\
     1072Available neighbours:
     1073"""
     1074  (poel, errors) = make_relations()
     1075  table = []
     1076  for iface,addrs in sorted(addrs_list.iteritems()):
     1077    if iface in ['lo0']:
     1078      continue
     1079
     1080    # Some formatting quirks
     1081    iface_len = max(map(len,addrs_list.keys()))
     1082    addr_len = max(map(len,[x[0] for x in [x[0] for x in addrs_list.values()]]))
     1083
     1084    for addr, comment in sorted(addrs,key=lambda x: parseaddr(x[0].split('/')[0])):
     1085      if not addr.startswith('172.'):
     1086        # Avoid listing internet connections as pool
     1087        continue
     1088      for neighbour in poel[network(addr)]:
     1089        if neighbour[0] != datadump['autogen_item']:
     1090          table.append((iface, neighbour[1]['ip'].split('/')[0], neighbour[0] + " (" + neighbour[1]['autogen_ifname'] + ")", neighbour[1]['comment']))
     1091
     1092  if not table:
     1093    # This should be considered very odd as it indicate no active connections to other nodes
     1094    output += " - none\n"
     1095  else:
     1096    col_width = [max(len(x) for x in col) for col in zip(*table)]
     1097    for row in table:
     1098      output += " - " + " || ".join("{:{}}".format(x, col_width[i]) for i, x in enumerate(row)) + "\n"
     1099
    10631100
    10641101  return output
Note: See TracChangeset for help on using the changeset viewer.