+class WTIIPS4(PCUControl):
+ def run(self, node_port, dryrun):
+ self.open(self.host)
+ self.sendPassword(self.password, "Enter Password:")
+
+ self.ifThenSend("IPS> ", "/Boot %s" % node_port)
+ if not dryrun:
+ self.ifThenSend("Sure? (Y/N): ", "N")
+ else:
+ self.ifThenSend("Sure? (Y/N): ", "Y")
+
+ self.ifThenSend("IPS> ", "")
+
+ self.close()
+ return 0
+
+class ePowerSwitchGood(PCUControl):
+ # NOTE:
+ # The old code used Python's HTTPPasswordMgrWithDefaultRealm()
+ # For some reason this both doesn't work and in some cases, actually
+ # hangs the PCU. Definitely not what we want.
+ #
+ # The code below is much simpler. Just letting things fail first,
+ # and then, trying again with authentication string in the header.
+ #
+ def run(self, node_port, dryrun):
+ self.transport = None
+ self.url = "http://%s:%d/" % (self.host,80)
+ uri = "%s:%d" % (self.host,80)
+
+ req = urllib2.Request(self.url)
+ try:
+ handle = urllib2.urlopen(req)
+ except IOError, e:
+ # NOTE: this is expected to fail initially
+ pass
+ else:
+ print self.url
+ print "-----------"
+ print handle.read()
+ print "-----------"
+ return "ERROR: not protected by HTTP authentication"
+
+ if not hasattr(e, 'code') or e.code != 401:
+ return "ERROR: failed for: %s" % str(e)
+
+ base64data = base64.encodestring("%s:%s" % (self.username, self.password))[:-1]
+ # NOTE: assuming basic realm authentication.
+ authheader = "Basic %s" % base64data
+ req.add_header("Authorization", authheader)
+
+ try:
+ f = urllib2.urlopen(req)
+ except IOError, e:
+ # failing here means the User/passwd is wrong (hopefully)
+ raise ExceptionPassword("Incorrect username/password")
+
+ # NOTE: after verifying that the user/password is correct,
+ # actually reboot the given node.
+ if not dryrun:
+ try:
+ data = urllib.urlencode({'P%d' % node_port : "r"})
+ req = urllib2.Request(self.url + "cmd.html")
+ req.add_header("Authorization", authheader)
+ # add data to handler,
+ f = urllib2.urlopen(req, data)
+ if self.verbose: print f.read()
+ except:
+ import traceback; traceback.print_exc()
+
+ # fetch url one more time on cmd.html, econtrol.html or whatever.
+ # pass
+ else:
+ if self.verbose: print f.read()
+
+ 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):
+ self.url = "http://%s:%d/" % (self.host,80)
+ uri = "%s:%d" % (self.host,80)
+
+ # create authinfo
+ authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm()
+ authinfo.add_password (None, uri, self.username, self.password)
+ authhandler = urllib2.HTTPBasicAuthHandler( authinfo )
+
+ # NOTE: it doesn't seem to matter whether this authinfo is here or not.
+ transport = urllib2.build_opener(authinfo)
+ f = transport.open(self.url)
+ if self.verbose: print f.read()
+
+ if not dryrun:
+ transport = urllib2.build_opener(authhandler)
+ f = transport.open(self.url + "cmd.html", "P%d=r" % node_port)
+ if self.verbose: print f.read()
+
+ self.close()
+ return 0
+
+class ePowerSwitch(PCUControl):
+ def run(self, node_port, dryrun):
+ self.url = "http://%s:%d/" % (self.host,80)
+ uri = "%s:%d" % (self.host,80)
+
+ # TODO: I'm still not sure what the deal is here.
+ # two independent calls appear to need to be made before the
+ # reboot will succeed. It doesn't seem to be possible to do
+ # this with a single call. I have no idea why.
+
+ # create authinfo
+ authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm()
+ authinfo.add_password (None, uri, self.username, self.password)
+ authhandler = urllib2.HTTPBasicAuthHandler( authinfo )
+
+ # NOTE: it doesn't seem to matter whether this authinfo is here or not.
+ transport = urllib2.build_opener()
+ f = transport.open(self.url + "elogin.html", "pwd=%s" % self.password)
+ if self.verbose: print f.read()
+
+ if not dryrun:
+ transport = urllib2.build_opener(authhandler)
+ f = transport.open(self.url + "econtrol.html", "P%d=r" % node_port)
+ if self.verbose: print f.read()
+
+ # data= "P%d=r" % node_port
+ #self.open(self.host, self.username, self.password)
+ #self.sendHTTP("elogin.html", "pwd=%s" % self.password)
+ #self.sendHTTP("econtrol.html", data)
+ #self.sendHTTP("cmd.html", data)
+
+ self.close()
+ return 0
+