Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sensor Monitor support #393

Merged
merged 9 commits into from
Sep 7, 2023
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
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._voltage_sensor_list = []
self._current_sensor_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_voltage_sensors(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._voltage_sensor_list)

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

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

def get_voltage_sensor(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 derived from VoltageSensorBase representing the specified voltage sensor
"""
voltage_sensor = None

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

return voltage_sensor

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

def get_num_current_sensors(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._current_sensor_list)

def get_all_current_sensors(self):
"""
Retrieves all current sensors available on this chassis

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

def get_current_sensor(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 derived from CurrentSensorBase representing the specified current
sensor
"""
current_sensor = None

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

return current_sensor

##############################################
# 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._voltage_sensor_list = []
self._current_sensor_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_voltage_sensors(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._voltage_sensor_list)

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

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

def get_voltage_sensor(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 derived from VoltageSensorBase representing the specified voltage
sensor
"""
voltage_sensor = None

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

return voltage_sensor

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

def get_num_current_sensors(self):
"""
Retrieves the number of current sensors available on this module

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

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

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

def get_current_sensor(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 derived from CurrentSensorBase representing the specified current_sensor
"""
current_sensor = None

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

return current_sensor

##############################################
# SFP methods
##############################################
Expand Down
173 changes: 173 additions & 0 deletions sonic_platform_base/sensor_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
"""
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

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

@classmethod
def get_type(cls):
"""
Specifies the type of the sensor such as current/voltage etc.

Returns:
Sensor type
"""
raise NotImplementedError

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

Returns:
Sensor measurement
"""
raise NotImplementedError

@classmethod
def get_unit(cls):
"""
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:
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 VoltageSensorBase(SensorBase):
"""
Abstract base class for interfacing with a voltage sensor module
"""

@classmethod
def get_type(cls):
return "SENSOR_TYPE_VOLTAGE"

@classmethod
def get_unit(cls):
return "mV"


class CurrentSensorBase(SensorBase):
"""
Abstract base class for interfacing with a current sensor module
"""

@classmethod
def get_type(cls):
return "SENSOR_TYPE_CURRENT"

@classmethod
def get_unit(cls):
return "mA"
Loading
Loading