Changeset 10281 in genesis


Ignore:
Timestamp:
Mar 27, 2012, 7:19:06 AM (13 years ago)
Author:
rick
Message:

Make the default node page a bit more usefull for daily usage.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10270 r10281  
    3232import rdnap
    3333from pprint import pprint
     34from collections import defaultdict
    3435try:
    3536  import yaml
     
    7576
    7677
    77 def make_graph():
     78def make_relations():
    7879  """ Process _ALL_ yaml files to get connection relations """
    7980  errors = ""
    80   poel = {}
     81  poel = defaultdict(list)
    8182  for host in get_hostlist():
    8283    try:
     
    9293        addr = parseaddr(addr)
    9394        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])]
    9997    except (KeyError, ValueError), e:
    10098      errors += "[FOUT] in '%s' interface '%s'" % (host,iface_key)
     
    234232  # Generate and connection listing
    235233  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
    242246  output += "</ul>"
     247  output += "<h2>MOTD details:</h2><pre>" + generate_motd(datadump) + "</pre>"
    243248
    244249  output += "<hr /><em><a href='..'>Back to overview</a></em>"
     
    305310  \n""" % datadump
    306311
    307   for iface_key in datadump['iface_keys']:
     312  for iface_key in datadump['autogen_iface_keys']:
    308313    if not datadump[iface_key].has_key('comment'):
    309314      datadump[iface_key]['comment'] = None
     
    408413
    409414  masterip_used = False
    410   for iface_key in datadump['iface_keys']:
     415  for iface_key in datadump['autogen_iface_keys']:
    411416    if datadump[iface_key]['ip'].startswith(datadump['masterip']):
    412417      masterip_used = True
     
    415420    addrs_list['lo0'].append((datadump['masterip'] + "/32", 'Master IP Not used in interface'))
    416421
    417   for iface_key in datadump['iface_keys']:
     422  for iface_key in datadump['autogen_iface_keys']:
    418423    ifacedump = datadump[iface_key]
    419424    ifname = ifacedump['autogen_ifname']
     
    479484  f = open(gfile, 'r')
    480485  datadump = yaml.load(f,Loader=Loader)
     486  f.close()
     487
     488  # Preformat certain needed variables for formatting and push those into special object
    481489  datadump['autogen_iface_keys'] = get_interface_keys(datadump)
    482490
     
    489497      datadump[key]['autogen_ifname'] = datadump[key]['interface'].split(':')[0]
    490498
    491 
    492499  dhcp_interfaces = [datadump[key]['autogen_ifname'] for key in datadump['autogen_iface_keys'] if datadump[key]['dhcp'] != 'no']
    493500  datadump['autogen_dhcp_interfaces'] = ' '.join(dhcp_interfaces)
    494501  datadump['autogen_item'] = item
    495502  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()
    498506  return datadump
     507
    499508
    500509def store_yaml(datadump, header=False):
     
    665674      datadump = get_yaml(node)
    666675
    667     # Preformat certain needed variables for formatting and push those into special object
    668     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 
    674676    if config == 'wleiden.yaml':
    675677      output += generate_wleiden_yaml(datadump)
     
    679681      f.close()
    680682    elif config == 'dnsmasq.conf':
    681       output += generate_dnsmasq_conf(datadump_extra)
     683      output += generate_dnsmasq_conf(datadump)
    682684    elif config == 'rc.conf.local':
    683       output += generate_rc_conf_local(datadump_extra)
     685      output += generate_rc_conf_local(datadump)
    684686    elif config == 'resolv.conf':
    685       output += generate_resolv_conf(datadump_extra)
     687      output += generate_resolv_conf(datadump)
    686688    elif config == 'motd':
    687       output += generate_motd(datadump_extra)
     689      output += generate_motd(datadump)
    688690    else:
    689691      assert False, "Config not found!"
Note: See TracChangeset for help on using the changeset viewer.