13 from nodequery import verify,query_to_dict,node_select
14 from nodecommon import *
17 api = plc.getAuthAPI()
18 from unified_model import *
19 from const 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 nodes
30 externalState['round'] += 1
32 l_nodes = syncplcdb.create_plcdb()
33 l_plcnodes = database.dbLoad("l_plcnodes")
35 l_nodes = get_nodeset(config)
37 # l_nodes = [config.node]
39 # l_nodes = [node['hostname'] for node in l_plcnodes]
41 checkAndRecordState(l_nodes, l_plcnodes)
43 def checkAndRecordState(l_nodes, l_plcnodes):
46 global_round = externalState['round']
48 for nodename in l_nodes:
49 if nodename not in externalState['nodes']:
50 externalState['nodes'][nodename] = {'round': 0, 'values': []}
52 node_round = externalState['nodes'][nodename]['round']
53 if node_round < global_round:
55 values = collectStatusAndState(nodename, l_plcnodes)
56 global_round = externalState['round']
57 externalState['nodes'][nodename]['values'] = values
58 externalState['nodes'][nodename]['round'] = global_round
63 database.dbDump(config.dbname, externalState)
65 database.dbDump(config.dbname, externalState)
67 fb = database.dbLoad('findbad')
69 def getnodesup(nodelist):
72 if node['hostname'] in fb['nodes'].keys():
74 if fb['nodes'][node['hostname']]['values']['state'] == "BOOT":
81 indexes = path.split("/")
85 values = values[index]
90 def collectStatusAndState(nodename, l_plcnodes):
94 for node in l_plcnodes:
95 if node['hostname'] == nodename:
101 pf = PersistFlags(nodename, 1, db='node_persistflags')
103 if not pf.checkattr('last_changed'):
104 pf.last_changed = time.time()
106 pf.last_checked = time.time()
108 if not pf.checkattr('status'):
109 pf.status = "unknown"
111 state_path = "nodes/" + nodename + "/values/state"
112 bootstate_path = "nodes/" + nodename + "/values/plcnode/boot_state"
114 if get(fb, state_path) == "BOOT":
115 if pf.status != "good": pf.last_changed = time.time()
117 elif get(fb, state_path) == "DEBUG":
118 bs = get(fb, bootstate_path)
119 if pf.status != bs: pf.last_changed = time.time()
122 if pf.status != "down": pf.last_changed = time.time()
126 print "%d %35s %s since(%s)" % (count, nodename, pf.status, diff_time(pf.last_changed))
127 # updated by other modules
135 if __name__ == '__main__':
136 import parser as parsermodule
137 parser = parsermodule.getParser(['nodesets'])
138 parser.set_defaults(filename=None, node=None, nodeselect=False, nodegroup=None,
139 increment=False, dbname="nodebad", cachenodes=False)
141 parser.add_option("", "--dbname", dest="dbname", metavar="FILE",
142 help="Specify the name of the database to which the information is saved")
143 parser.add_option("-i", "--increment", action="store_true", dest="increment",
144 help="Increment round number to force refresh or retry")
145 parser = parsermodule.getParser(['defaults'], parser)
146 config = parsermodule.parse_args(parser)
150 except Exception, err:
152 print traceback.print_exc()
153 print "Exception: %s" % err
154 print "Saving data... exitting."
155 database.dbDump(config.dbname, externalState)