1 from pcucontrol.reboot import *
3 class DRAC(PCUControl):
4 supported_ports = [22,443,5869]
5 def run_drac(self, node_port, dryrun):
6 print "trying racadm_reboot..."
7 return racadm_reboot(self.host, self.username, self.password, node_port, dryrun)
9 def run_ssh(self, node_port, dryrun):
10 ssh_options="-o StrictHostKeyChecking=no "+\
11 "-o PasswordAuthentication=yes "+\
12 "-o PubkeyAuthentication=no"
14 if not s.login(self.host, self.username, self.password, ssh_options,
15 original_prompts="Dell", login_timeout=Transport.TELNET_TIMEOUT):
16 raise ExceptionPassword("Invalid Password")
22 #index = s.expect(["DRAC 5", "[%s]#" % self.username ])
23 # NOTE: be careful to escape any characters used by 're.compile'
24 index = s.expect(["\$", "\[%s\]#" % self.username ])
28 s.send("racadm getsysinfo")
33 s.send("racadm serveraction powercycle")
35 s.send("serveraction powercycle")
40 raise ExceptionPrompt("EOF before expected Prompt")
41 except pexpect.TIMEOUT:
43 raise ExceptionPrompt("Timeout before expected Prompt")
49 class DRACDefault(PCUControl):
50 supported_ports = [22,443,5869]
51 def run_ssh(self, node_port, dryrun):
52 self.transport.open(self.host, self.username)
53 self.transport.sendPassword(self.password)
56 self.transport.write("\r\n")
59 self.transport.ifThenSend("[%s]#" % self.username, "getsysinfo")
62 self.transport.ifThenSend("[%s]#" % self.username, "serveraction powercycle")
64 self.transport.ifThenSend("[%s]#" % self.username, "exit")
66 self.transport.close()
69 ### rebooting Dell systems via RAC card
70 # Marc E. Fiuczynski - June 01 2005
71 # tested with David Lowenthal's itchy/scratchy nodes at UGA
73 def runcmd(command, args, username, password, timeout = None):
76 result_ready = threading.Condition()
80 result_ready.acquire()
85 result_ready.release()
87 def do_command(command, username, password):
90 # Popen4 is a popen-type class that combines stdout and stderr
91 p = popen2.Popen4(command)
93 # read all output data
94 p.tochild.write("%s\n" % username)
95 p.tochild.write("%s\n" % password)
97 data = p.fromchild.read()
100 # might get interrupted by a signal in poll() or waitpid()
103 set_result((retval, data))
106 if ex.errno == errno.EINTR:
109 except Exception, ex:
113 command = " ".join([command] + args)
115 worker = threading.Thread(target = do_command, args = (command, username, password, ))
116 worker.setDaemon(True)
117 result_ready.acquire()
119 result_ready.wait(timeout)
122 raise Exception, "command timed-out: '%s'" % command
124 result_ready.release()
127 if isinstance(result, Exception):
130 (retval, data) = result
131 if os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == 0:
134 out = "system command ('%s') " % command
135 if os.WIFEXITED(retval):
136 out += "failed, rc = %d" % os.WEXITSTATUS(retval)
138 out += "killed by signal %d" % os.WTERMSIG(retval)
140 out += "; output follows:\n" + data
143 def racadm_reboot(host, username, password, port, dryrun):
146 ip = socket.gethostbyname(host)
148 cmd = "/usr/sbin/racadm"
151 output = runcmd(cmd, ["-r %s -i serveraction powercycle" % ip],
154 output = runcmd(cmd, ["-r %s -i getsysinfo" % ip],
157 print "RUNCMD: %s" % output
162 except Exception, err:
163 logger.debug("runcmd raised exception %s" % err)