www/database.php
[monitor.git] / reboot.py
index 4cccdf0..337b0b4 100755 (executable)
--- a/reboot.py
+++ b/reboot.py
@@ -11,14 +11,13 @@ import urllib2
 import urllib
 import threading, popen2
 import array, struct
 import urllib
 import threading, popen2
 import array, struct
-#from socket import *
-import socket
 import plc
 import base64
 from subprocess import PIPE, Popen
 import ssh.pxssh as pxssh
 import ssh.pexpect as pexpect
 import socket
 import plc
 import base64
 from subprocess import PIPE, Popen
 import ssh.pxssh as pxssh
 import ssh.pexpect as pexpect
 import socket
+import moncommands 
 
 # Use our versions of telnetlib and pyssh
 sys.path.insert(0, os.path.dirname(sys.argv[0]))
 
 # Use our versions of telnetlib and pyssh
 sys.path.insert(0, os.path.dirname(sys.argv[0]))
@@ -559,10 +558,10 @@ class APC(PCUControl):
 
 class IntelAMT(PCUControl):
        def run(self, node_port, dryrun):
 
 class IntelAMT(PCUControl):
        def run(self, node_port, dryrun):
-               import soltesz
 
 
-               cmd = soltesz.CMD()
-               cmd_str = "IntelAMTSDK/Samples/RemoteControl/remoteControl"
+               cmd = moncommands.CMD()
+               #[cmd_str = "IntelAMTSDK/Samples/RemoteControl/remoteControl"
+               cmd_str = "cmdamt/remoteControl"
 
                if dryrun:
                        # NOTE: -p checks the power state of the host.
 
                if dryrun:
                        # NOTE: -p checks the power state of the host.
@@ -624,9 +623,8 @@ class HPiLO(PCUControl):
                
 class HPiLOHttps(PCUControl):
        def run(self, node_port, dryrun):
                
 class HPiLOHttps(PCUControl):
        def run(self, node_port, dryrun):
-               import soltesz
 
 
-               locfg = soltesz.CMD()
+               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)
                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)
@@ -637,7 +635,7 @@ class HPiLOHttps(PCUControl):
                        return sout.strip()
 
                if not dryrun:
                        return sout.strip()
 
                if not dryrun:
-                       locfg = soltesz.CMD()
+                       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)
                        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)
@@ -706,7 +704,9 @@ class BayTechCtrlCUnibe(PCUControl):
 
                # Control Outlets  (5 ,1).........5
                try:
 
                # Control Outlets  (5 ,1).........5
                try:
-                       index = s.expect(["Enter Request :"])
+                       print s
+                       print "Enter Request" in s.before
+                       index = s.expect("Enter Request")
 
                        if index == 0:
                                print "3"
 
                        if index == 0:
                                print "3"
@@ -786,7 +786,10 @@ class BayTechCtrlC(PCUControl):
                                                        print "sending Y"
                                                        s.send("Y\r\n")
 
                                                        print "sending Y"
                                                        s.send("Y\r\n")
 
-                               index = s.expect(["DS-RPC>"])
+                               # NOTE: for some reason, the script times out with the
+                               # following line.  In manual tests, it works correctly, but
+                               # with automated tests, evidently it fails.
+                               #index = s.expect(["DS-RPC>"])
                                #print "got prompt back"
 
                        s.close()
                                #print "got prompt back"
 
                        s.close()
@@ -904,6 +907,20 @@ class ePowerSwitchGood(PCUControl):
                self.close()
                return 0
 
                self.close()
                return 0
 
+class CustomPCU(PCUControl):
+       def run(self, node_port, dryrun):
+               url = "https://www-itec.uni-klu.ac.at/plab-pcu/index.php" 
+
+               if not dryrun:
+                       # Turn host off, then on
+                       formstr = "plab%s=off" % node_port
+                       os.system("curl --user %s:%s --form '%s' --insecure %s" % (self.username, self.password, formstr, url))
+                       time.sleep(5)
+                       formstr = "plab%s=on" % node_port
+                       os.system("curl --user %s:%s --form '%s' --insecure %s" % (self.username, self.password, formstr, url))
+               else:
+                       os.system("curl --user %s:%s --insecure %s" % (self.username, self.password, url))
+
 
 class ePowerSwitchOld(PCUControl):
        def run(self, node_port, dryrun):
 
 class ePowerSwitchOld(PCUControl):
        def run(self, node_port, dryrun):
@@ -1148,12 +1165,16 @@ def pcu_name(pcu):
        else:
                return None
 
        else:
                return None
 
-import soltesz
-fb =soltesz.dbLoad("findbadpcus")
+#import database
+from monitor import database
+fb = None
 
 def get_pcu_values(pcu_id):
 
 def get_pcu_values(pcu_id):
-       # TODO: obviously, this shouldn't be loaded each time...
-
+       global fb
+       if fb == None:
+               # this shouldn't be loaded each time...
+               fb = database.dbLoad("findbadpcus")
+               
        try:
                values = fb['nodes']["id_%s" % pcu_id]['values']
        except:
        try:
                values = fb['nodes']["id_%s" % pcu_id]['values']
        except:
@@ -1299,6 +1320,9 @@ def reboot_test(nodename, values, continue_probe, verbose, dryrun):
                                eps = ePowerSwitchGood(values, verbose, ['80'])
 
                        rb_ret = eps.reboot(values[nodename], dryrun)
                                eps = ePowerSwitchGood(values, verbose, ['80'])
 
                        rb_ret = eps.reboot(values[nodename], dryrun)
+               elif continue_probe and values['pcu_id'] in [1122]:
+                       custom = CustomPCU(values, verbose, ['80', '443'])
+                       custom.reboot(values[nodename], dryrun)
 
                elif continue_probe:
                        rb_ret = "Unsupported_PCU"
 
                elif continue_probe:
                        rb_ret = "Unsupported_PCU"