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 BayTechRPC16(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 self.transport.open(self.host, self.username, None, "Enter user name:")
31 self.transport.sendPassword(self.password, "Enter Password:")
33 #self.transport.ifThenSend("RPC-16>", "Status")
35 self.transport.ifThenSend("RPC-16>", "Reboot %d" % node_port)
37 # Reboot Outlet N (Y/N)?
39 self.transport.ifThenSend("(Y/N)?", "N")
41 self.transport.ifThenSend("(Y/N)?", "Y")
42 self.transport.ifThenSend("RPC-16>", "")
44 self.transport.close()
47 class BayTechCtrlCUnibe(PCUControl):
49 For some reason, these units let you log in fine, but they hang
50 indefinitely, unless you send a Ctrl-C after the password. No idea
53 supported_ports = [22]
54 def run_ssh(self, node_port, dryrun):
55 print "BayTechCtrlC %s" % self.host
57 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
59 if not s.login(self.host, self.username, self.password, ssh_options):
60 raise ExceptionPassword("Invalid Password")
61 # Otherwise, the login succeeded.
63 # Send a ctrl-c to the remote process.
64 print "sending ctrl-c"
67 # Control Outlets (5 ,1).........5
69 #index = s.expect("Enter Request")
70 index = s.expect(["Enter Request :"])
76 index = s.expect(["DS-RPC>", "Enter user name:"])
78 s.send(self.username + "\r\n")
80 index = s.expect(["DS-RPC>"])
83 print "Reboot %d" % node_port
85 s.send("Reboot %d\r\n" % node_port)
88 index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
97 raise ExceptionPrompt("PCU Reported 'Port in use.'")
99 raise ExceptionSequence("Issued command 'Reboot' failed.")
102 index = s.expect(["DS-RPC>"])
103 #print "got prompt back"
108 raise ExceptionPrompt("EOF before expected Prompt")
109 except pexpect.TIMEOUT:
110 raise ExceptionPrompt("Timeout before expected Prompt")
114 class BayTechCtrlC(PCUControl):
116 For some reason, these units let you log in fine, but they hang
117 indefinitely, unless you send a Ctrl-C after the password. No idea
120 supported_ports = [22]
121 def run_ssh(self, node_port, dryrun):
122 print "BayTechCtrlC %s" % self.host
124 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
127 if not s.login(self.host, self.username, self.password, ssh_options):
128 raise ExceptionPassword("Invalid Password")
130 raise ExceptionNoTransport("No Connection Possible")
133 # Otherwise, the login succeeded.
135 # Send a ctrl-c to the remote process.
136 print "SENDING ctrl-c"
139 # Control Outlets (5 ,1).........5
141 print "EXPECTING: ", "Enter Request :"
142 index = s.expect(["Enter Request :"])
147 print "EXPECTING: ", "DS-RPC>"
148 index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
150 print "sending username"
151 s.send(self.username + "\r\n")
152 index = s.expect(["DS-RPC>"])
154 raise ExceptionPrompt("PCU Reported 'Port in use.'")
157 print "SENDING: Reboot %d" % node_port
158 s.send("Reboot %d\r\n" % node_port)
162 print "EXPECTING: ", "Y/N?"
163 index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
172 raise ExceptionPrompt("PCU Reported 'Port in use.'")
174 raise ExceptionSequence("Issued command 'Reboot' failed.")
176 # NOTE: for some reason, the script times out with the
177 # following line. In manual tests, it works correctly, but
178 # with automated tests, evidently it fails.
181 #print "TOTAL--", s.allstr, "--EOT"
182 index = s.expect(["DS-RPC>"])
183 print "got prompt back"
188 raise ExceptionPrompt("EOF before 'Enter Request' Prompt")
189 except pexpect.TIMEOUT:
190 raise ExceptionPrompt("Timeout before Prompt")
194 class BayTech(PCUControl):
195 supported_ports = [22,23]
197 def run_telnet(self, node_port, dryrun):
198 return self.run_ssh(node_port, dryrun)
200 def run_ssh(self, node_port, dryrun):
201 self.transport.open(self.host, self.username)
202 self.transport.sendPassword(self.password)
204 # Control Outlets (5 ,1).........5
205 self.transport.ifThenSend("Enter Request :", "5")
209 self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port, ExceptionNotFound)
210 except ExceptionNotFound, msg:
211 # one machine is configured to ask for a username,
212 # even after login...
213 print "msg: %s" % msg
214 self.transport.write(self.username + "\r\n")
216 self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port)
218 # Reboot Outlet N (Y/N)?
220 self.transport.ifThenSend("(Y/N)?", "N")
222 self.transport.ifThenSend("(Y/N)?", "Y")
224 self.transport.ifThenSend("DS-RPC>", "")
226 self.transport.close()