-fbpcu = database.dbLoad('findbadpcus')
-hn2lb = database.dbLoad("plcdb_hn2lb")
-
-def get(fb, path):
- indexes = path.split("/")
- values = fb
- for index in indexes:
- if index in values:
- values = values[index]
+ d_pcu = None
+ for pcu in l_plcpcus:
+ if pcu['pcu_id'] == pcuname:
+ d_pcu = pcu
+ break
+ if not d_pcu:
+ continue
+
+ pf = HistoryPCURecord.findby_or_create(plc_pcuid=d_pcu['pcu_id'])
+ pf.last_checked = datetime.now()
+
+ try:
+ # Find the most recent record
+ pcurec = FindbadPCURecord.query.filter(FindbadPCURecord.plc_pcuid==pcuname).order_by(FindbadPCURecord.date_checked.desc()).first()
+ print "NODEREC: ", pcurec.date_checked
+ except:
+ print "COULD NOT FIND FB record for %s" % reboot.pcu_name(pcu)
+ import traceback
+ print traceback.print_exc()
+ # don't have the info to create a new entry right now, so continue.
+ continue
+
+ pcu_state = pcurec.reboot_trial_status
+ current_state = pcu_state
+
+ if current_state == 0 or current_state == "0":
+ if pf.status != "good":
+ pf.last_changed = datetime.now()
+ pf.status = "good"
+ elif current_state == 'NetDown':
+ if pf.status != "netdown":
+ pf.last_changed = datetime.now()
+ pf.status = "netdown"
+ elif current_state == 'Not_Run':
+ if pf.status != "badconfig":
+ pf.last_changed = datetime.now()
+ pf.status = "badconfig"