@@ -200,16 +200,10 @@ class Psu(FixedPsu):
200
200
def __init__ (self , psu_index ):
201
201
super (Psu , self ).__init__ (psu_index )
202
202
203
- psu_voltage_out2 = os .path .join (PSU_PATH , "power/psu{}_volt_out2" .format (self .index ))
204
- psu_voltage = os .path .join (PSU_PATH , "power/psu{}_volt" .format (self .index ))
205
- # Workaround for psu voltage sysfs file as the file name differs among platforms
206
- if os .path .exists (psu_voltage_out2 ):
207
- self .psu_voltage = psu_voltage_out2
208
- else :
209
- self .psu_voltage = psu_voltage
210
- self .psu_voltage_min = self .psu_voltage + "_min"
211
- self .psu_voltage_max = self .psu_voltage + "_max"
212
- self .psu_voltage_capability = self .psu_voltage + "_capability"
203
+ self ._psu_voltage = None
204
+ self ._psu_voltage_min = None
205
+ self ._psu_voltage_max = None
206
+ self ._psu_voltage_capability = None
213
207
214
208
self .psu_current = os .path .join (PSU_PATH , self .PSU_CURRENT .format (self .index ))
215
209
self .psu_power = os .path .join (PSU_PATH , self .PSU_POWER .format (self .index ))
@@ -228,6 +222,47 @@ def __init__(self, psu_index):
228
222
from .thermal import initialize_psu_thermal
229
223
self ._thermal_list = initialize_psu_thermal (psu_index , self .get_power_available_status )
230
224
225
+ @property
226
+ def psu_voltage (self ):
227
+ if not self ._psu_voltage :
228
+ psu_voltage_out = os .path .join (PSU_PATH , "power/psu{}_volt_out2" .format (self .index ))
229
+ if os .path .exists (psu_voltage_out ):
230
+ self ._psu_voltage = psu_voltage_out
231
+ else :
232
+ psu_voltage_out = os .path .join (PSU_PATH , "power/psu{}_volt" .format (self .index ))
233
+ if os .path .exists (psu_voltage_out ):
234
+ self ._psu_voltage = psu_voltage_out
235
+
236
+ return self ._psu_voltage
237
+
238
+ @property
239
+ def psu_voltage_min (self ):
240
+ if not self ._psu_voltage_min :
241
+ psu_voltage = self .psu_voltage
242
+ if psu_voltage :
243
+ self ._psu_voltage_min = psu_voltage + "_min"
244
+
245
+ return self ._psu_voltage_min
246
+
247
+ @property
248
+ def psu_voltage_max (self ):
249
+ if not self ._psu_voltage_max :
250
+ psu_voltage = self .psu_voltage
251
+ if psu_voltage :
252
+ self ._psu_voltage_max = psu_voltage + "_max"
253
+
254
+ return self ._psu_voltage_max
255
+
256
+ @property
257
+ def psu_voltage_capability (self ):
258
+ if not self ._psu_voltage_capability :
259
+ psu_voltage = self .psu_voltage
260
+ if psu_voltage :
261
+ self ._psu_voltage_capability = psu_voltage + "_capability"
262
+
263
+ return self ._psu_voltage_capability
264
+
265
+
231
266
def get_model (self ):
232
267
"""
233
268
Retrieves the model number (or part number) of the device
@@ -272,7 +307,7 @@ def get_voltage(self):
272
307
A float number, the output voltage in volts,
273
308
e.g. 12.1
274
309
"""
275
- if self .get_powergood_status ():
310
+ if self .get_powergood_status () and self . psu_voltage :
276
311
# TODO: should we put log_func=None here? If not do this, when a PSU is back to power, some PSU related
277
312
# sysfs may not ready, read_int_from_file would encounter exception and log an error.
278
313
voltage = utils .read_int_from_file (self .psu_voltage , log_func = logger .log_info )
0 commit comments