give noop myops xmlrpc call a extra parameter to allow it to work with the
[monitor.git] / pcucontrol / models / BayTech.py
1 from pcucontrol.reboot import *
2
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)
7
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:")
11
12                 #self.transport.ifThenSend("RPC-16>", "Status")
13                 self.transport.ifThenSend("RPC3-NC>", "Reboot %d" % node_port)
14
15                 # Reboot Outlet  N        (Y/N)?
16                 if dryrun:
17                         self.transport.ifThenSend("(Y/N)?", "N")
18                 else:
19                         self.transport.ifThenSend("(Y/N)?", "Y")
20                 self.transport.ifThenSend("RPC3-NC>", "")
21
22                 self.transport.close()
23                 return 0
24
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:")
32
33                 #self.transport.ifThenSend("RPC-16>", "Status")
34
35                 self.transport.ifThenSend("RPC-16>", "Reboot %d" % node_port)
36
37                 # Reboot Outlet  N        (Y/N)?
38                 if dryrun:
39                         self.transport.ifThenSend("(Y/N)?", "N")
40                 else:
41                         self.transport.ifThenSend("(Y/N)?", "Y")
42                 self.transport.ifThenSend("RPC-16>", "")
43
44                 self.transport.close()
45                 return 0
46
47 class BayTechCtrlCUnibe(PCUControl):
48         """
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
51                 why.
52         """
53         supported_ports = [22]
54         def run_ssh(self, node_port, dryrun):
55                 print "BayTechCtrlC %s" % self.host
56
57                 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
58                 s = pxssh.pxssh()
59                 if not s.login(self.host, self.username, self.password, ssh_options):
60                         raise ExceptionPassword("Invalid Password")
61                 # Otherwise, the login succeeded.
62
63                 # Send a ctrl-c to the remote process.
64                 print "sending ctrl-c"
65                 s.send(chr(3))
66
67                 # Control Outlets  (5 ,1).........5
68                 try:
69                         #index = s.expect("Enter Request")
70                         index = s.expect(["Enter Request :"])
71
72                         if index == 0:
73                                 print "3"
74                                 s.send("3\r\n")
75                                 time.sleep(5)
76                                 index = s.expect(["DS-RPC>", "Enter user name:"])
77                                 if index == 1:
78                                         s.send(self.username + "\r\n")
79                                         time.sleep(5)
80                                         index = s.expect(["DS-RPC>"])
81
82                                 if index == 0:
83                                         print "Reboot %d" % node_port
84                                         time.sleep(5)
85                                         s.send("Reboot %d\r\n" % node_port)
86
87                                         time.sleep(5)
88                                         index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
89                                         if index == 0:
90                                                 if dryrun:
91                                                         print "sending N"
92                                                         s.send("N\r\n")
93                                                 else:
94                                                         print "sending Y"
95                                                         s.send("Y\r\n")
96                                         elif index == 1:
97                                                 raise ExceptionPrompt("PCU Reported 'Port in use.'")
98                                         elif index == 2:
99                                                 raise ExceptionSequence("Issued command 'Reboot' failed.")
100
101                                 time.sleep(5)
102                                 index = s.expect(["DS-RPC>"])
103                                 #print "got prompt back"
104
105                         s.close()
106
107                 except pexpect.EOF:
108                         raise ExceptionPrompt("EOF before expected Prompt")
109                 except pexpect.TIMEOUT:
110                         raise ExceptionPrompt("Timeout before expected Prompt")
111
112                 return 0
113
114 class BayTechCtrlC(PCUControl):
115         """
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
118                 why.
119         """
120         supported_ports = [22]
121         def run_ssh(self, node_port, dryrun):
122                 print "BayTechCtrlC %s" % self.host
123
124                 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
125                 s = pxssh.pxssh()
126                 try:
127                         if not s.login(self.host, self.username, self.password, ssh_options):
128                                 raise ExceptionPassword("Invalid Password")
129                 except pexpect.EOF:
130                         raise ExceptionNoTransport("No Connection Possible")
131                         
132                         
133                 # Otherwise, the login succeeded.
134
135                 # Send a ctrl-c to the remote process.
136                 print "SENDING ctrl-c"
137                 s.send(chr(3))
138
139                 # Control Outlets  (5 ,1).........5
140                 try:
141                         print "EXPECTING: ", "Enter Request :"
142                         index = s.expect(["Enter Request :"])
143
144                         if index == 0:
145                                 print "SENDING: 5"
146                                 s.send("5\r\n")
147                                 print "EXPECTING: ", "DS-RPC>"
148                                 index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
149                                 if index == 1:
150                                         print "sending username"
151                                         s.send(self.username + "\r\n")
152                                         index = s.expect(["DS-RPC>"])
153                                 elif index == 2:
154                                         raise ExceptionPrompt("PCU Reported 'Port in use.'")
155
156                                 if index == 0:
157                                         print "SENDING: Reboot %d" % node_port
158                                         s.send("Reboot %d\r\n" % node_port)
159
160                                         print "SLEEPING: 5"
161                                         time.sleep(5)
162                                         print "EXPECTING: ", "Y/N?"
163                                         index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
164                                         if index == 0:
165                                                 if dryrun:
166                                                         print "sending N"
167                                                         s.send("N\r\n")
168                                                 else:
169                                                         print "SENDING: Y"
170                                                         s.send("Y\r\n")
171                                         elif index == 1:
172                                                 raise ExceptionPrompt("PCU Reported 'Port in use.'")
173                                         elif index == 2:
174                                                 raise ExceptionSequence("Issued command 'Reboot' failed.")
175
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.
179                                 print "SLEEPING: 5"
180                                 time.sleep(5)
181                                 #print "TOTAL--", s.allstr, "--EOT"
182                                 index = s.expect(["DS-RPC>"])
183                                 print "got prompt back"
184
185                         s.close()
186
187                 except pexpect.EOF:
188                         raise ExceptionPrompt("EOF before 'Enter Request' Prompt")
189                 except pexpect.TIMEOUT:
190                         raise ExceptionPrompt("Timeout before Prompt")
191
192                 return 0
193
194
195 class BayTech5CtrlC(PCUControl):
196         """
197                 For some reason, these units let you log in fine, but they hang
198                 indefinitely, unless you send a Ctrl-C after the password.  No idea
199                 why.
200         """
201         supported_ports = [22]
202         def run_ssh(self, node_port, dryrun):
203                 print "BayTech5CtrlC %s" % self.host
204
205                 ssh_options="-o StrictHostKeyChecking=no -o PasswordAuthentication=yes -o PubkeyAuthentication=no"
206                 s = pxssh.pxssh()
207                 try:
208                         if not s.login(self.host, self.username, self.password, ssh_options):
209                                 raise ExceptionPassword("Invalid Password")
210                 except pexpect.EOF:
211                         raise ExceptionNoTransport("No Connection Possible")
212                         
213                         
214                 # Otherwise, the login succeeded.
215                 # Control Outlets  (5 ,1).........5
216                 try:
217                         print "EXPECTING: ", "Enter Request :"
218                         s.send("\r\n")
219                         time.sleep(2)
220                         index = s.expect(["Enter Request"])
221
222                         if index == 0:
223                                 print "SENDING: 5"
224                                 s.send("5\r\n")
225                                 print "EXPECTING: ", "DS-RPC>"
226                                 time.sleep(3)
227                                 # Send a ctrl-c to the remote process.
228                                 #print "SENDING ctrl-c"
229                                 #s.send(chr(3))
230
231                                 index = s.expect(["DS-RPC>", "Enter user name:", "Port in use."])
232                                 if index == 1:
233                                         print "sending username"
234                                         s.send(self.username + "\r\n")
235                                         index = s.expect(["DS-RPC>"])
236                                 elif index == 2:
237                                         raise ExceptionPrompt("PCU Reported 'Port in use.'")
238
239                                 if index == 0:
240                                         print "SENDING: Reboot %d" % node_port
241                                         #s.send("Reboot %d\r\n" % node_port)
242                                         s.send("Reboot %d\r" % node_port)
243
244                                         print "SLEEPING: 5"
245                                         time.sleep(5)
246                                         print "EXPECTING: ", "Y/N?"
247                                         index = s.expect(["\(Y/N\)\?", "Port in use", "DS-RPC>"])
248                                         if index == 0:
249                                                 if dryrun:
250                                                         print "sending N"
251                                                         s.send("N\r\n")
252                                                 else:
253                                                         print "SENDING: Y"
254                                                         s.send("Y\r\n")
255                                         elif index == 1:
256                                                 raise ExceptionPrompt("PCU Reported 'Port in use.'")
257                                         elif index == 2:
258                                                 raise ExceptionSequence("Issued command 'Reboot' failed.")
259
260                                 # NOTE: for some reason, the script times out with the
261                                 # following line.  In manual tests, it works correctly, but
262                                 # with automated tests, evidently it fails.
263                                 print "SLEEPING: 5"
264                                 time.sleep(5)
265                                 #print "TOTAL--", s.allstr, "--EOT"
266                                 index = s.expect(["DS-RPC>"])
267                                 print "got prompt back"
268
269                         s.close()
270
271                 except pexpect.EOF:
272                         raise ExceptionPrompt("EOF before 'Enter Request' Prompt")
273                 except pexpect.TIMEOUT:
274                         raise ExceptionPrompt("Timeout before Prompt")
275
276                 return 0
277
278 class BayTech(PCUControl):
279         supported_ports = [22,23]
280
281         def run_telnet(self, node_port, dryrun):
282                 return self.run_ssh(node_port, dryrun)
283
284         def run_ssh(self, node_port, dryrun):
285                 self.transport.open(self.host, self.username)
286                 self.transport.sendPassword(self.password)
287
288                 # Control Outlets  (5 ,1).........5
289                 self.transport.ifThenSend("Enter Request :", "5")
290
291                 # Reboot N
292                 try:
293                         self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port, ExceptionNotFound)
294                 except ExceptionNotFound, msg:
295                         # one machine is configured to ask for a username,
296                         # even after login...
297                         print "msg: %s" % msg
298                         self.transport.write(self.username + "\r\n")
299                         time.sleep(5)
300                         self.transport.ifThenSend("DS-RPC>", "Reboot %d" % node_port)
301
302                 # Reboot Outlet  N        (Y/N)?
303                 if dryrun:
304                         self.transport.ifThenSend("(Y/N)?", "N")
305                 else:
306                         self.transport.ifThenSend("(Y/N)?", "Y")
307                 time.sleep(5)
308                 self.transport.ifThenSend("DS-RPC>", "")
309
310                 self.transport.close()
311                 return 0