sonic-buildimage/device/accton/x86_64-accton_as5812_54t-r0/plugins/psuutil.py
Roy Lee 9179990ba1 [device][accton] Add as5812-54t. (#3428)
* Verified as5812_54t platfrom, except SDK and monitor.
Signed-off-by: roy_lee <roy_lee@accton.com>

* Add as5812-54t to build its debian package.
Signed-off-by: roy_lee <roy_lee@accton.com>

* Use the right cpld read/write api.
Signed-off-by: roy_lee <roy_lee@accton.com>

* Update device paths.
Signed-off-by: roy_lee <roy_lee@accton.com>

* update psu driver, correct python lib location.
Signed-off-by: roy_lee <roy_lee@accton.com>

* Give a default return value.
Signed-off-by: roy_lee <roy_lee@accton.com>
2019-09-10 22:07:13 -07:00

66 lines
1.8 KiB
Python
Executable File

#!/usr/bin/env python
#############################################################################
# Accton
#
# Module contains an implementation of SONiC PSU Base API and
# provides the PSUs status which are available in the platform
#
#############################################################################
import os.path
try:
from sonic_psu.psu_base import PsuBase
except ImportError as e:
raise ImportError (str(e) + "- required module not found")
class PsuUtil(PsuBase):
"""Platform-specific PSUutil class"""
def __init__(self):
PsuBase.__init__(self)
self.psu_path = "/sys/bus/i2c/devices/"
self.psu_presence = "/psu_present"
self.psu_oper_status = "/psu_power_good"
self.psu_mapping = {
1: ["11-0038", "11-0050"],
2: ["12-003b", "12-0053"],
}
def get_num_psus(self):
return len(self.psu_mapping)
def get_psu_status(self, index):
if index is None:
return False
status = 0
lst = self.psu_mapping[index]
for i in lst:
node = self.psu_path + i + self.psu_oper_status
try:
with open(node, 'r') as power_status:
status += int(power_status.read())
except IOError:
return False
return status > 0
def get_psu_presence(self, index):
if index is None:
return False
status = 0
lst = self.psu_mapping[index]
for i in lst:
node = self.psu_path + i + self.psu_presence
try:
with open(node, 'r') as presence_status:
status += int(presence_status.read())
except IOError:
return False
return status > 0