X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=grouprins.py;h=1896f418a14b4fbfe34655af520c77255bd4dc16;hb=6d46ab9b534b60675a3dcb11fcb664589a3691f8;hp=ffb4f85cd2e6fcc3f9b6ed33ccb047896e014287;hpb=c51ad794e8dc07072d705b508e79ba06849aa408;p=monitor.git diff --git a/grouprins.py b/grouprins.py index ffb4f85..1896f41 100755 --- a/grouprins.py +++ b/grouprins.py @@ -15,12 +15,12 @@ import plc api = plc.getAuthAPI() -import policy import traceback -from config import config as cfg -import config as configmodule +import config +import util.file from optparse import OptionParser +import const from nodecommon import * from nodequery import verify,query_to_dict,node_select import database @@ -28,11 +28,12 @@ from unified_model import * import os import time +import parser as parsermodule from model import * import bootman # debug nodes -import monitor # down nodes with pcu import reboot # down nodes without pcu +import mailmonitor # down nodes with pcu from emailTxt import mailtxt #reboot.verbose = 0 import sys @@ -53,18 +54,21 @@ class Reboot(object): mailtxt.pcudown_one[1] % args, True, db='pcu_persistmessages') loginbase = plc.siteId(host) - m.send([policy.TECHEMAIL % loginbase]) + m.send([const.TECHEMAIL % loginbase]) def pcu(self, host): # TODO: It should be possible to diagnose the various conditions of # the PCU here, and send different messages as appropriate. - if self.fbnode['pcu'] == "PCU": + print "'%s'" % self.fbnode['pcu'] + if self.fbnode['pcu'] == "PCU" or "PCUOK" in self.fbnode['pcu']: self.action = "reboot.reboot('%s')" % host pflags = PersistFlags(host, 2*60*60*24, db='pcu_persistflags') + pflags.resetRecentFlag('pcutried') if not pflags.getRecentFlag('pcutried'): pflags.setRecentFlag('pcutried') try: + print "CALLING REBOOT!!!" ret = reboot.reboot(host) pflags.save() @@ -93,8 +97,10 @@ class Reboot(object): return True else: + print "GetRecentFlag()" return False else: + print "NO PCUOK" self.action = "None" return False @@ -107,10 +113,10 @@ class Reboot(object): pflags.setRecentFlag('endrecord') pflags.save() - # Then in either case, run monitor.reboot() - self.action = "monitor.reboot('%s')" % host + # Then in either case, run mailmonitor.reboot() + self.action = "mailmonitor.reboot('%s')" % host try: - return monitor.reboot(host) + return mailmonitor.reboot(host) except Exception, e: print traceback.print_exc(); print e return False @@ -159,12 +165,8 @@ try: except: rebootlog = LogRoll() -parser = OptionParser() -parser.set_defaults(nodegroup=None, - node=None, - nodelist=None, - nodeselect=None, - timewait=0, +parser = parsermodule.getParser(['nodesets']) +parser.set_defaults( timewait=0, skip=0, rins=False, reboot=False, @@ -176,33 +178,9 @@ parser.set_defaults(nodegroup=None, stopvalue=None, quiet=False, ) -parser.add_option("", "--node", dest="node", metavar="nodename.edu", - help="A single node name to add to the nodegroup") -parser.add_option("", "--nodelist", dest="nodelist", metavar="list.txt", - help="Use all nodes in the given file for operation.") -parser.add_option("", "--nodegroup", dest="nodegroup", metavar="NodegroupName", - help="Specify a nodegroup to perform actions on") -parser.add_option("", "--nodeselect", dest="nodeselect", metavar="querystring", - help="Specify a query to perform on findbad db") - -parser.add_option("", "--verbose", dest="verbose", action="store_true", - help="Extra debug output messages.") -parser.add_option("", "--nosetup", dest="nosetup", action="store_true", - help="Do not perform the orginary setup phase.") - -parser.add_option("", "--skip", dest="skip", - help="Number of machines to skip on the input queue.") -parser.add_option("", "--timewait", dest="timewait", - help="Minutes to wait between iterations of 10 nodes.") parser.add_option("", "--stopselect", dest="stopselect", metavar="", help="The select string that must evaluate to true for the node to be considered 'done'") - -parser.add_option("", "--stopkey", dest="stopkey", metavar="", - help="") -parser.add_option("", "--stopvalue", dest="stopvalue", metavar="", - help="") - parser.add_option("", "--findbad", dest="findbad", action="store_true", help="Re-run findbad on the nodes we're going to check before acting.") parser.add_option("", "--force", dest="force", action="store_true", @@ -211,9 +189,18 @@ parser.add_option("", "--rins", dest="rins", action="store_true", help="Set the boot_state to 'rins' for all nodes.") parser.add_option("", "--reboot", dest="reboot", action="store_true", help="Actively try to reboot the nodes, keeping a log of actions.") -#config = config(parser) -config = cfg(parser) -config.parse_args() + +parser.add_option("", "--verbose", dest="verbose", action="store_true", + help="Extra debug output messages.") +parser.add_option("", "--nosetup", dest="nosetup", action="store_true", + help="Do not perform the orginary setup phase.") +parser.add_option("", "--skip", dest="skip", + help="Number of machines to skip on the input queue.") +parser.add_option("", "--timewait", dest="timewait", + help="Minutes to wait between iterations of 10 nodes.") + +parser = parsermodule.getParser(['defaults'], parser) +config = parsermodule.parse_args(parser) # COLLECT nodegroups, nodes and node lists if config.nodegroup: @@ -225,16 +212,17 @@ if config.node or config.nodelist: if config.node: hostnames = [ config.node ] else: hostnames = config.getListFromFile(config.nodelist) +fb = database.dbLoad("findbad") + if config.nodeselect: - hostnames = node_select(config.nodeselect) + hostnames = node_select(config.nodeselect, fb['nodes'].keys(), fb) if config.findbad: # rerun findbad with the nodes in the given nodes. file = "findbad.txt" - configmodule.setFileFromList(file, hostnames) + util.file.setFileFromList(file, hostnames) os.system("./findbad.py --cachenodes --debug=0 --dbname=findbad --increment --nodelist %s" % file) -fb = database.dbLoad("findbad") # commands: i = 1 count = 1 @@ -251,7 +239,7 @@ for host in hostnames: print "%-2d" % i, nodegroup_display(node, fb) i += 1 - if i < int(config.skip): continue + if i-1 <= int(config.skip): continue if config.stopselect: dict_query = query_to_dict(config.stopselect)