Verify expect versions of DRAC, HPiLO and updates to APCControl, & OpenIPMI
[pcucontrol.git] / pcucontrol / models / OpenIPMI.py
1
2 from pcucontrol.reboot import *
3 import subprocess
4
5 class OpenIPMI(PCUControl):
6
7         supported_ports = [80,443,623]
8
9         # TODO: get exit codes to determine success or failure...
10         def run_http(self, node_port, dryrun):
11                 return self.run_ipmi(node_port, dryrun)
12         def run_https(self, node_port, dryrun):
13                 return self.run_ipmi(node_port, dryrun)
14
15         def run_ipmi(self, node_port, dryrun):
16
17                 if not dryrun:
18                         ipmi_cmd = "power cycle"
19                 else:
20                         ipmi_cmd = "user list"
21
22                 cmd = "ipmitool -I lanplus -H %s -U %s -P '%s' %s"
23                 cmd = cmd % ( self.host, self.username, self.password, ipmi_cmd )
24                 p = subprocess.Popen(cmd, shell=True, 
25                                            stdin=subprocess.PIPE, stdout=subprocess.PIPE, 
26                                            stderr=subprocess.STDOUT, close_fds=True)
27                 (i,p) = (p.stdin, p.stdout)
28                 result = p.read()
29                 #print "RESULT: ", result
30
31                 if "Error" in result:
32                         return result
33                 else:
34                         return 0