Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 54 additions & 47 deletions device/celestica/x86_64-cel_seastone_2-r0/sonic_platform/chassis.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def __init__(self):
self.__initialize_fan()
self.__initialize_psu()
self.__initialize_thermals()
self.__initialize_sfp()
self.__initialize_eeprom()

# self.is_host = self._api_common.is_host()
Expand All @@ -57,12 +58,18 @@ def __initialize_fan(self):
fan_index += 1
self._fan_list.append(fan)

# def __initialize_sfp(self):
# from sonic_platform.sfp import Sfp
# for index in range(0, NUM_SFP):
# sfp = Sfp(index)
# self._sfp_list.append(sfp)
# self.sfp_module_initialized = True
def __initialize_sfp(self):
from sonic_platform.sfp import Sfp

sfp_config_path = self._api_common.get_config_path(Sfp.SFP_CONFIG)
sfp_config = self._api_common.load_json_file(sfp_config_path)

sfp_index = 0
for index in range(0, sfp_config['port_num']):
sfp = Sfp(sfp_index,conf=sfp_config)
self._sfp_list.append(sfp)
sfp_index += 1
self.sfp_module_initialized = True

def __initialize_psu(self):
from sonic_platform.psu import Psu
Expand Down Expand Up @@ -162,51 +169,51 @@ def get_reboot_cause(self):
# ######################## SFP methods #########################
# ##############################################################

# def get_num_sfps(self):
# """
# Retrieves the number of sfps available on this chassis
# Returns:
# An integer, the number of sfps available on this chassis
# """
# if not self.sfp_module_initialized:
# self.__initialize_sfp()
def get_num_sfps(self):
"""
Retrieves the number of sfps available on this chassis
Returns:
An integer, the number of sfps available on this chassis
"""
if not self.sfp_module_initialized:
self.__initialize_sfp()

# return len(self._sfp_list)
return len(self._sfp_list)

# def get_all_sfps(self):
# """
# Retrieves all sfps available on this chassis
# Returns:
# A list of objects derived from SfpBase representing all sfps
# available on this chassis
# """
# if not self.sfp_module_initialized:
# self.__initialize_sfp()
def get_all_sfps(self):
"""
Retrieves all sfps available on this chassis
Returns:
A list of objects derived from SfpBase representing all sfps
available on this chassis
"""
if not self.sfp_module_initialized:
self.__initialize_sfp()

# return self._sfp_list
return self._sfp_list

# def get_sfp(self, index):
# """
# Retrieves sfp represented by (1-based) index <index>
# Args:
# index: An integer, the index (1-based) of the sfp to retrieve.
# The index should be the sequence of a physical port in a chassis,
# starting from 1.
# For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
# Returns:
# An object dervied from SfpBase representing the specified sfp
# """
# sfp = None
# if not self.sfp_module_initialized:
# self.__initialize_sfp()

# try:
# # The index will start from 1
# sfp = self._sfp_list[index-1]
# except IndexError:
# sys.stderr.write("SFP index {} out of range (1-{})\n".format(
# index, len(self._sfp_list)))
# return sfp
def get_sfp(self, index):
"""
Retrieves sfp represented by (1-based) index <index>
Args:
index: An integer, the index (1-based) of the sfp to retrieve.
The index should be the sequence of a physical port in a chassis,
starting from 1.
For example, 1 for Ethernet0, 2 for Ethernet4 and so on.
Returns:
An object dervied from SfpBase representing the specified sfp
"""
sfp = None
if not self.sfp_module_initialized:
self.__initialize_sfp()

try:
# The index will start from 1
sfp = self._sfp_list[index-1]
except IndexError:
sys.stderr.write("SFP index {} out of range (1-{})\n".format(
index, len(self._sfp_list)))
return sfp

# ##############################################################
# ####################### Other methods ########################
Expand Down
40 changes: 40 additions & 0 deletions device/celestica/x86_64-cel_seastone_2-r0/sonic_platform/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Common:
OUTPUT_SOURCE_IPMI = 'ipmitool'
OUTPUT_SOURCE_GIVEN_LIST = 'value_list'
OUTPUT_SOURCE_GIVEN_VALUE = 'value'
OUTPUT_SOURCE_SYSFS = 'sysfs_value'

SET_METHOD_IPMI = 'ipmitool'
NULL_VAL = 'N/A'
Expand Down Expand Up @@ -68,6 +69,40 @@ def _ipmi_get(self, index, config):
status, output = self._run_command(cmd)
return output if status else None

def _sysfs_read(self,index,config):
sysfs_path = config.get('sysfs_path')

#### Remaining Design Warning : Check argument type
argument = config['argument'][index].split(',')
sysfs_path = sysfs_path.format(*argument)
content = ""
try:
content = open(sysfs_path)
content = content.readline().rstrip()
except IOError as e:
print("Error: unable to open file: %s" % str(e))
return False

return content

def _sysfs_write(self,index,config,input):
sysfs_path = config.get('sysfs_path')
#### Remaining Design Warning : Check argument type
argument = config['argument'][index].split(',')
sysfs_path = sysfs_path.format(*argument)
#### Remaining Design Warning : Validate write_offset
write_offset = int(config.get('write_offset'))
output = ""
try:
open_file = open(sysfs_path,"r+")
open_file.seek(write_offset)
open_file.write(input)
open_file.close()
except IOError as e:
print("Error: unable to open file: %s" % str(e))
return False , output
return True , output

def _ipmi_set(self, index, config, input):
arg = config['argument'][index].format(input)
return self._run_command(config['command'].format(arg))
Expand Down Expand Up @@ -119,6 +154,9 @@ def get_output(self, index, config, default):
elif output_source == self.OUTPUT_SOURCE_GIVEN_LIST:
output = config["value_list"][index]

elif output_source == self.OUTPUT_SOURCE_SYSFS:
output = self._sysfs_read(index,config)

else:
output = default

Expand All @@ -143,6 +181,8 @@ def set_output(self, index, input, config):
set_method = config.get('set_method')
if set_method == self.SET_METHOD_IPMI:
output = self._ipmi_set(index, config, cleaned_input)[0]
elif set_method == self.OUTPUT_SOURCE_SYSFS:
output = self._sysfs_write(index,config,cleaned_input)[0]
else:
output = False

Expand Down
Loading