X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=pcucontrol%2Freboot.py;h=a54eead5b4c3639c4b7baf8e3e198e091ad0c471;hb=f60bc6208846ab5ed02e85645bcf424d12a4356b;hp=a6e1934a0c41db674339eb28422ef16ab52c9a6a;hpb=4c1af5526615cf1958b801176c802283d7d4d308;p=pcucontrol.git diff --git a/pcucontrol/reboot.py b/pcucontrol/reboot.py index a6e1934..a54eead 100755 --- a/pcucontrol/reboot.py +++ b/pcucontrol/reboot.py @@ -1,4 +1,4 @@ -#!/usr/bin/python +#!/usr/bin/python2 # # Reboot specified nodes # @@ -33,7 +33,7 @@ import pcucontrol.transports.pyssh as pyssh #MONITOR_USER_ID = 11142 import logging -verbose = 1 +verbose = 0 #dryrun = 0; class ExceptionNoTransport(Exception): pass @@ -88,9 +88,9 @@ class PCUModel(PCU): raise Exception("No such Node ID: %d" % node_id) - def catcherror(self, function, node_port): + def catcherror(self, function, node_port, dryrun): try: - return function(node_port) + return function(node_port, dryrun) except ExceptionNotFound, err: return "Not found: " + str(err) except ExceptionPassword, err: @@ -255,7 +255,7 @@ class Transport: if self.transport != None: output = self.transport.read_until(expected, self.TELNET_TIMEOUT) if output.find(expected) == -1: - print "OUTPUT: --%s--" % output + #print "OUTPUT: --%s--" % output raise ErrorClass, "'%s' not found: Got: %s" % (expected, output) else: self.transport.write(buffer + "\r\n") @@ -310,7 +310,7 @@ class PCUControl(PCUModel,PCURecord): if port_list == []: raise ExceptionPort("No Open Port: No transport from open ports") - print port_list + #print port_list ret = "No implementation for open ports on selected PCU model" for port in port_list: @@ -320,9 +320,9 @@ class PCUControl(PCUModel,PCURecord): type = Transport.porttypemap[port] self.transport = Transport(type, verbose) - print "checking for run_%s" % type + #print "checking for run_%s" % type if hasattr(self, "run_%s" % type): - print "found run_%s" % type + #print "found run_%s" % type fxn = getattr(self, "run_%s" % type) ret = self.catcherror(fxn, node_port, dryrun) if ret == 0: # NOTE: success!, so stop @@ -357,13 +357,27 @@ class BasicPCUControl(PCUModel): PCUModel.__init__(self, plc_pcu_record) def run_expect_script(self, scriptname, **args): + #print "Running EXPECT: %s" % scriptname locfg = command.CMD() + if 'ip' in args: + host = self.ip + else: + host = self.host + + #print args + if 'sequence' in args: + seq = " ".join(args['sequence']) + seq = "'%s'" % seq + else: + seq = "" + cmd_str = get_python_lib(1) + "/pcucontrol/models/exp/" - cmd = cmd_str + "%s %s %s '%s' %s %s " % ( - scriptname, self.host, self.username, - self.password, args['dryrun'], args['model']) - cmd_out, cmd_err = locfg.run_noexcept(cmd) + cmd = cmd_str + "%s %s %s '%s' %s %s %s" % ( + scriptname, host, self.username, + self.password, args['dryrun'], args['model'], seq) + #print cmd + cmd_out, cmd_err = locfg.run_noexcept("expect " + cmd) return cmd_out.strip() + cmd_err.strip() def reboot(self, node_port, dryrun): @@ -376,9 +390,9 @@ class BasicPCUControl(PCUModel): if not hasattr(self, looking_for_fxn): raise Exception("This model (%s) does not implement %s" % (self.model, looking_for_fxn)) - print "found function %s in model %s" % (looking_for_fxn, self.model) + #print "found function %s in model %s" % (looking_for_fxn, self.model) reboot_fxn = getattr(self, looking_for_fxn) - ret = self.catcherror(reboot_fxn, node_port) + ret = self.catcherror(reboot_fxn, node_port, dryrun) return ret @@ -523,6 +537,21 @@ def reboot_test_new(nodename, values, verbose, dryrun): return rb_ret +def reboot_simple(nodeid, values, verbose, dryrun): + rb_ret = "" + try: + # Find the index of the given nodeid; use the same index in the ports list + port = values['ports'][values['node_ids'].index(nodeid)] + object = eval('%s(values, verbose)' % values['model']) + rb_ret = object.reboot(port, dryrun) + # TODO: how to handle the weird, georgetown pcus, the drac faults, and ilo faults? + except ExceptionPort, err: + rb_ret = str(err) + except NameError, err: + rb_ret = str(err) + + return rb_ret + def main(): print "this does not work."