Changeset 8340 in genesis


Ignore:
Timestamp:
Aug 13, 2010, 5:38:57 PM (14 years ago)
Author:
rick
Message:

All multiple status to be merged into one big status

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nodes/get-network-status.py

    r8333 r8340  
    1919# When force is used as argument, use this range
    2020DEFAULT_SCAN_RANGE= ['172.16.0.0/21']
     21
     22# Default node status output
     23nodemap_status_file = '/tmp/nodemap_status.yaml'
    2124
    2225#
     
    254257
    255258  # Data store format used for nodemap generation
    256   nodemap_status_file = '/tmp/nodemap_status.yaml'
    257259  nodemap = { 'node' : {}, 'link' : {}}
    258260
     
    305307  print "# Wrote nodemap status to '%s'" % nodemap_status_file
    306308
     309
     310def do_merge(files):
     311  """ Merge all external statuses in our own nodestatus, using optimistic approch """
     312  stream = file(nodemap_status_file,'r')
     313  status = yaml.load(stream)
     314  for cfile in files:
     315    try:
     316      print "# Merging '%s'" % cfile
     317      stream = file(cfile,'r')
     318      new_status = yaml.load(stream)
     319      for item in ['node', 'link']:
     320        for key, value in status[item].iteritems():
     321          if not status[item].has_key(key):
     322            # New items always welcome
     323            status[item][key] = value
     324            print "## [%s][%] is new (%s)" % (item, key, value)
     325          elif value < status[item][key]:
     326            # Better values always welcome
     327            status[item][key] = value
     328            print "## [%s][%] is better (%s)" % (item, key, value)
     329    except IOError, e:
     330      print "## ERROR '%s'" % e
     331
     332  # Save results back to file
     333  stream = file(nodemap_status_file,'w')
     334  yaml.dump(status, stream, default_flow_style=False)
     335
    307336def usage():
    308337    print "Usage: %s <arguments>"
     
    355384    opt_nmap_scan = False
    356385    opt_store_scan = False
     386  elif sys.argv[1] == "merge":
     387    do_merge(sys.argv[2:])
     388    sys.exit(0)
    357389  else:
    358390    usage()
Note: See TracChangeset for help on using the changeset viewer.