+ cmd = moncommands.CMD()
+ #[cmd_str = "IntelAMTSDK/Samples/RemoteControl/remoteControl"
+ cmd_str = "cmdamt/remoteControl"
+
+ if dryrun:
+ # NOTE: -p checks the power state of the host.
+ # TODO: parse the output to find out if it's ok or not.
+ cmd_str += " -p http://%s:16992/RemoteControlService -user admin -pass '%s' " % (self.host, self.password )
+ else:
+ cmd_str += " -A http://%s:16992/RemoteControlService -user admin -pass '%s' " % (self.host, self.password )
+
+ print cmd_str
+ return cmd.system(cmd_str, self.TELNET_TIMEOUT)
+
+class DRACRacAdm(PCUControl):
+ def run(self, node_port, dryrun):
+
+ print "trying racadm_reboot..."
+ racadm_reboot(self.host, self.username, self.password, node_port, dryrun)
+
+ return 0
+
+class DRAC(PCUControl):
+ def run(self, node_port, dryrun):
+ self.open(self.host, self.username)
+ self.sendPassword(self.password)
+
+ print "logging in..."
+ self.transport.write("\r\n")
+ # Testing Reboot ?
+ if dryrun:
+ self.ifThenSend("[%s]#" % self.username, "getsysinfo")
+ else:
+ # Reset this machine
+ self.ifThenSend("[%s]#" % self.username, "serveraction powercycle")
+
+ self.ifThenSend("[%s]#" % self.username, "exit")
+
+ self.close()
+ return 0
+
+class HPiLO(PCUControl):
+ def run(self, node_port, dryrun):
+ self.open(self.host, self.username)
+ self.sendPassword(self.password)
+
+ # </>hpiLO->
+ self.ifThenSend("</>hpiLO->", "cd system1")
+
+ # Reboot Outlet N (Y/N)?
+ if dryrun:
+ self.ifThenSend("</system1>hpiLO->", "POWER")
+ else:
+ # Reset this machine
+ self.ifThenSend("</system1>hpiLO->", "reset")
+
+ self.ifThenSend("</system1>hpiLO->", "exit")
+
+ self.close()
+ return 0
+
+
+class HPiLOHttps(PCUControl):
+ def run(self, node_port, dryrun):
+
+ locfg = moncommands.CMD()
+ cmd = "cmdhttps/locfg.pl -s %s -f %s -u %s -p '%s' | grep 'MESSAGE' | grep -v 'No error'" % (
+ self.host, "iloxml/Get_Network.xml",
+ self.username, self.password)
+ sout, serr = locfg.run_noexcept(cmd)
+
+ if sout.strip() != "":
+ print "sout: %s" % sout.strip()
+ return sout.strip()
+
+ if not dryrun:
+ locfg = moncommands.CMD()
+ cmd = "cmdhttps/locfg.pl -s %s -f %s -u %s -p '%s' | grep 'MESSAGE' | grep -v 'No error'" % (
+ self.host, "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
+
+class BayTechAU(PCUControl):
+ def run(self, node_port, dryrun):
+ self.open(self.host, self.username, None, "Enter user name:")
+ self.sendPassword(self.password, "Enter Password:")
+
+ #self.ifThenSend("RPC-16>", "Status")
+ self.ifThenSend("RPC3-NC>", "Reboot %d" % node_port)
+
+ # Reboot Outlet N (Y/N)?
+ if dryrun:
+ self.ifThenSend("(Y/N)?", "N")
+ else:
+ self.ifThenSend("(Y/N)?", "Y")
+ self.ifThenSend("RPC3-NC>", "")
+
+ self.close()
+ return 0
+
+class BayTechGeorgeTown(PCUControl):
+ def run(self, node_port, dryrun):
+ # this initial open/close is to prevent things from raising an
+ # exception. the pcu always is weird during the first connection, and
+ # even if it's not, what does it matter to open a second connection
+ # right away?
+ self.open(self.host, self.username, None, "Enter user name:")
+ self.close()
+ time.sleep(1)
+ self.open(self.host, self.username, None, "Enter user name:")
+ self.sendPassword(self.password, "Enter Password:")
+
+ #self.ifThenSend("RPC-16>", "Status")
+
+ self.ifThenSend("RPC-16>", "Reboot %d" % node_port)
+
+ # Reboot Outlet N (Y/N)?
+ if dryrun:
+ self.ifThenSend("(Y/N)?", "N")
+ else:
+ self.ifThenSend("(Y/N)?", "Y")
+ self.ifThenSend("RPC-16>", "")
+
+ self.close()
+ return 0
+
+class BayTechCtrlCUnibe(PCUControl):
+ """
+ For some reason, these units let you log in fine, but they hang
+ indefinitely, unless you send a Ctrl-C after the password. No idea
+ why.
+ """
+ def run(self, node_port, dryrun):
+ print "BayTechCtrlC %s" % self.host
+
+ ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
+ s = pxssh.pxssh()
+ if not s.login(self.host, self.username, self.password, ssh_options):
+ raise ExceptionPassword("Invalid Password")
+ # Otherwise, the login succeeded.
+
+ # Send a ctrl-c to the remote process.
+ print "sending ctrl-c"
+ s.send(chr(3))
+
+ # Control Outlets (5 ,1).........5
+ try:
+ #index = s.expect("Enter Request")
+ index = s.expect(["Enter Request :"])
+
+ if index == 0:
+ print "3"
+ s.send("3\r\n")
+ index = s.expect(["DS-RPC>", "Enter user name:"])
+ if index == 1:
+ s.send(self.username + "\r\n")
+ index = s.expect(["DS-RPC>"])
+
+ if index == 0:
+ print "Reboot %d" % node_port
+ s.send("Reboot %d\r\n" % node_port)
+
+ time.sleep(5)
+ index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
+ if index == 0:
+ if dryrun:
+ print "sending N"
+ s.send("N\r\n")
+ else:
+ print "sending Y"
+ s.send("Y\r\n")
+ elif index == 1:
+ raise ExceptionPrompt("PCU Reported 'Port in use.'")
+ elif index == 2:
+ raise ExceptionSequence("Issued command 'Reboot' failed.")
+
+ time.sleep(5)
+ index = s.expect(["DS-RPC>"])
+ #print "got prompt back"
+
+ s.close()
+
+ except pexpect.EOF:
+ raise ExceptionPrompt("EOF before expected Prompt")
+ except pexpect.TIMEOUT:
+ raise ExceptionPrompt("Timeout before expected Prompt")
+
+ return 0
+
+class BayTechCtrlC(PCUControl):
+ """
+ For some reason, these units let you log in fine, but they hang
+ indefinitely, unless you send a Ctrl-C after the password. No idea
+ why.
+ """
+ def run(self, node_port, dryrun):
+ print "BayTechCtrlC %s" % self.host
+
+ ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
+ s = pxssh.pxssh()
+ if not s.login(self.host, self.username, self.password, ssh_options):
+ raise ExceptionPassword("Invalid Password")
+ # Otherwise, the login succeeded.
+
+ # Send a ctrl-c to the remote process.
+ print "SENDING ctrl-c"
+ s.send(chr(3))