X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=comon.py;h=8d96e1697665920b38ffc1ea79405e1192113b1a;hb=refs%2Fheads%2F1.0;hp=118211407d68e5a91c2664efc60d5ae2fb985801;hpb=b48d8621180e1d4dec000a511b130a7d63442240;p=monitor.git diff --git a/comon.py b/comon.py index 1182114..8d96e16 100755 --- a/comon.py +++ b/comon.py @@ -40,6 +40,40 @@ COMONURL = "http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_node # 3 == rins # 4 == ins +def _tohash(rawdata): + # First line Comon returns is list of keys with respect to index + try: + keys = rawdata.readline().rstrip().split(", ") + l_host = [] + hash = {} + i_ignored = 0 + for line in rawdata.readlines(): + l_host = line.rstrip().split(", ") # split the line on ', ' + hostname = l_host[0] + hash[hostname] = {} + for i in range(1,len(keys)): + hash[hostname][keys[i]]=l_host[i] + + except Exception, err: + logger.debug("No hosts retrieved") + return {} + return hash + +def comonget(url): + rawdata = None + print "Getting: %s" % url + try: + coserv = urllib2.Request(url) + coserv.add_header('User-Agent', 'PL_Monitor +http://monitor.planet-lab.org/') + opener = urllib2.build_opener() + # Initial web get from summer.cs in CSV + rawdata = opener.open(coserv) + except urllib2.URLError, (err): + print "Attempting %s" %COMONURL + print "URL error (%s)" % (err) + rawdata = None + return _tohash(rawdata) + class Comon(Thread): """ @@ -211,12 +245,6 @@ def main(): print("%-40s \t Bootstate %s nodetype %s kernver %s keyok %s" % ( host, cdb[host]['bootstate'], cdb[host]['nodetype'], cdb[host]['kernver'], cdb[host]['keyok'])) - #ssh = soltesz.SSH('root', host) - #try: - # val = ssh.run("uname -r") - # print "%s == %s" % (host, val), - #except: - # pass # else: # print("key mismatch at: %s" % host) #print a.codata['michelangelo.ani.univie.ac.at']