3
3
# provides the PSUs status which are available in the platform
4
4
#
5
5
6
- import os .path
7
6
import subprocess
8
7
9
8
try :
@@ -17,7 +16,7 @@ class PsuUtil(PsuBase):
17
16
18
17
def __init__ (self ):
19
18
PsuBase .__init__ (self )
20
- self .psu_status = "ipmitool raw 0x38 0x1 {} 0x50"
19
+ self .psu_status = [ "ipmitool" , " raw" , " 0x38" , " 0x1" , "" , " 0x50"]
21
20
22
21
def get_num_psus (self ):
23
22
"""
@@ -39,9 +38,10 @@ def get_psu_status(self, index):
39
38
return False
40
39
41
40
status = 0
41
+ cmd = ["ipmitool" , "raw" , "0x38" , "0x2" , "7" , "0x32" , "0x28" , "1" ]
42
42
try :
43
- p = os . popen ( "ipmitool raw 0x38 0x2 7 0x32 0x28 1" )
44
- content = p .readline ().rstrip ()
43
+ p = subprocess . Popen ( cmd , stdout = subprocess . PIPE , universal_newlines = True )
44
+ content = p .stdout . readline ().rstrip ()
45
45
reg_value = int (content , 16 )
46
46
mask = (1 << (8 - index ))
47
47
if reg_value & mask == 0 :
@@ -63,9 +63,10 @@ def get_psu_presence(self, index):
63
63
if index is None :
64
64
return False
65
65
status = 0
66
+ self .psu_status [4 ] = str (index - 1 )
66
67
try :
67
- p = os . popen (self .psu_status . format ( index - 1 ) )
68
- content = p .readline ().rstrip ()
68
+ p = subprocess . Popen (self .psu_status , stdout = subprocess . PIPE , universal_newlines = True )
69
+ content = p .stdout . readline ().rstrip ()
69
70
reg_value = int (content , 16 )
70
71
if reg_value != 0 :
71
72
return False
0 commit comments