Changeset 10270 in genesis for tools


Ignore:
Timestamp:
Mar 22, 2012, 11:04:29 AM (13 years ago)
Author:
rick
Message:

Make sure more usefull page overviews for nodes and other items. Including an
dynamic listing on the units they are connected to.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tools/gformat.py

    r10264 r10270  
    7373DOWN = 20
    7474UNKNOWN = 90
     75
     76
     77def make_graph():
     78  """ Process _ALL_ yaml files to get connection relations """
     79  errors = ""
     80  poel = {}
     81  for host in get_hostlist():
     82    try:
     83      datadump = get_yaml(host)
     84      for iface_key in datadump['autogen_iface_keys']:
     85        l = datadump[iface_key]['ip']
     86        addr, mask = l.split('/')
     87
     88        # Not parsing of these folks please
     89        if not valid_addr(addr):
     90          continue
     91
     92        addr = parseaddr(addr)
     93        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]
     99    except (KeyError, ValueError), e:
     100      errors += "[FOUT] in '%s' interface '%s'" % (host,iface_key)
     101      errors += e
     102      continue
     103  return (poel, errors)
    75104
    76105
     
    192221  return "\n".join(files)
    193222
     223def generate_node_overview(host):
     224  """ Print overview of all files available for node """
     225  datadump = get_yaml(host)
     226  params = { 'host' : host }
     227  output = "<em><a href='..'>Back to overview</a></em><hr />"
     228  output += "<h2>Available files:</h2><ul>"
     229  for cf in files:
     230    params['cf'] = cf
     231    output += '<li><a href="%(host)s/%(cf)s">%(cf)s</a></li>\n' % params
     232  output += "</ul>"
     233
     234  # Generate and connection listing
     235  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
     242  output += "</ul>"
     243
     244  output += "<hr /><em><a href='..'>Back to overview</a></em>"
     245  return output
    194246
    195247
     
    656708
    657709
    658   uri = os.environ['PATH_INFO'].strip('/').split('/')
     710  base_uri = os.environ['PATH_INFO']
     711  uri = base_uri.strip('/').split('/')
     712
    659713  output = ""
    660714  if not uri[0]:
     
    666720      output += generate_title(get_hostlist())
    667721  elif len(uri) == 1:
    668     output += "Content-type:text/plain\r\n\r\n"
    669     output += generate_node(uri[0])
     722    if is_text_request():
     723      output += "Content-type:text/plain\r\n\r\n"
     724      output += generate_node(uri[0])
     725    else:
     726      output += "Content-type:text/html\r\n\r\n"
     727      output += generate_node_overview(uri[0])
    670728  elif len(uri) == 2:
    671729    output += "Content-type:text/plain\r\n\r\n"
     
    868926\ttest CNodeRick dnsmasq.conf  =  Receive output of CGI script
    869927\t                                for arguments CNodeRick/dnsmasq.conf
    870 \tlist <nodes|proxies>         =  List systems which marked up.
     928\tlist <all|nodes|proxies>     =  List systems which marked up.
    871929"""
    872930  exit(0)
     
    10121070      elif sys.argv[2] == "proxies":
    10131071        systems = get_proxylist()
     1072      elif sys.argv[2] == "all":
     1073        systems = get_hostlist()
    10141074      else:
    10151075        usage()
Note: See TracChangeset for help on using the changeset viewer.