1 from pcucontrol.reboot import *
4 class DRAC(PCUControl):
5 supported_ports = [22,443,5869]
6 def run_drac(self, node_port, dryrun):
7 print "trying racadm_reboot..."
8 return racadm_reboot(self.host, self.username, self.password, node_port, dryrun)
10 def run_ssh(self, node_port, dryrun):
11 ssh_options="-o StrictHostKeyChecking=no "+\
12 "-o PasswordAuthentication=yes "+\
13 "-o PubkeyAuthentication=no"
15 if not s.login(self.host, self.username, self.password, ssh_options,
16 original_prompts="Dell", login_timeout=Transport.TELNET_TIMEOUT):
17 raise ExceptionPassword("Invalid Password")
23 #index = s.expect(["DRAC 5", "[%s]#" % self.username ])
24 # NOTE: be careful to escape any characters used by 're.compile'
25 index = s.expect(["\$", "\[%s\]#" % self.username ])
30 s.sendline("racadm getsysinfo")
32 s.sendline("getsysinfo")
34 print "serveraction powercycle"
36 s.sendline("racadm serveraction powercycle")
38 s.sendline("serveraction powercycle")
40 # TODO: this is really lousy. Without the sleep, the sendlines
41 # don't completely get through. Even the added, expect line
42 # returns right away without waiting for the commands above to
43 # complete... Therefore, this delay is guaranteed to fail in some
46 index = s.expect(["\$", "\[%s\]#" % self.username ])
48 print "INDEX 2:", index
52 raise ExceptionPrompt("EOF before expected Prompt")
53 except pexpect.TIMEOUT:
55 raise ExceptionPrompt("Timeout before expected Prompt")
61 ### rebooting Dell systems via RAC card
62 # Marc E. Fiuczynski - June 01 2005
63 # tested with David Lowenthal's itchy/scratchy nodes at UGA
65 def runcmd(command, args, username, password, timeout = None):
68 result_ready = threading.Condition()
72 result_ready.acquire()
77 result_ready.release()
79 def do_command(command, username, password):
82 # Popen4 is a popen-type class that combines stdout and stderr
83 p = popen2.Popen4(command)
85 # read all output data
86 p.tochild.write("%s\n" % username)
87 p.tochild.write("%s\n" % password)
89 data = p.fromchild.read()
92 # might get interrupted by a signal in poll() or waitpid()
95 set_result((retval, data))
98 if ex.errno == errno.EINTR:
101 except Exception, ex:
105 command = " ".join([command] + args)
107 worker = threading.Thread(target = do_command, args = (command, username, password, ))
108 worker.setDaemon(True)
109 result_ready.acquire()
111 result_ready.wait(timeout)
114 raise Exception, "command timed-out: '%s'" % command
116 result_ready.release()
119 if isinstance(result, Exception):
122 (retval, data) = result
123 if os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == 0:
126 out = "system command ('%s') " % command
127 if os.WIFEXITED(retval):
128 out += "failed, rc = %d" % os.WEXITSTATUS(retval)
130 out += "killed by signal %d" % os.WTERMSIG(retval)
132 out += "; output follows:\n" + data
135 def racadm_reboot(host, username, password, port, dryrun):
138 ip = socket.gethostbyname(host)
140 cmd = "/usr/sbin/racadm"
143 output = runcmd(cmd, ["-r %s -i serveraction powercycle" % ip],
146 output = runcmd(cmd, ["-r %s -i getsysinfo" % ip],
149 print "RUNCMD: %s" % output
154 except Exception, err:
155 logger.debug("runcmd raised exception %s" % err)