8 from reboot import pcu_name
14 from nodequery import verify,query_to_dict,node_select
17 api = plc.getAuthAPI()
18 from unified_model import *
19 from monitor_policy import MINUP
22 externalState = {'round': round, 'nodes': {}}
27 externalState = database.if_cached_else(1, config.dbname, lambda : externalState)
29 # update global round number to force refreshes across all pcus
30 externalState['round'] += 1
32 l_plcpcus = database.if_cached_else_refresh(1, 1, "pculist", lambda : plc.GetPCUs())
37 if pcu['hostname'] == config.pcu or pcu['ip'] == config.pcu:
38 l_pcus = [pcu['pcu_id']]
40 print "ERROR: could not find pcu %s" % config.pcu
43 l_pcus = [pcu['pcu_id'] for pcu in l_plcpcus]
45 checkAndRecordState(l_pcus, l_plcpcus)
47 def checkAndRecordState(l_pcus, l_plcpcus):
50 global_round = externalState['round']
52 for pcuname in l_pcus:
53 if pcuname not in externalState['nodes']:
54 externalState['nodes'][pcuname] = {'round': 0, 'values': []}
56 pcu_round = externalState['nodes'][pcuname]['round']
57 if pcu_round < global_round:
59 values = collectStatusAndState(pcuname, l_plcpcus)
60 global_round = externalState['round']
61 externalState['nodes'][pcuname]['values'] = values
62 externalState['nodes'][pcuname]['round'] = global_round
67 database.dbDump(config.dbname, externalState)
69 database.dbDump(config.dbname, externalState)
71 fbpcu = database.dbLoad('findbadpcus')
72 hn2lb = database.dbLoad("plcdb_hn2lb")
75 indexes = path.split("/")
79 values = values[index]
84 def collectStatusAndState(pcuname, l_plcpcus):
89 if pcu['pcu_id'] == pcuname:
95 pf = PersistFlags(pcuname, 1, db='pcu_persistflags')
97 if not pf.checkattr('last_changed'):
98 pf.last_changed = time.time()
100 pf.last_checked = time.time()
102 if not pf.checkattr('valid'):
106 if not pf.checkattr('status'):
107 pf.status = "unknown"
109 state_path = "nodes/id_" + str(pcuname) + "/values/reboot"
110 bootstate_path = "nodes/id_" + str(pcuname) + "/values/plcpcu/boot_state"
112 current_state = get(fbpcu, state_path)
113 if current_state == 0:
114 if pf.status != "good": pf.last_changed = time.time()
116 elif current_state == 'NetDown':
117 if pf.status != "netdown": pf.last_changed = time.time()
118 pf.status = "netdown"
119 elif current_state == 'Not_Run':
120 if pf.status != "badconfig": pf.last_changed = time.time()
121 pf.status = "badconfig"
123 if pf.status != "error": pf.last_changed = time.time()
127 print "%d %35s %s since(%s)" % (count, pcu_name(d_pcu), pf.status, diff_time(pf.last_changed))
128 # updated by other modules
136 if __name__ == '__main__':
137 from config import config
138 from optparse import OptionParser
139 parser = OptionParser()
140 parser.set_defaults(filename=None, pcu=None, pcuselect=False, pcugroup=None,
141 increment=False, dbname="pcubad", cachepcus=False)
142 parser.add_option("", "--pcu", dest="pcu", metavar="hostname",
143 help="Provide a single pcu to operate on")
144 parser.add_option("", "--pculist", dest="pculist", metavar="file.list",
145 help="Provide a list of files to operate on")
147 parser.add_option("", "--dbname", dest="dbname", metavar="FILE",
148 help="Specify the name of the database to which the information is saved")
149 parser.add_option("-i", "--increment", action="store_true", dest="increment",
150 help="Increment round number to force refresh or retry")
151 config = config(parser)
156 except Exception, err:
158 print traceback.print_exc()
159 print "Exception: %s" % err
160 print "Saving data... exitting."
161 database.dbDump(config.dbname, externalState)