# reboot_sequence = []
def run(self, node_port, dryrun):
- print "RUNNING!!!!!!!!!!!!"
+ #print "RUNNING!!!!!!!!!!!!"
if self.transport.type == Transport.HTTPS or self.type == Transport.HTTP:
- print "APC via http...."
+ #print "APC via http...."
return self.run_http_or_https(node_port, dryrun)
else:
- print "APC via telnet/ssh...."
+ #print "APC via telnet/ssh...."
return self.run_telnet_or_ssh(node_port, dryrun)
def pcu_run(self, node_port, dryrun=False):
raise ExceptionNoTransport("Unsupported transport for http command")
cmd = cmd % ( self.username, self.password, self.host)
- print "CMD: %s" % cmd
+ #print "CMD: %s" % cmd
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
return 0
else:
# NOTE: an error has occurred, so no need to log out.
- print "RESULT: ", result
+ #print "RESULT: ", result
return result
def get_https_cmd(self):
version = self.get_version()
- print "VERSION: %s" % version
+ #print "VERSION: %s" % version
if "AP96" in version:
cmd = "curl -s --insecure --user '%s:%s' https://%s/outlets.htm " + \
" | grep -E '^[^<]+' " + \
def get_http_cmd(self):
version = self.get_version()
- print "VERSION: %s" % version
+ #print "VERSION: %s" % version
if "AP7900" in version:
cmd = "curl -s --anyauth --user '%s:%s' http://%s/rPDUout.htm | grep -E '^[^<]+'"
elif "AP7920" in version:
cmd = "curl -s --anyauth --user '%s:%s' http://%s/ms3out.htm | grep -E '^[^<]+' "
else:
# default case...
- print "USING DEFAULT"
+ #print "USING DEFAULT"
cmd = "curl -s --anyauth --user '%s:%s' http://%s/ms3out.htm | grep -E '^[^<]+' "
return cmd
cmd = cmd % ( self.username, self.password, self.host)
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE).stdout
- print p.read()
+ #print p.read()
class APCControl12p3(APCControl):
def run_telnet_or_ssh(self, node_port, dryrun):
class APCControl121p3(APCControl):
def run_telnet_or_ssh(self, node_port, dryrun):
- print "TEST! "
+ #print "TEST! "
self.reboot_sequence = ["1", "2", "1", str(node_port), "3"]
return super(APCControl121p3, self).run_telnet_or_ssh(node_port, dryrun)
"""
supported_ports = [22]
def run_ssh(self, node_port, dryrun):
- print "BayTechCtrlC %s" % self.host
+ #print "BayTechCtrlC %s" % self.host
ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
s = pxssh.pxssh()
# Otherwise, the login succeeded.
# Send a ctrl-c to the remote process.
- print "sending ctrl-c"
+ #print "sending ctrl-c"
s.send(chr(3))
# Control Outlets (5 ,1).........5
index = s.expect(["Enter Request :"])
if index == 0:
- print "3"
+ #print "3"
s.send("3\r\n")
time.sleep(5)
index = s.expect(["DS-RPC>", "Enter user name:"])
index = s.expect(["DS-RPC>"])
if index == 0:
- print "Reboot %d" % node_port
+ #print "Reboot %d" % node_port
time.sleep(5)
s.send("Reboot %d\r\n" % node_port)
index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
if index == 0:
if dryrun:
- print "sending N"
+ #print "sending N"
s.send("N\r\n")
else:
- print "sending Y"
+ #print "sending Y"
s.send("Y\r\n")
elif index == 1:
raise ExceptionPrompt("PCU Reported 'Port in use.'")
"""
supported_ports = [22]
def run_ssh(self, node_port, dryrun):
- print "BayTechCtrlC %s" % self.host
+ #print "BayTechCtrlC %s" % self.host
ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
s = pxssh.pxssh()
# Otherwise, the login succeeded.
# Send a ctrl-c to the remote process.
- print "SENDING ctrl-c"
+ #print "SENDING ctrl-c"
s.send(chr(3))
# Control Outlets (5 ,1).........5
try:
- print "EXPECTING: ", "Enter Request :"
+ #print "EXPECTING: ", "Enter Request :"
index = s.expect(["Enter Request :"])
if index == 0:
- print "SENDING: 5"
+ #print "SENDING: 5"
s.send("5\r\n")
- print "EXPECTING: ", "DS-RPC>"
+ #print "EXPECTING: ", "DS-RPC>"
index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
if index == 1:
- print "sending username"
+ #print "sending username"
s.send(self.username + "\r\n")
index = s.expect(["DS-RPC>"])
elif index == 2:
raise ExceptionPrompt("PCU Reported 'Port in use.'")
if index == 0:
- print "SENDING: Reboot %d" % node_port
+ #print "SENDING: Reboot %d" % node_port
s.send("Reboot %d\r\n" % node_port)
- print "SLEEPING: 5"
+ #print "SLEEPING: 5"
time.sleep(5)
- print "EXPECTING: ", "Y/N?"
+ #print "EXPECTING: ", "Y/N?"
index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
if index == 0:
if dryrun:
- print "sending N"
+ #print "sending N"
s.send("N\r\n")
else:
- print "SENDING: Y"
+ #print "SENDING: Y"
s.send("Y\r\n")
elif index == 1:
raise ExceptionPrompt("PCU Reported 'Port in use.'")
# 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.
- print "SLEEPING: 5"
+ #print "SLEEPING: 5"
time.sleep(5)
#print "TOTAL--", s.allstr, "--EOT"
index = s.expect(["DS-RPC>"])
- print "got prompt back"
+ #print "got prompt back"
s.close()
"""
supported_ports = [22]
def run_ssh(self, node_port, dryrun):
- print "BayTech5CtrlC %s" % self.host
+ #print "BayTech5CtrlC %s" % self.host
ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
s = pxssh.pxssh()
# Otherwise, the login succeeded.
# Control Outlets (5 ,1).........5
try:
- print "EXPECTING: ", "Enter Request :"
+ #print "EXPECTING: ", "Enter Request :"
s.send("\r\n")
time.sleep(2)
index = s.expect(["Enter Request"])
if index == 0:
- print "SENDING: 5"
+ #print "SENDING: 5"
s.send("5\r\n")
- print "EXPECTING: ", "DS-RPC>"
+ #print "EXPECTING: ", "DS-RPC>"
time.sleep(3)
# Send a ctrl-c to the remote process.
- #print "SENDING ctrl-c"
+ ##print "SENDING ctrl-c"
#s.send(chr(3))
index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
if index == 1:
- print "sending username"
+ #print "sending username"
s.send(self.username + "\r\n")
index = s.expect(["DS-RPC>"])
elif index == 2:
raise ExceptionPrompt("PCU Reported 'Port in use.'")
if index == 0:
- print "SENDING: Reboot %d" % node_port
+ #print "SENDING: Reboot %d" % node_port
#s.send("Reboot %d\r\n" % node_port)
s.send("Reboot %d\r" % node_port)
- print "SLEEPING: 5"
+ #print "SLEEPING: 5"
time.sleep(5)
- print "EXPECTING: ", "Y/N?"
+ #print "EXPECTING: ", "Y/N?"
index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
if index == 0:
if dryrun:
- print "sending N"
+ #print "sending N"
s.send("N\r\n")
else:
- print "SENDING: Y"
+ #print "SENDING: Y"
s.send("Y\r\n")
elif index == 1:
raise ExceptionPrompt("PCU Reported 'Port in use.'")
# 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.
- print "SLEEPING: 5"
+ #print "SLEEPING: 5"
time.sleep(5)
#print "TOTAL--", s.allstr, "--EOT"
index = s.expect(["DS-RPC>"])
- print "got prompt back"
+ #print "got prompt back"
s.close()
except ExceptionNotFound, msg:
# one machine is configured to ask for a username,
# even after login...
- print "msg: %s" % msg
+ #print "msg: %s" % msg
self.transport.write(self.username + "\r\n")
time.sleep(5)
self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port)
p = os.popen(cmd)
result = p.read()
- print "RESULT: ", result
+ #print "RESULT: ", result
if len(result.split()) > 3:
return 0
self.transport.ifThenSend("Password >", self.password, ExceptionPassword)
self.transport.write("\r\n\r\n")
if not dryrun: # P# - Pulse relay
- print "node_port %s" % node_port
+ #print "node_port %s" % node_port
self.transport.ifThenSend("Enter >",
"P%s"%node_port,
ExceptionNotFound)
- print "send newlines"
+ #print "send newlines"
self.transport.write("\r\n\r\n")
- print "after new lines"
+ #print "after new lines"
# Get the next prompt
- print "wait for enter"
+ #print "wait for enter"
self.transport.ifElse("Enter >", ExceptionTimeout)
- print "closing "
+ #print "closing "
self.transport.close()
return 0
power_on = False
- print "open socket"
+ #print "open socket"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
- print "connect"
+ #print "connect"
s.connect((self.host, 9100))
except socket.error, e:
s.close()
raise Exception(e)
# get current status
- print "Checking status"
+ #print "Checking status"
s.send(self.format_msg("", 'O'))
ret = self.recv_noblock(s, 8)
- print "Current status is '%s'" % ret
+ #print "Current status is '%s'" % ret
if ret == '':
raise Exception("Status returned 'another session already open' on %s %s : %s" % (self.host, node_port, ret))
if not dryrun:
if power_on:
- print "Pulsing %s" % node_port
+ #print "Pulsing %s" % node_port
s.send(self.format_msg("%s" % node_port, 'P'))
else:
# NOTE: turn power on ; do not pulse the port.
- print "Power was off, so turning on ..."
+ #print "Power was off, so turning on ..."
s.send(self.format_msg("%s" % node_port, 'E'))
#s.send(self.format_msg("%s" % node_port, 'P'))
- print "Receiving response."
+ #print "Receiving response."
ret = self.recv_noblock(s, 8)
- print "Current status is '%s'" % ret
+ #print "Current status is '%s'" % ret
if node_port < len(ret):
status = ret[node_port]
else:
cmd_str += " -A http://%s:16992/RemoteControlService -user admin -pass '%s' " % (self.host, self.password )
- print cmd_str
+ #print cmd_str
return cmd.system(cmd_str, Transport.TELNET_TIMEOUT)
# NOTE: this is expected to fail initially
pass
else:
- print self.url
- print "-----------"
- print handle.read()
- print "-----------"
- return "ERROR: not protected by HTTP authentication"
+ #print self.url
+ #print "-----------"
+ r = handle.read()
+ #print "-----------"
+ return "ERROR: not protected by HTTP authentication: %s" % r
if not hasattr(e, 'code') or e.code != 401:
return "ERROR: failed for: %s" % str(e)
authinfo = { "pwd" : self.password }
data = urllib.urlencode(authinfo)
req = urllib2.Request(self.url + "/elogin.html", data)
- print self.url
- print data
+ #print self.url
+ #print data
response = urllib2.urlopen(req)
reply = response.read()
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:
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
PCUModel.__init__(self, plc_pcu_record)
def run_expect_script(self, scriptname, **args):
- print "Running EXPECT: %s" % scriptname
+ #print "Running EXPECT: %s" % scriptname
locfg = command.CMD()
if 'ip' in args:
else:
host = self.host
- print args
+ #print args
if 'sequence' in args:
seq = " ".join(args['sequence'])
seq = "'%s'" % seq
cmd = cmd_str + "%s %s %s '%s' %s %s %s" % (
scriptname, host, self.username,
self.password, args['dryrun'], args['model'], seq)
- print cmd
+ #print cmd
cmd_out, cmd_err = locfg.run_noexcept("expect " + cmd)
return cmd_out.strip() + cmd_err.strip()
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, dryrun)
more unique. If that still fails then we return False.
"""
cmd = "ssh %s -l %s %s" % (ssh_options, username, server)
- print cmd
+ #print cmd
spawn.__init__(self, cmd, timeout=login_timeout)
#, "(?i)no route to host"])
i = self.expect(["(?i)are you sure you want to continue connecting", original_prompts, "(?i)password", "(?i)permission denied", "(?i)terminal type", TIMEOUT, "(?i)connection closed by remote host"])