Changeset 10281 in genesis
- Timestamp:
- Mar 27, 2012, 7:19:06 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
tools/gformat.py
r10270 r10281 32 32 import rdnap 33 33 from pprint import pprint 34 from collections import defaultdict 34 35 try: 35 36 import yaml … … 75 76 76 77 77 def make_ graph():78 def make_relations(): 78 79 """ Process _ALL_ yaml files to get connection relations """ 79 80 errors = "" 80 poel = {}81 poel = defaultdict(list) 81 82 for host in get_hostlist(): 82 83 try: … … 92 93 addr = parseaddr(addr) 93 94 mask = int(mask) 94 addr = addr & ~((1 << (32 - mask)) - 1) 95 if poel.has_key(addr): 96 poel[addr] += [host] 97 else: 98 poel[addr] = [host] 95 network = addr & ~((1 << (32 - mask)) - 1) 96 poel[network] += [(host,datadump[iface_key])] 99 97 except (KeyError, ValueError), e: 100 98 errors += "[FOUT] in '%s' interface '%s'" % (host,iface_key) … … 234 232 # Generate and connection listing 235 233 output += "<h2>Connected To:</h2><ul>" 236 (poel, errors) = make_graph() 237 for addr, hosts in poel.iteritems(): 238 if host in hosts and len(hosts) > 1: 239 for remote in [x for x in hosts if x != host]: 240 params = { 'remote': remote} 241 output += '<li><a href="%(remote)s">%(remote)s</a></li>\n' % params 234 (poel, errors) = make_relations() 235 for network, hosts in poel.iteritems(): 236 if host in [x[0] for x in hosts]: 237 if len(hosts) == 1: 238 # Single not connected interface 239 continue 240 for remote,ifacedump in hosts: 241 if remote == host: 242 # This side of the interface 243 continue 244 params = { 'remote': remote, 'remote_ip' : ifacedump['ip'] } 245 output += '<li><a href="%(remote)s">%(remote)s</a> -- %(remote_ip)s</li>\n' % params 242 246 output += "</ul>" 247 output += "<h2>MOTD details:</h2><pre>" + generate_motd(datadump) + "</pre>" 243 248 244 249 output += "<hr /><em><a href='..'>Back to overview</a></em>" … … 305 310 \n""" % datadump 306 311 307 for iface_key in datadump[' iface_keys']:312 for iface_key in datadump['autogen_iface_keys']: 308 313 if not datadump[iface_key].has_key('comment'): 309 314 datadump[iface_key]['comment'] = None … … 408 413 409 414 masterip_used = False 410 for iface_key in datadump[' iface_keys']:415 for iface_key in datadump['autogen_iface_keys']: 411 416 if datadump[iface_key]['ip'].startswith(datadump['masterip']): 412 417 masterip_used = True … … 415 420 addrs_list['lo0'].append((datadump['masterip'] + "/32", 'Master IP Not used in interface')) 416 421 417 for iface_key in datadump[' iface_keys']:422 for iface_key in datadump['autogen_iface_keys']: 418 423 ifacedump = datadump[iface_key] 419 424 ifname = ifacedump['autogen_ifname'] … … 479 484 f = open(gfile, 'r') 480 485 datadump = yaml.load(f,Loader=Loader) 486 f.close() 487 488 # Preformat certain needed variables for formatting and push those into special object 481 489 datadump['autogen_iface_keys'] = get_interface_keys(datadump) 482 490 … … 489 497 datadump[key]['autogen_ifname'] = datadump[key]['interface'].split(':')[0] 490 498 491 492 499 dhcp_interfaces = [datadump[key]['autogen_ifname'] for key in datadump['autogen_iface_keys'] if datadump[key]['dhcp'] != 'no'] 493 500 datadump['autogen_dhcp_interfaces'] = ' '.join(dhcp_interfaces) 494 501 datadump['autogen_item'] = item 495 502 datadump['autogen_fqdn'] = get_fqdn(datadump) 496 f.close() 497 503 504 datadump['autogen_domain'] = datadump['domain'] if datadump.has_key('domain') else 'wleiden.net' 505 datadump['autogen_nodename_lower'] = datadump['nodename'].lower() 498 506 return datadump 507 499 508 500 509 def store_yaml(datadump, header=False): … … 665 674 datadump = get_yaml(node) 666 675 667 # Preformat certain needed variables for formatting and push those into special object668 datadump_extra = copy.deepcopy(datadump)669 if not datadump_extra.has_key('domain'):670 datadump_extra['domain'] = 'wleiden.net'671 datadump_extra['nodename_lower'] = datadump_extra['nodename'].lower()672 datadump_extra['iface_keys'] = sorted([elem for elem in datadump.keys() if elem.startswith('iface_')])673 674 676 if config == 'wleiden.yaml': 675 677 output += generate_wleiden_yaml(datadump) … … 679 681 f.close() 680 682 elif config == 'dnsmasq.conf': 681 output += generate_dnsmasq_conf(datadump _extra)683 output += generate_dnsmasq_conf(datadump) 682 684 elif config == 'rc.conf.local': 683 output += generate_rc_conf_local(datadump _extra)685 output += generate_rc_conf_local(datadump) 684 686 elif config == 'resolv.conf': 685 output += generate_resolv_conf(datadump _extra)687 output += generate_resolv_conf(datadump) 686 688 elif config == 'motd': 687 output += generate_motd(datadump _extra)689 output += generate_motd(datadump) 688 690 else: 689 691 assert False, "Config not found!"
Note:
See TracChangeset
for help on using the changeset viewer.