X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=pcucontrol%2Fmodels%2FHPiLO.py;h=7a2863addaf948f9c665841f12cb42c67ee0e31e;hb=fec28d68cc164e581c476ee93fd4b4b68ef939fd;hp=78ceb0ac2d4b96167d1bea53ec732dbde040a7cb;hpb=c40d1a5b09026d2c7b52dfd029326bcaa23dff82;p=pcucontrol.git diff --git a/pcucontrol/models/HPiLO.py b/pcucontrol/models/HPiLO.py index 78ceb0a..7a2863a 100644 --- a/pcucontrol/models/HPiLO.py +++ b/pcucontrol/models/HPiLO.py @@ -1,60 +1,37 @@ from pcucontrol.reboot import * from distutils.sysconfig import get_python_lib; - -class HPiLO(PCUControl): - supported_ports = [22,443] - def run(self, node_port, dryrun): - if self.type == Transport.SSH: - return self.run_ssh(node_port, dryrun) - elif self.type == Transport.HTTP or self.type == Transport.HTTPS: - return self.run_https(node_port, dryrun) - else: - raise ExceptionNoTransport("Unimplemented Transport for HPiLO %s" % self.type) - - def run_ssh(self, node_port, dryrun): - - self.transport.open(self.host, self.username) - self.transport.sendPassword(self.password) - - # hpiLO-> - self.transport.ifThenSend("hpiLO->", "cd system1") - - # Reboot Outlet N (Y/N)? - if dryrun: - self.transport.ifThenSend("hpiLO->", "POWER") - else: - # Reset this machine - self.transport.ifThenSend("hpiLO->", "reset") - - self.transport.ifThenSend("hpiLO->", "exit") - - self.transport.close() - return 0 - - def run_https(self, node_port, dryrun): - - locfg = command.CMD() - - cmd_str = get_python_lib(1) + "/pcucontrol/models/hpilo/" - - cmd = cmd_str + "locfg.pl -s %s -f %s -u %s -p '%s' | grep 'MESSAGE' | grep -v 'No error'" % ( - self.host, cmd_str+"iloxml/Get_Network.xml", - self.username, self.password) - sout, serr = locfg.run_noexcept(cmd) - - if sout.strip() != "" or serr.strip() != "": - print "sout: %s" % sout.strip() - return sout.strip() + serr.strip() - - if not dryrun: - locfg = command.CMD() - cmd = cmd_str + "locfg.pl -s %s -f %s -u %s -p '%s' | grep 'MESSAGE' | grep -v 'No error'" % ( - self.host, cmd_str+"iloxml/Reset_Server.xml", - self.username, self.password) - sout, serr = locfg.run_noexcept(cmd) - - if sout.strip() != "": - print "sout: %s" % sout.strip() - #return sout.strip() - - return 0 +import subprocess + +class HPiLO(BasicPCUControl): + supported_ports = [443,22] + def run(self, node_port, dryrun): + if self.type == Transport.SSH: + return self.run_ssh(node_port, dryrun) + elif self.type == Transport.HTTP or self.type == Transport.HTTPS: + return self.run_https(node_port, dryrun) + else: + raise ExceptionNoTransport("Unimplemented Transport for HPiLO %s" % self.type) + + def pcu_run(self, node_port, dryrun=False): + r = self.run_https(node_port, dryrun=False) + if "No error" in r: + return r + r2 = self.run_ssh(node_port, dryrun=False) + if "No error" in r2: + return r2 + return r + " :: " +r2 + + def pcu_test(self, node_port, dryrun=True): + r = self.run_https(node_port, dryrun=True) + if "No error" in r: + return r + r2 = self.run_ssh(node_port, dryrun=True) + if "No error" in r2: + return r2 + return r + " :: " +r2 + + def run_ssh(self, node_port, dryrun): + return self.run_expect_script("HPiLO.exp ssh", dryrun=dryrun, model="None") + + def run_https(self, node_port, dryrun): + return self.run_expect_script("HPiLO.exp https", dryrun=dryrun, model="None")