1 from pcucontrol.reboot import *
3 class BayTechRPC3NC(PCUControl):
4 def run_telnet(self, node_port, dryrun):
5 return self.run_ssh(node_port, dryrun)
7 def run_ssh(self, node_port, dryrun):
8 self.transport.open(self.host, self.username, None, "Enter user name:")
9 self.transport.sendPassword(self.password, "Enter Password:")
11 #self.transport.ifThenSend("RPC-16>", "Status")
12 self.transport.ifThenSend("RPC3-NC>", "Reboot %d" % node_port)
14 # Reboot Outlet N (Y/N)?
16 self.transport.ifThenSend("(Y/N)?", "N")
18 self.transport.ifThenSend("(Y/N)?", "Y")
19 self.transport.ifThenSend("RPC3-NC>", "")
21 self.transport.close()
24 class BayTechRPC16(PCUControl):
25 def run_telnet(self, node_port, dryrun):
26 return self.run_ssh(node_port, dryrun)
27 def run_ssh(self, node_port, dryrun):
28 self.transport.open(self.host, self.username, None, "Enter user name:")
29 self.transport.sendPassword(self.password, "Enter Password:")
31 #self.transport.ifThenSend("RPC-16>", "Status")
33 self.transport.ifThenSend("RPC-16>", "Reboot %d" % node_port)
35 # Reboot Outlet N (Y/N)?
37 self.transport.ifThenSend("(Y/N)?", "N")
39 self.transport.ifThenSend("(Y/N)?", "Y")
40 self.transport.ifThenSend("RPC-16>", "")
42 self.transport.close()
45 class BayTechCtrlCUnibe(PCUControl):
47 For some reason, these units let you log in fine, but they hang
48 indefinitely, unless you send a Ctrl-C after the password. No idea
51 def run_ssh(self, node_port, dryrun):
52 print "BayTechCtrlC %s" % self.host
54 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
56 if not s.login(self.host, self.username, self.password, ssh_options):
57 raise ExceptionPassword("Invalid Password")
58 # Otherwise, the login succeeded.
60 # Send a ctrl-c to the remote process.
61 print "sending ctrl-c"
64 # Control Outlets (5 ,1).........5
66 #index = s.expect("Enter Request")
67 index = s.expect(["Enter Request :"])
72 index = s.expect(["DS-RPC>", "Enter user name:"])
74 s.send(self.username + "\r\n")
75 index = s.expect(["DS-RPC>"])
78 print "Reboot %d" % node_port
80 s.send("Reboot %d\r\n" % node_port)
83 index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
92 raise ExceptionPrompt("PCU Reported 'Port in use.'")
94 raise ExceptionSequence("Issued command 'Reboot' failed.")
97 index = s.expect(["DS-RPC>"])
98 #print "got prompt back"
103 raise ExceptionPrompt("EOF before expected Prompt")
104 except pexpect.TIMEOUT:
105 raise ExceptionPrompt("Timeout before expected Prompt")
109 class BayTechCtrlC(PCUControl):
111 For some reason, these units let you log in fine, but they hang
112 indefinitely, unless you send a Ctrl-C after the password. No idea
115 def run_ssh(self, node_port, dryrun):
116 print "BayTechCtrlC %s" % self.host
118 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
120 if not s.login(self.host, self.username, self.password, ssh_options):
121 raise ExceptionPassword("Invalid Password")
122 # Otherwise, the login succeeded.
124 # Send a ctrl-c to the remote process.
125 print "SENDING ctrl-c"
128 # Control Outlets (5 ,1).........5
130 print "EXPECTING: ", "Enter Request :"
131 index = s.expect(["Enter Request :"])
136 print "EXPECTING: ", "DS-RPC>"
137 index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
139 print "sending username"
140 s.send(self.username + "\r\n")
141 index = s.expect(["DS-RPC>"])
143 raise ExceptionPrompt("PCU Reported 'Port in use.'")
146 print "SENDING: Reboot %d" % node_port
147 s.send("Reboot %d\r\n" % node_port)
151 print "EXPECTING: ", "Y/N?"
152 index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
161 raise ExceptionPrompt("PCU Reported 'Port in use.'")
163 raise ExceptionSequence("Issued command 'Reboot' failed.")
165 # NOTE: for some reason, the script times out with the
166 # following line. In manual tests, it works correctly, but
167 # with automated tests, evidently it fails.
170 #print "TOTAL--", s.allstr, "--EOT"
171 index = s.expect(["DS-RPC>"])
172 print "got prompt back"
177 raise ExceptionPrompt("EOF before 'Enter Request' Prompt")
178 except pexpect.TIMEOUT:
179 raise ExceptionPrompt("Timeout before Prompt")
183 class BayTech(PCUControl):
184 supported_ports = [22,23]
186 def run_telnet(self, node_port, dryrun):
187 return self.run_ssh(node_port, dryrun)
189 def run_ssh(self, node_port, dryrun):
190 self.transport.open(self.host, self.username)
191 self.transport.sendPassword(self.password)
193 # Control Outlets (5 ,1).........5
194 self.transport.ifThenSend("Enter Request :", "5")
198 self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port, ExceptionNotFound)
199 except ExceptionNotFound, msg:
200 # one machine is configured to ask for a username,
201 # even after login...
202 print "msg: %s" % msg
203 self.transport.write(self.username + "\r\n")
205 self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port)
207 # Reboot Outlet N (Y/N)?
209 self.transport.ifThenSend("(Y/N)?", "N")
211 self.transport.ifThenSend("(Y/N)?", "Y")
213 self.transport.ifThenSend("DS-RPC>", "")
215 self.transport.close()