import sys
from monitor import database
-from nodecommon import *
-from unified_model import Record
+from monitor.common import *
+from monitor.model import Record
import glob
import os
import traceback
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
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):
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
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):
fb_noderec = None
#fb_noderec = FindbadNodeRecord.query.filter(FindbadNodeRecord.hostname==node).order_by(FindbadNodeRecord.date_checked.desc()).first()
fb_noderec = FindbadNodeRecord.get_latest_by(hostname=node)
+ except KeyboardInterrupt:
+ print "Exiting at user request: Ctrl-C"
+ sys.exit(1)
except:
print traceback.print_exc()
continue
#if 'plcnode' in fb_nodeinfo:
# fb_nodeinfo.update(fb_nodeinfo['plcnode'])
- #if verifyDBrecord(dict_query, fb_nodeinfo):
if verify(dict_query, fb_nodeinfo):
#print fb_nodeinfo.keys()
#print node #fb_nodeinfo
#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:
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 KeyboardInterrupt:
+ print "Exiting at user request: Ctrl-C"
+ sys.exit(1)
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
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(",")