5 api = plc.PLC(auth.auth, auth.plc)
9 from datetime import datetime, timedelta
13 from nodecommon import color_pcu_state, datetime_fromstr
14 from nodehistory import get_filefromglob
21 # up with good hardware
22 # up with good hardware & functional pcu
24 #cm_url="http://summer.cs.princeton.edu/status/tabulator.cgi?table=table_nodeviewshort&format=formatcsv&dumpcols='name,cpuspeed,memsize,disksize'"
25 #cm = database.if_cached_else(1, "cmhardware", lambda : comon.comonget(cm_url))
27 def gethardwarequality(nodename, fb):
28 if nodename in fb['nodes'] and 'comonstats' in fb['nodes'][nodename]['values']:
29 cstat = fb['nodes'][nodename]['values']['comonstats']
30 for field in ['cpuspeed', 'memsize', 'disksize']:
31 if field not in cstat: cstat[field] = "null"
33 if cstat['cpuspeed'] != "null" and float(cstat['cpuspeed']) < 2.4:
34 return "BAD" # "cpu_slow",
35 if cstat['memsize'] != "null" and float(cstat['memsize']) < 2.9:
36 return "BAD" # "mem_small",
37 if cstat['disksize'] != "null" and float(cstat['disksize']) < 320.0:
38 return "BAD" # "disk_small",
40 if cstat['disksize'] == "null" and \
41 cstat['cpuspeed'] == "null" and \
42 cstat['memsize'] == "null":
46 if float(cstat['cpuspeed']) >= 2.4 and \
47 float(cstat['memsize']) >= 2.9 and \
48 (cstat['disksize'] == "null" or float(cstat['disksize']) >= 320.0):
57 def addtostats(stats, a):
58 if a['cc'] not in stats:
59 stats[a['cc']] = {'total' : 0,
64 stats[a['cc']]['total'] += 1
65 if a['status'] == "boot":
66 stats[a['cc']]['up'] += 1
67 if a['hardware'] == "A-OK":
68 stats[a['cc']]['goodhw'] += 1
69 if a['pcuok'] == "PCUOK " or a['pcuok'] == "PCUA-OK":
70 stats[a['cc']]['pcuok'] += 1
76 archive = database.SPickle(path)
84 begin = time.strftime(format)
86 d = datetime_fromstr(begin)
87 fbstr = get_filefromglob(d, "production.findbad")
88 fbpcustr = get_filefromglob(d, "production.findbadpcus")
90 l_plcnodes = database.dbLoad("l_plcnodes")
91 l_plcsites = database.dbLoad("l_plcsites")
92 lb2hn = database.dbLoad("plcdb_lb2hn")
93 fb = archive.load(fbstr)
94 fbpcu = archive.load(fbpcustr)
98 # COLLECT nodegroups, nodes and node lists
99 for site in l_plcsites:
101 if site['login_base'] in lb2hn:
102 nodes = lb2hn[site['login_base']]
104 hostname = node['hostname']
105 fields = hostname.split(".")
106 if len(fields[-1]) == 2:
108 elif fields[-1] == "edu":
110 elif site['login_base'] == "ft":
112 elif site['login_base'] == "ntu":
114 elif site['login_base'] in ["mcgill", "canarieottawa", 'canariecalgary',
115 'canariehalifax', 'canariemontreal',
116 'canarietoronto', 'canariewinnipeg']:
118 elif site['login_base'] in ["plcoloclarasanti", "plcoloclarasaopa",
119 "plcoloclarabueno", "plcoloclaratijua",
122 elif site['login_base'] in ["plcoloamst", 'cwi']:
124 elif site['login_base'] == "urv":
126 elif site['login_base'] == "ncl":
128 elif site['login_base'] == "waterford":
130 elif site['login_base'] in ["kisti", "snummlab"]:
132 elif site['login_base'] == "astri":
134 elif fields[-1] in [ "org", "net" ]:
136 elif fields[-1] == "com":
141 if hostname in fb['nodes']:
142 if 'state' in fb['nodes'][hostname]['values']:
143 state = fb['nodes'][hostname]['values']['state'].lower()
148 'site' : site['login_base'],
151 'hardware' : gethardwarequality(hostname, fb),
152 'pcuok' : color_pcu_state(fb['nodes'][hostname]['values']) }
154 # print traceback.print_exc()
156 # print fb['nodes'][hostname]['values']
157 results.append("%(cc)7s %(status)8s %(hardware)8s %(pcuok)8s %(site)15s %(host)42s " % args)
158 addtostats(stats, args)
160 site['latitude'] = -2
161 site['longitude'] = -2
163 #print "%4s %20s %8s %8s" % (CC, site['login_base'], site['latitude'], site['longitude'])
165 regions = { 'mideast' : ['cy', 'gr', 'il', 'in', 'lb', 'pk'],
167 'usa' : ['pr','us', 'uscom', 'usedu', 'usorg'],
168 'europe' : ['at','ch','cz','be', 'de', 'dk',
169 'es','fi', 'fr', 'hu', 'ie', 'is', 'it','nl',
170 'no', 'pl', 'pt', 'se', 'tr', 'uk'],
171 'asia' : ['cn','hk','jp','kr', 'ru', 'sg', 'si','tw',],
172 'australia': ['au', 'nz',],
173 'southam' : ['ar','br','southamerica','uy', 've'],
177 for key in regions.keys():
178 statsfold[key] = {'total' : 0, 'up' : 0,
179 'goodhw': 0, 'pcuok' : 0}
181 totaltotal = { 'total' : 0, 'up' : 0,
182 'goodhw': 0, 'pcuok' : 0}
183 # for all of the cc stats
184 for cc in stats.keys():
185 # search for the cc in the regions dict
186 for region in regions:
187 # if the cc is assigned to a region
188 if cc in regions[region]:
189 # add all values in cc stats to that region
190 for key in statsfold[region]:
191 statsfold[region][key] += stats[cc][key]
192 totaltotal[key] += stats[cc][key]
195 print " REGION | total | up |& goodhw |& pcuok "
196 for region in statsfold.keys():
197 statsfold[region]['region'] = region
198 print "%(region)13s | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % statsfold[region]
199 print " totals | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % totaltotal
202 print " Region | total | up |& goodhw |& pcuok "
203 for region in stats.keys():
204 stats[region]['region'] = region
205 print "%(region)13s | %(total)5s | %(up)3s | %(goodhw)7s | %(pcuok)3s" % stats[region]
210 if __name__ == "__main__":