+ for node in fb['nodes'].keys():
+ if nodelist is not None:
+ if node not in nodelist: continue
+
+ fb_nodeinfo = fb['nodes'][node]['values']
+ if pcu_in(fb_nodeinfo):
+ pcuinfo = fbpcu['nodes']['id_%s' % fb_nodeinfo['plcnode']['pcu_ids'][0]]['values']
+ if verify(dict_query, pcuinfo):
+ nodenames.append(node)
+ str = "cmdhttps/locfg.pl -s %s -f iloxml/License.xml -u %s -p '%s' | grep MESSAGE" % \
+ (pcu_name(pcuinfo), pcuinfo['username'], pcuinfo['password'])
+ #pcunames.append(str)
+ pcunames.append(pcuinfo['pcu_id'])
+ return (nodenames, pcunames)
+
+def node_select(str_query, nodelist=None, fbdb=None):
+ global fb
+
+ hostnames = []
+ if str_query is None: return hostnames
+
+ #print str_query
+ dict_query = query_to_dict(str_query)
+ #print dict_query
+
+ if fbdb is not None:
+ fb = fbdb
+
+ for node in fb['nodes'].keys():
+ if nodelist is not None:
+ if node not in nodelist: continue
+
+ fb_nodeinfo = fb['nodes'][node]['values']
+
+ if fb_nodeinfo == []:
+ #print node, "has lost values"
+ continue
+ #sys.exit(1)
+ fb_nodeinfo['pcu'] = color_pcu_state(fb_nodeinfo)
+ fb_nodeinfo['hostname'] = node
+ if 'plcnode' in fb_nodeinfo:
+ fb_nodeinfo.update(fb_nodeinfo['plcnode'])
+
+ if verify(dict_query, fb_nodeinfo):
+ #print node #fb_nodeinfo
+ hostnames.append(node)
+ else:
+ #print "NO MATCH", node
+ pass
+
+ return hostnames
+
+
+def main():
+ global fb
+ global fbpcu
+
+ import parser as parsermodule
+ parser = parsermodule.getParser()
+
+ parser.set_defaults(node=None, fromtime=None, select=None, list=None,
+ pcuselect=None, nodelist=None, daysdown=None, fields=None)
+ parser.add_option("", "--daysdown", dest="daysdown", action="store_true",
+ help="List the node state and days down...")
+ parser.add_option("", "--select", dest="select", metavar="key=value",
+ help="List all nodes with the given key=value pattern")
+ parser.add_option("", "--fields", dest="fields", metavar="key,list,...",
+ help="a list of keys to display for each entry.")
+ parser.add_option("", "--list", dest="list", action="store_true",
+ help="Write only the hostnames as output.")
+ parser.add_option("", "--pcuselect", dest="pcuselect", metavar="key=value",
+ help="List all nodes with the given key=value pattern")
+ parser.add_option("", "--nodelist", dest="nodelist", metavar="nodelist.txt",
+ help="A list of nodes to bring out of debug mode.")
+ parser.add_option("", "--fromtime", dest="fromtime", metavar="YYYY-MM-DD",
+ help="Specify a starting date from which to begin the query.")
+
+ parser = parsermodule.getParser(['defaults'], parser)
+ config = parsermodule.parse_args(parser)
+
+ if config.fromtime:
+ path = "archive-pdb"
+ archive = database.SPickle(path)
+ d = datetime_fromstr(config.fromtime)
+ glob_str = "%s*.production.findbad.pkl" % d.strftime("%Y-%m-%d")
+ os.chdir(path)
+ #print glob_str
+ file = glob.glob(glob_str)[0]
+ #print "loading %s" % file
+ os.chdir("..")
+ fb = archive.load(file[:-4])