1 from pcucontrol.reboot import *
3 class BayTechRPC3NC(PCUControl):
4 supported_ports = [22,23]
5 def run_telnet(self, node_port, dryrun):
6 return self.run_ssh(node_port, dryrun)
8 def run_ssh(self, node_port, dryrun):
9 self.transport.open(self.host, self.username, None, "Enter user name:")
10 self.transport.sendPassword(self.password, "Enter Password:")
12 #self.transport.ifThenSend("RPC-16>", "Status")
13 self.transport.ifThenSend("RPC3-NC>", "Reboot %d" % node_port)
15 # Reboot Outlet N (Y/N)?
17 self.transport.ifThenSend("(Y/N)?", "N")
19 self.transport.ifThenSend("(Y/N)?", "Y")
20 self.transport.ifThenSend("RPC3-NC>", "")
22 self.transport.close()
25 class BayTechGeorgeTown(PCUControl):
26 supported_ports = [22,23]
27 def run_telnet(self, node_port, dryrun):
28 return self.run_ssh(node_port, dryrun)
29 def run_ssh(self, node_port, dryrun):
30 # NOTE: The georgetown pcu always drops the first connection,
31 self.transport.open(self.host, self.username, None, "Enter")
32 self.transport.close()
34 self.transport.open(self.host, self.username, None, "Enter user name:")
35 self.transport.sendPassword(self.password, "Enter Password:")
37 self.transport.ifThenSend("RPC-16>", "Reboot %d" % node_port)
39 # Reboot Outlet N (Y/N)?
41 self.transport.ifThenSend("(Y/N)?", "N")
43 self.transport.ifThenSend("(Y/N)?", "Y")
44 self.transport.ifThenSend("RPC-16>", "")
46 self.transport.close()
50 class BayTechRPC16(PCUControl):
51 supported_ports = [22,23]
52 def run_telnet(self, node_port, dryrun):
53 return self.run_ssh(node_port, dryrun)
54 def run_ssh(self, node_port, dryrun):
55 self.transport.open(self.host, self.username, None, "Enter user name:")
56 self.transport.sendPassword(self.password, "Enter Password:")
58 #self.transport.ifThenSend("RPC-16>", "Status")
60 self.transport.ifThenSend("RPC-16>", "Reboot %d" % node_port)
62 # Reboot Outlet N (Y/N)?
64 self.transport.ifThenSend("(Y/N)?", "N")
66 self.transport.ifThenSend("(Y/N)?", "Y")
67 self.transport.ifThenSend("RPC-16>", "")
69 self.transport.close()
72 class BayTechCtrlCUnibe(PCUControl):
74 For some reason, these units let you log in fine, but they hang
75 indefinitely, unless you send a Ctrl-C after the password. No idea
78 supported_ports = [22]
79 def run_ssh(self, node_port, dryrun):
80 print "BayTechCtrlC %s" % self.host
82 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
84 if not s.login(self.host, self.username, self.password, ssh_options):
85 raise ExceptionPassword("Invalid Password")
86 # Otherwise, the login succeeded.
88 # Send a ctrl-c to the remote process.
89 print "sending ctrl-c"
92 # Control Outlets (5 ,1).........5
94 #index = s.expect("Enter Request")
95 index = s.expect(["Enter Request :"])
101 index = s.expect(["DS-RPC>", "Enter user name:"])
103 s.send(self.username + "\r\n")
105 index = s.expect(["DS-RPC>"])
108 print "Reboot %d" % node_port
110 s.send("Reboot %d\r\n" % node_port)
113 index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
122 raise ExceptionPrompt("PCU Reported 'Port in use.'")
124 raise ExceptionSequence("Issued command 'Reboot' failed.")
127 index = s.expect(["DS-RPC>"])
128 #print "got prompt back"
133 raise ExceptionPrompt("EOF before expected Prompt")
134 except pexpect.TIMEOUT:
135 raise ExceptionPrompt("Timeout before expected Prompt")
139 class BayTechCtrlC(PCUControl):
141 For some reason, these units let you log in fine, but they hang
142 indefinitely, unless you send a Ctrl-C after the password. No idea
145 supported_ports = [22]
146 def run_ssh(self, node_port, dryrun):
147 print "BayTechCtrlC %s" % self.host
149 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
152 if not s.login(self.host, self.username, self.password, ssh_options):
153 raise ExceptionPassword("Invalid Password")
155 raise ExceptionNoTransport("No Connection Possible")
158 # Otherwise, the login succeeded.
160 # Send a ctrl-c to the remote process.
161 print "SENDING ctrl-c"
164 # Control Outlets (5 ,1).........5
166 print "EXPECTING: ", "Enter Request :"
167 index = s.expect(["Enter Request :"])
172 print "EXPECTING: ", "DS-RPC>"
173 index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
175 print "sending username"
176 s.send(self.username + "\r\n")
177 index = s.expect(["DS-RPC>"])
179 raise ExceptionPrompt("PCU Reported 'Port in use.'")
182 print "SENDING: Reboot %d" % node_port
183 s.send("Reboot %d\r\n" % node_port)
187 print "EXPECTING: ", "Y/N?"
188 index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
197 raise ExceptionPrompt("PCU Reported 'Port in use.'")
199 raise ExceptionSequence("Issued command 'Reboot' failed.")
201 # NOTE: for some reason, the script times out with the
202 # following line. In manual tests, it works correctly, but
203 # with automated tests, evidently it fails.
206 #print "TOTAL--", s.allstr, "--EOT"
207 index = s.expect(["DS-RPC>"])
208 print "got prompt back"
213 raise ExceptionPrompt("EOF before 'Enter Request' Prompt")
214 except pexpect.TIMEOUT:
215 raise ExceptionPrompt("Timeout before Prompt")
220 class BayTech5CtrlC(PCUControl):
222 For some reason, these units let you log in fine, but they hang
223 indefinitely, unless you send a Ctrl-C after the password. No idea
226 supported_ports = [22]
227 def run_ssh(self, node_port, dryrun):
228 print "BayTech5CtrlC %s" % self.host
230 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
233 if not s.login(self.host, self.username, self.password, ssh_options):
234 raise ExceptionPassword("Invalid Password")
236 raise ExceptionNoTransport("No Connection Possible")
239 # Otherwise, the login succeeded.
240 # Control Outlets (5 ,1).........5
242 print "EXPECTING: ", "Enter Request :"
245 index = s.expect(["Enter Request"])
250 print "EXPECTING: ", "DS-RPC>"
252 # Send a ctrl-c to the remote process.
253 #print "SENDING ctrl-c"
256 index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
258 print "sending username"
259 s.send(self.username + "\r\n")
260 index = s.expect(["DS-RPC>"])
262 raise ExceptionPrompt("PCU Reported 'Port in use.'")
265 print "SENDING: Reboot %d" % node_port
266 #s.send("Reboot %d\r\n" % node_port)
267 s.send("Reboot %d\r" % node_port)
271 print "EXPECTING: ", "Y/N?"
272 index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
281 raise ExceptionPrompt("PCU Reported 'Port in use.'")
283 raise ExceptionSequence("Issued command 'Reboot' failed.")
285 # NOTE: for some reason, the script times out with the
286 # following line. In manual tests, it works correctly, but
287 # with automated tests, evidently it fails.
290 #print "TOTAL--", s.allstr, "--EOT"
291 index = s.expect(["DS-RPC>"])
292 print "got prompt back"
297 raise ExceptionPrompt("EOF before 'Enter Request' Prompt")
298 except pexpect.TIMEOUT:
299 raise ExceptionPrompt("Timeout before Prompt")
303 class BayTech(PCUControl):
304 supported_ports = [22,23]
306 def run_telnet(self, node_port, dryrun):
307 return self.run_ssh(node_port, dryrun)
309 def run_ssh(self, node_port, dryrun):
310 self.transport.open(self.host, self.username)
311 self.transport.sendPassword(self.password)
313 # Control Outlets (5 ,1).........5
314 self.transport.ifThenSend("Enter Request :", "5")
318 self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port, ExceptionNotFound)
319 except ExceptionNotFound, msg:
320 # one machine is configured to ask for a username,
321 # even after login...
322 print "msg: %s" % msg
323 self.transport.write(self.username + "\r\n")
325 self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port)
327 # Reboot Outlet N (Y/N)?
329 self.transport.ifThenSend("(Y/N)?", "N")
331 self.transport.ifThenSend("(Y/N)?", "Y")
333 self.transport.ifThenSend("DS-RPC>", "")
335 self.transport.close()