5 api = plc.PLC(auth.auth, auth.plc)
8 fb = soltesz.dbLoad("findbad")
9 fbpcu = soltesz.dbLoad("findbadpcus")
10 from nodecommon import *
11 from policy import Diagnose
18 def daysdown_print_nodeinfo(fbnode, hostname):
19 fbnode['hostname'] = hostname
20 fbnode['daysdown'] = Diagnose.getStrDaysDown(fbnode)
21 fbnode['intdaysdown'] = Diagnose.getDaysDown(fbnode)
23 print "%(intdaysdown)5s %(hostname)-44s | %(state)10.10s | %(daysdown)s" % fbnode
25 def fb_print_nodeinfo(fbnode, hostname):
26 fbnode['hostname'] = hostname
27 fbnode['checked'] = diff_time(fbnode['checked'])
29 fbnode['bootcd'] = fbnode['bootcd'].split()[-1]
31 fbnode['bootcd'] = "unknown"
32 if 'ERROR' in fbnode['category']:
35 fbnode['kernel'] = fbnode['kernel'].split()[2]
36 fbnode['pcu'] = color_pcu_state(fbnode)
37 print "%(hostname)-39s | %(checked)11.11s | %(state)10.10s | %(ssh)5.5s | %(pcu)6.6s | %(bootcd)6.6s | %(category)8.8s | %(kernel)s" % fbnode
39 def verify(constraints, data):
41 constraints is a list of key, value pairs.
42 # [ {... : ...}==AND , ... , ... , ] == OR
45 for con in constraints:
46 #print "con: %s" % con
47 if len(con.keys()) == 0:
52 for key in con.keys():
53 #print "looking at key: %s" % key
55 value_re = re.compile(con[key])
56 con_and_true = con_and_true & (value_re.search(data[key]) is not None)
58 print "missing key %s" % key
61 con_or_true = con_or_true | con_and_true
65 def query_to_dict(query):
69 or_queries = query.split('||')
70 for or_query in or_queries:
71 and_queries = or_query.split('&&')
75 for and_query in and_queries:
76 (key, value) = and_query.split('=')
84 if 'plcnode' in fbdata:
85 if 'pcu_ids' in fbdata['plcnode']:
86 if len(fbdata['plcnode']['pcu_ids']) > 0:
90 def pcu_select(str_query):
92 if str_query is None: return pcunames
95 dict_query = query_to_dict(str_query)
98 for node in fb['nodes'].keys():
100 fb_nodeinfo = fb['nodes'][node]['values']
101 if _pcu_in(fb_nodeinfo):
102 pcuinfo = fbpcu['nodes']['id_%s' % fb_nodeinfo['plcnode']['pcu_ids'][0]]['values']
103 if verify(dict_query, pcuinfo):
104 pcunames.append(node)
108 def node_select(str_query):
110 if str_query is None: return hostnames
113 dict_query = query_to_dict(str_query)
116 for node in fb['nodes'].keys():
118 fb_nodeinfo = fb['nodes'][node]['values']
120 if verify(dict_query, fb_nodeinfo):
121 #print node #fb_nodeinfo
122 hostnames.append(node)
124 #print "NO MATCH", node
131 from config import config
132 from optparse import OptionParser
133 parser = OptionParser()
134 parser.set_defaults(node=None, select=None, pcuselect=None, nodelist=None, daysdown=None)
135 parser.add_option("", "--daysdown", dest="daysdown", action="store_true",
136 help="List the node state and days down...")
137 parser.add_option("", "--select", dest="select", metavar="key=value",
138 help="List all nodes with the given key=value pattern")
139 parser.add_option("", "--pcuselect", dest="pcuselect", metavar="key=value",
140 help="List all nodes with the given key=value pattern")
141 parser.add_option("", "--nodelist", dest="nodelist", metavar="nodelist.txt",
142 help="A list of nodes to bring out of debug mode.")
143 config = config(parser)
147 nodelist = config.getListFromFile(config.nodelist)
148 elif config.select is not None:
149 nodelist = node_select(config.select)
150 elif config.pcuselect is not None:
151 nodelist = pcu_select(config.pcuselect)
153 nodelist = fb['nodes'].keys()
155 for node in nodelist:
158 if node not in fb['nodes']:
161 fb_nodeinfo = fb['nodes'][node]['values']
164 daysdown_print_nodeinfo(fb_nodeinfo, node)
167 fb_print_nodeinfo(fb_nodeinfo, node)
168 elif not config.select and 'state' in fb_nodeinfo:
169 fb_print_nodeinfo(fb_nodeinfo, node)
173 if __name__ == "__main__":