Changeset 13324 in genesis
- Timestamp:
- Jul 28, 2015, 8:50:28 AM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r13320 r13324 123 123 rc_conf_local_cache = {} 124 124 nameservers_cache = [] 125 relations_cache = None 125 126 def clear_cache(): 126 127 ''' Poor mans cache implementation ''' … … 132 133 normal_proxies = [] 133 134 nameservers_cache = [] 135 relations_cache = None 134 136 135 137 NO_DHCP = 0 … … 263 265 264 266 265 def make_relations( datadumps=dict()):267 def make_relations(): 266 268 """ Process _ALL_ yaml files to get connection relations """ 269 global relations_cache 270 271 if relations_cache: 272 return relations_cache 273 267 274 errors = [] 268 275 poel = defaultdict(list) 269 276 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) 275 279 try: 276 280 for iface_key in datadump['autogen_iface_keys']: 277 281 net_addr = network(datadump[iface_key]['ip']) 278 poel[net_addr] += [(host,datadump[iface_key] )]282 poel[net_addr] += [(host,datadump[iface_key].copy())] 279 283 except (KeyError, ValueError), e: 280 284 errors.append("[FOUT] in '%s' interface '%s' (%s)" % (host,iface_key, e)) 281 285 continue 282 return (poel, errors) 286 287 relations_cache = (poel, errors) 288 return relations_cache 283 289 284 290 … … 1061 1067 if not has_item: 1062 1068 output += " - none\n" 1069 1070 output += '\n' 1071 output += """\ 1072 Available 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 1063 1100 1064 1101 return output
Note:
See TracChangeset
for help on using the changeset viewer.