X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=nodequery.py;h=738e58d0d57e66043c3b10495c2fcf17a6c516cb;hb=3f2acbd8b7761dae4bb02fedd3557e1003cafb43;hp=4378e2ca2b51d421aced077beadbd22aa7519cb7;hpb=da913fbd1629fc4669b186915df8ff3a340482d3;p=monitor.git diff --git a/nodequery.py b/nodequery.py index 4378e2c..738e58d 100755 --- a/nodequery.py +++ b/nodequery.py @@ -3,7 +3,7 @@ import sys from monitor import database -from nodecommon import * +from monitor.common import * from monitor.model import Record import glob import os @@ -13,12 +13,11 @@ import time import re import string -from monitor.pcu import reboot -from monitor.wrapper import plc, plccache +from monitor.wrapper import plc api = plc.getAuthAPI() -from monitor.database.info.model import FindbadNodeRecordSync, FindbadNodeRecord, session -from monitor import util +from monitor.database.info.model import HistoryNodeRecord, FindbadNodeRecord, FindbadPCURecord, session +from monitor.util import file as utilfile from monitor import config @@ -75,10 +74,10 @@ def get(fb, path): indexes = path.split(".") values = fb for index in indexes: - if index in values: - values = values[index] - else: - raise NoKeyException(index) + if values and index in values: + values = values[index] + else: + raise NoKeyException(index) return values def verifyType(constraints, data): @@ -254,9 +253,10 @@ def query_to_dict(query): return ad def pcu_in(fbdata): - if 'plcnode' in fbdata: - if 'pcu_ids' in fbdata['plcnode']: - if len(fbdata['plcnode']['pcu_ids']) > 0: + #if 'plcnode' in fbdata: + if 'plc_node_stats' in fbdata: + if fbdata['plc_node_stats'] and 'pcu_ids' in fbdata['plc_node_stats']: + if len(fbdata['plc_node_stats']['pcu_ids']) > 0: return True return False @@ -269,24 +269,35 @@ def pcu_select(str_query, nodelist=None): fbquery = FindbadNodeRecord.get_all_latest() fb_nodelist = [ n.hostname for n in fbquery ] if True: + # NOTE: this doesn't work when there are only a few records current. + # pcu_select should apply to all pcus globally, not just the most recent records. fbpcuquery = FindbadPCURecord.get_all_latest() fbpcu_list = [ p.plc_pcuid for p in fbpcuquery ] dict_query = query_to_dict(str_query) - - for noderec in fbquery: - if nodelist is not None: - if noderec.hostname not in nodelist: continue - - fb_nodeinfo = noderec.to_dict() - if pcu_in(fb_nodeinfo): - pcurec = FindbadPCURecord.get_latest_by(plc_pcuid=get(fb_nodeinfo, 'plc_node_stats.pcu_ids')[0]) - pcuinfo = pcurec.to_dict() - if verify(dict_query, pcuinfo): - nodenames.append(noderec.hostname) - str = "cmdhttps/locfg.pl -s %s -f iloxml/License.xml -u %s -p '%s' | grep MESSAGE" % \ - (reboot.pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password']) - pcunames.append(pcuinfo['plc_pcuid']) + print "dict_query", dict_query + print 'length %s' % len(fbpcuquery.all()) + + for pcurec in fbpcuquery: + pcuinfo = pcurec.to_dict() + if verify(dict_query, pcuinfo): + #nodenames.append(noderec.hostname) + #print 'appending %s' % pcuinfo['plc_pcuid'] + pcunames.append(pcuinfo['plc_pcuid']) + + #for noderec in fbquery: + # if nodelist is not None: + # if noderec.hostname not in nodelist: continue +# +# fb_nodeinfo = noderec.to_dict() +# if pcu_in(fb_nodeinfo): +# pcurec = FindbadPCURecord.get_latest_by(plc_pcuid=get(fb_nodeinfo, +# 'plc_node_stats.pcu_ids')[0]).first() +# if pcurec: +# pcuinfo = pcurec.to_dict() +# if verify(dict_query, pcuinfo): +# nodenames.append(noderec.hostname) +# pcunames.append(pcuinfo['plc_pcuid']) return (nodenames, pcunames) def node_select(str_query, nodelist=None, fb=None): @@ -371,16 +382,13 @@ def main(): #fbnodes = FindbadNodeRecord.select(FindbadNodeRecord.q.hostname, orderBy='date_checked',distinct=True).reversed() fb = None - #reboot.fb = fbpcu - if config.nodelist: - nodelist = util.file.getListFromFile(config.nodelist) + nodelist = utilfile.getListFromFile(config.nodelist) else: # NOTE: list of nodes should come from findbad db. Otherwise, we # don't know for sure that there's a record in the db.. - plcnodes = plccache.l_nodes - nodelist = [ node['hostname'] for node in plcnodes ] - #nodelist = ['planetlab-1.cs.princeton.edu'] + fbquery = HistoryNodeRecord.query.all() + nodelist = [ n.hostname for n in fbquery ] pculist = None if config.select is not None and config.pcuselect is not None: @@ -403,13 +411,14 @@ def main(): try: # Find the most recent record - fb_noderec = FindbadNodeRecord.query.filter(FindbadNodeRecord.hostname==node).order_by(FindbadNodeRecord.date_checked.desc()).first() + fb_noderec = FindbadNodeRecord.get_latest_by(hostname=node) + if not fb_noderec: continue + fb_nodeinfo = fb_noderec.to_dict() except: print traceback.print_exc() - pass + continue if config.listkeys: - fb_nodeinfo = fb_noderec.to_dict() print "Primary keys available in the findbad object:" for key in fb_nodeinfo.keys(): print "\t",key @@ -422,7 +431,6 @@ def main(): if config.daysdown: daysdown_print_nodeinfo(fb_nodeinfo, node) else: - fb_nodeinfo = fb_noderec.to_dict() if config.select: if config.fields: fields = config.fields.split(",")