2021-09-25 17:35:16 -05:00
|
|
|
#
|
|
|
|
# fanutil.py
|
|
|
|
# Platform-specific FAN status interface for SONiC
|
|
|
|
#
|
|
|
|
|
|
|
|
import sys
|
2023-01-05 18:22:09 -06:00
|
|
|
from sonic_py_common.general import getstatusoutput_noshell
|
2021-09-25 17:35:16 -05:00
|
|
|
|
2023-01-05 18:22:09 -06:00
|
|
|
SENSORS_CMD = ["docker", "exec", "-i", "pmon", "/usr/bin/sensors"]
|
2021-09-25 17:35:16 -05:00
|
|
|
DOCKER_SENSORS_CMD = "/usr/bin/sensors"
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
from sonic_fan.fan_base import FanBase
|
|
|
|
except ImportError as e:
|
|
|
|
raise ImportError(str(e) + "- required module not found")
|
|
|
|
|
|
|
|
|
|
|
|
class FanUtil(FanBase):
|
|
|
|
"""Platform-specific FanUtil class"""
|
|
|
|
_fan_mapping = {
|
|
|
|
1 : '0',
|
|
|
|
2 : '1',
|
|
|
|
3 : '2'
|
|
|
|
}
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
FanBase.__init__(self)
|
|
|
|
|
|
|
|
def isDockerEnv(self):
|
|
|
|
num_docker = open('/proc/self/cgroup', 'r').read().count(":/docker")
|
|
|
|
if num_docker > 0:
|
|
|
|
return True
|
|
|
|
|
|
|
|
def get_num_fans(self):
|
2023-01-05 18:22:09 -06:00
|
|
|
n3248pxe_MAX_FANTRAYS = 3
|
|
|
|
return n3248pxe_MAX_FANTRAYS
|
2021-09-25 17:35:16 -05:00
|
|
|
|
|
|
|
def get_presence(self, idx):
|
2023-01-05 18:22:09 -06:00
|
|
|
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
|
|
|
return int(open(sysfs_path).read(), 16)
|
2021-09-25 17:35:16 -05:00
|
|
|
|
|
|
|
def get_direction(self, idx):
|
2023-01-05 18:22:09 -06:00
|
|
|
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_dir"
|
|
|
|
return open(sysfs_path).read()
|
2021-09-25 17:35:16 -05:00
|
|
|
|
|
|
|
def get_speed(self, idx):
|
|
|
|
dockerenv = self.isDockerEnv()
|
|
|
|
if not dockerenv:
|
2023-01-05 18:22:09 -06:00
|
|
|
status, cmd_output = getstatusoutput_noshell(SENSORS_CMD)
|
|
|
|
else:
|
|
|
|
status, cmd_output = getstatusoutput_noshell(DOCKER_SENSORS_CMD)
|
2021-09-25 17:35:16 -05:00
|
|
|
if status:
|
|
|
|
print('Failed to execute sensors command')
|
|
|
|
sys.exit(0)
|
|
|
|
fan_id = 'Fan ' + str(idx)
|
|
|
|
found = False
|
|
|
|
for line in cmd_output.splitlines():
|
|
|
|
if line.startswith('emc2305-i2c-7-2c'):
|
|
|
|
found = True
|
|
|
|
if found and line.startswith(fan_id):
|
|
|
|
return line.split()[3]
|
|
|
|
return 0.0
|
|
|
|
|
|
|
|
def get_status(self, idx):
|
2023-01-05 18:22:09 -06:00
|
|
|
sysfs_path = "/sys/devices/platform/dell-n3248pxe-cpld.0/fan" + self._fan_mapping[idx] + "_prs"
|
|
|
|
return int(open(sysfs_path).read(), 16)
|
2021-09-25 17:35:16 -05:00
|
|
|
|
|
|
|
|
|
|
|
def set_speed(self, idx):
|
2023-01-05 18:22:09 -06:00
|
|
|
return False
|