Skip to content

Commit

Permalink
Added BFN PSU cache (#9)
Browse files Browse the repository at this point in the history
Signed-off-by: Andriy Kokhan <andriyx.kokhan@intel.com>
  • Loading branch information
Andriy Kokhan committed Dec 10, 2021
1 parent c55f750 commit ead20bd
Showing 1 changed file with 32 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
try:
import os
import sys
import time

sys.path.append(os.path.dirname(__file__))

Expand All @@ -18,6 +19,8 @@ class Psu(PsuBase):
def __init__(self, index):
PsuBase.__init__(self)
self.__index = index
self.__info = None
self.__ts = 0
# STUB IMPLEMENTATION
self.color = ""

Expand All @@ -33,7 +36,16 @@ def __info_get(self):
def psu_info_get(client):
return client.pltfm_mgr.pltfm_mgr_pwr_supply_info_get(self.__index)

return thrift_try(psu_info_get)
# Update cache once per 2 seconds
if self.__ts + 2 < time.time():
self.__info = None
try:
self.__info = thrift_try(psu_info_get, attempts=1)
finally:
self.__ts = time.time()
return self.__info
return self.__info


@staticmethod
def get_num_psus():
Expand All @@ -54,6 +66,8 @@ def get_powergood_status(self):
:return: Boolean, True if PSU is operating properly, False if PSU is faulty
"""
info = self.__info_get()
if info is None:
return False
return info.ffault == False and info.vout != 0

def get_voltage(self):
Expand All @@ -64,7 +78,8 @@ def get_voltage(self):
A float number, the output voltage in volts,
e.g. 12.1
"""
return float(self.__info_get().vout)
info = self.__info_get()
return float(info.vout) if info else 0

def get_current(self):
"""
Expand All @@ -73,7 +88,8 @@ def get_current(self):
Returns:
A float number, the electric current in amperes, e.g 15.4
"""
return self.__info_get().iout / 1000.
info = self.__info_get()
return info.iout / 1000 if info else 0

def get_power(self):
"""
Expand All @@ -82,7 +98,8 @@ def get_power(self):
Returns:
A float number, the power in watts, e.g. 302.6
"""
return self.__info_get().pwr_out / 1000.
info = self.__info_get()
return info.pwr_out / 1000 if info else 0

def get_presence(self):
"""
Expand All @@ -94,8 +111,11 @@ def get_presence(self):
def psu_present_get(client):
return client.pltfm_mgr.pltfm_mgr_pwr_supply_present_get(self.__index)

status = thrift_try(psu_present_get)
return status
status = False
try:
status = thrift_try(psu_present_get)
finally:
return status

def set_status_led(self, color):
"""
Expand Down Expand Up @@ -130,7 +150,8 @@ def get_serial(self):
Returns:
string: Serial number of device
"""
return self.__info_get().serial
info = self.__info_get()
return info.serial if info else "N/A"

def get_model(self):
"""
Expand All @@ -139,7 +160,8 @@ def get_model(self):
Returns:
string: Model/part number of device
"""
return self.__info_get().model
info = self.__info_get()
return info.model if info else "N/A"

def is_replaceable(self):
"""
Expand All @@ -156,7 +178,8 @@ def get_revision(self):
Returns:
string: Revision value of device
"""
return self.__info_get().rev
info = self.__info_get()
return info.rev if info else "N/A"

def get_status(self):
"""
Expand Down

0 comments on commit ead20bd

Please sign in to comment.