sonic-buildimage/device/celestica/x86_64-cel_silverstone-r0/sonic_platform/helper.py
Wirut Getbamrung 65fc916dcf [platform/device] - Implement Silverstone platform API [Chassis/Fan] (#3706)
Implement part of the Chassis and Fan related APIs.

- Chassis APIs

get_base_mac()
get_serial_number()
get_serial_number()
get_system_eeprom_info()
get_reboot_cause()

- Fan APIs

get_direction()
get_speed()
get_target_speed()
get_speed_tolerance()
set_speed()
set_status_led()
get_target_speed()

- Fan APIs base on Device API

get_name()
get_presence()
get_model()
get_serial()
get_status()

Signed-off-by: Wirut Getbamrung wgetbumr@celestica.com
2019-11-06 18:56:17 -08:00

57 lines
1.4 KiB
Python

#!/usr/bin/env python
import os
import subprocess
HOST_CHK_CMD = "docker > /dev/null 2>&1"
EMPTY_STRING = ""
class APIHelper():
def __init__(self):
pass
def is_host(self):
return os.system(HOST_CHK_CMD) == 0
def read_txt_file(self, file_path):
try:
with open(file_path, 'r') as fd:
data = fd.read()
return data.strip()
except IOError:
pass
return None
def ipmi_raw(self, netfn, cmd):
status = True
result = ""
try:
cmd = "ipmitool raw {} {}".format(str(netfn), str(cmd))
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
except:
status = False
return status, result
def ipmi_fru_id(self, id, key=None):
status = True
result = ""
try:
cmd = "ipmitool fru print {}".format(str(
id)) if not key else "ipmitool fru print {0} | grep '{1}' ".format(str(id), str(key))
p = subprocess.Popen(
cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
raw_data, err = p.communicate()
if err == '':
result = raw_data.strip()
except:
status = False
return status, result