Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions sonic_platform_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
from . import psu_base
from . import sfp_base
from . import thermal_base
from . import sensor_base
from . import watchdog_base
91 changes: 91 additions & 0 deletions sonic_platform_base/chassis_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ def __init__(self):
# List of ThermalBase-derived objects representing all thermals
# available on the chassis
self._thermal_list = []
self._vsensor_list = []
self._isensor_list = []

# List of SfpBase-derived objects representing all sfps
# available on the chassis
Expand Down Expand Up @@ -451,6 +453,95 @@ def get_thermal_manager(self):
"""
raise NotImplementedError

##############################################
# Voltage Sensor Methods
##############################################

def get_num_vsensors(self):
"""
Retrieves the number of voltage sensors available on this chassis

Returns:
An integer, the number of voltage sensors available on this chassis
"""
return len(self._vsensor_list)

def get_all_vsensors(self):
"""
Retrieves all voltage sensors available on this chassis

Returns:
A list of objects derived from VsensorBase representing all voltage
sensors available on this chassis
"""
return self._vsensor_list

def get_vsensor(self, index):
"""
Retrieves voltage sensor unit represented by (0-based) index <index>

Args:
index: An integer, the index (0-based) of the voltage sensor to
retrieve

Returns:
An object dervied from VsensorBase representing the specified voltage sensor
Comment thread
bmridul marked this conversation as resolved.
Outdated
"""
vsensor = None

try:
vsensor = self._vsensor_list[index]
except IndexError:
sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format(
Comment thread
bmridul marked this conversation as resolved.
index, len(self._vsensor_list)-1))

return vsensor

##############################################
# Current Sensor Methods
##############################################

def get_num_isensors(self):
"""
Retrieves the number of current sensors available on this chassis

Returns:
An integer, the number of current sensors available on this chassis
"""
return len(self._isensor_list)

def get_all_isensors(self):
"""
Retrieves all Current sensors available on this chassis
Comment thread
bmridul marked this conversation as resolved.
Outdated

Returns:
A list of objects derived from IsensorBase representing all current
sensors available on this chassis
"""
return self._isensor_list

def get_isensor(self, index):
"""
Retrieves current sensor object represented by (0-based) index <index>

Args:
index: An integer, the index (0-based) of the current sensor to
retrieve

Returns:
An object dervied from IsensorBase representing the specified Current
Comment thread
bmridul marked this conversation as resolved.
Outdated
sensor
"""
isensor = None

try:
isensor = self._isensor_list[index]
except IndexError:
sys.stderr.write("Current sensor index {} out of range (0-{})\n".format(
index, len(self._isensor_list)-1))

return isensor

##############################################
# SFP methods
##############################################
Expand Down
91 changes: 91 additions & 0 deletions sonic_platform_base/module_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def __init__(self):
# List of ThermalBase-derived objects representing all thermals
# available on the module
self._thermal_list = []
self._vsensor_list = []
self._isensor_list = []

# List of SfpBase-derived objects representing all sfps
# available on the module
Expand Down Expand Up @@ -372,6 +374,95 @@ def get_thermal(self, index):

return thermal

##############################################
# Voltage Sensor methods
##############################################

def get_num_vsensors(self):
"""
Retrieves the number of voltage sensors available on this module

Returns:
An integer, the number of voltage sensors available on this module
"""
return len(self._vsensor_list)

def get_all_vsensors(self):
"""
Retrieves all voltage sensors available on this module

Returns:
A list of objects derived from VsensorBase representing all voltage
sensors available on this module
"""
return self._vsensor_list

def get_vsensor(self, index):
"""
Retrieves voltage sensor unit represented by (0-based) index <index>

Args:
index: An integer, the index (0-based) of the voltage sensor to
retrieve

Returns:
An object dervied from VsensorBase representing the specified voltage
Comment thread
bmridul marked this conversation as resolved.
Outdated
sensor
"""
vsensor = None

try:
vsensor = self._vsensor_list[index]
except IndexError:
sys.stderr.write("Voltage sensor index {} out of range (0-{})\n".format(
index, len(self._vsensor_list)-1))

return vsensor

##############################################
# Current sensor methods
##############################################

def get_num_Isensors(self):
Comment thread
bmridul marked this conversation as resolved.
Outdated
"""
Retrieves the number of Current sensors available on this module
Comment thread
bmridul marked this conversation as resolved.
Outdated

Returns:
An integer, the number of Current sensors available on this module
"""
return len(self._Isensor_list)
Comment thread
bmridul marked this conversation as resolved.
Outdated

def get_all_isensors(self):
"""
Retrieves all current sensors available on this module

Returns:
A list of objects derived from IsensorBase representing all current
sensors available on this module
"""
return self._isensor_list

def get_isensor(self, index):
"""
Retrieves Current sensor object represented by (0-based) index <index>
Comment thread
bmridul marked this conversation as resolved.
Outdated

Args:
index: An integer, the index (0-based) of the current sensor to
retrieve

Returns:
An object dervied from IsensorBase representing the specified isensor
Comment thread
bmridul marked this conversation as resolved.
Outdated
"""
isensor = None

try:
isensor = self._isensor_list[index]
except IndexError:
sys.stderr.write("Current sensor index {} out of range (0-{})\n".format(
index, len(self._isensor_list)-1))

return isensor

##############################################
# SFP methods
##############################################
Expand Down
172 changes: 172 additions & 0 deletions sonic_platform_base/sensor_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
"""
sensor_base.py

Abstract base class for implementing a platform-specific class with which
to interact with a sensor module in SONiC
"""

from . import device_base

SENSOR_TYPE_VOLTAGE = 1
SENSOR_TYPE_CURRENT = 2

class SensorBase(device_base.DeviceBase):
"""
Abstract base class for interfacing with a sensor module
"""

def get_type(self):
"""
Specifies the type of the sensor.

Returns:
Sensor type
"""
raise NotImplementedError

def get_value(self):
"""
Retrieves measurement reported by sensor

Returns:
Sensor measurement
"""
raise NotImplementedError

def get_unit(self):
"""
Retrieves unit of measurement reported by sensor

Returns:
Sensor measurement unit
"""
raise NotImplementedError

def get_high_threshold(self):
"""
Retrieves the high threshold of sensor

Returns:
High threshold
"""
raise NotImplementedError

def get_low_threshold(self):
"""
Retrieves the low threshold

Returns:
Low threshold
"""
raise NotImplementedError

def set_high_threshold(self, value):
"""
Sets the high threshold value of sensor

Args :
Comment thread
bmridul marked this conversation as resolved.
Outdated
value: High threshold value to set

Returns:
A boolean, True if threshold is set successfully, False if not
"""
raise NotImplementedError

def set_low_threshold(self, value):
"""
Sets the low threshold value of sensor

Args :
value: Value

Returns:
A boolean, True if threshold is set successfully, False if not
"""
raise NotImplementedError

def get_high_critical_threshold(self):
"""
Retrieves the high critical threshold value of sensor

Returns:
The high critical threshold value of sensor
"""
raise NotImplementedError

def get_low_critical_threshold(self):
"""
Retrieves the low critical threshold value of sensor

Returns:
The low critical threshold value of sensor
"""
raise NotImplementedError

def set_high_critical_threshold(self, value):
"""
Sets the critical high threshold value of sensor

Args :
value: Critical high threshold Value

Returns:
A boolean, True if threshold is set successfully, False if not
"""
raise NotImplementedError

def set_low_critical_threshold(self, value):
"""
Sets the critical low threshold value of sensor

Args :
value: Critial low threshold Value

Returns:
A boolean, True if threshold is set successfully, False if not
"""
raise NotImplementedError

def get_minimum_recorded(self):
"""
Retrieves the minimum recorded value of sensor

Returns:
The minimum recorded value of sensor
"""
raise NotImplementedError

def get_maximum_recorded(self):
"""
Retrieves the maximum recorded value of sensor

Returns:
The maximum recorded value of sensor
"""
raise NotImplementedError



class VsensorBase(SensorBase):
Comment thread
bmridul marked this conversation as resolved.
Outdated
"""
Abstract base class for interfacing with a voltage sensor module
"""
MILLI_VOLTS = "mV"

def get_type(self):
return SENSOR_TYPE_VOLTAGE

def get_unit(self):
return MILLI_VOLTS

Comment thread
bmridul marked this conversation as resolved.

class IsensorBase(SensorBase):
"""
Abstract base class for interfacing with a current sensor module
"""
MILLI_AMPS = "mA"

def get_type(self):
return SENSOR_TYPE_CURRENT

def get_unit(self):
return MILLI_AMPS