From 8813b1d2d7c4e710ea5ef6269a97b260bd3a3a81 Mon Sep 17 00:00:00 2001 From: mprabhu-nokia <66807480+mprabhu-nokia@users.noreply.github.com> Date: Thu, 12 Nov 2020 13:09:22 -0500 Subject: [PATCH] Common power consumption and supply APIs for modular chassis (#136) sonic-platform-base: Changes to introduce APIs for modular chassis for power-consumption and supplied HLD: Azure/SONiC#646 PSUd APIs for power requirement calculations get_maximum_supplied_power() - per PSU get_status_master_led() - get master psu led status. Class method. set_status_master_led() - set master psu led status. Class method. get_maximum_consumed_power(self) - per consumer API. Consumers are modules, Fans --- sonic_platform_base/chassis_base.py | 11 +++++++ sonic_platform_base/device_base.py | 6 ++++ sonic_platform_base/fan_drawer_base.py | 10 +++++++ sonic_platform_base/module_base.py | 10 +++++++ sonic_platform_base/psu_base.py | 41 ++++++++++++++++++++++---- 5 files changed, 72 insertions(+), 6 deletions(-) diff --git a/sonic_platform_base/chassis_base.py b/sonic_platform_base/chassis_base.py index 3cbeeac7acf5..864d6541bb75 100644 --- a/sonic_platform_base/chassis_base.py +++ b/sonic_platform_base/chassis_base.py @@ -144,6 +144,17 @@ def get_my_slot(self): """ return NotImplementedError + def is_modular_chassis(self): + """ + Retrieves whether the sonic instance is part of modular chassis + + Returns: + A bool value, should return False by default or for fixed-platforms. + Should return True for supervisor-cards, line-cards etc running as part + of modular-chassis. + """ + return False + ############################################## # Component methods ############################################## diff --git a/sonic_platform_base/device_base.py b/sonic_platform_base/device_base.py index 3116f2471f40..909449d2c95b 100644 --- a/sonic_platform_base/device_base.py +++ b/sonic_platform_base/device_base.py @@ -11,6 +11,12 @@ class DeviceBase(object): peripheral device """ + # Possible status LED colors + STATUS_LED_COLOR_GREEN = "green" + STATUS_LED_COLOR_AMBER = "amber" + STATUS_LED_COLOR_RED = "red" + STATUS_LED_COLOR_OFF = "off" + def get_name(self): """ Retrieves the name of the device diff --git a/sonic_platform_base/fan_drawer_base.py b/sonic_platform_base/fan_drawer_base.py index ed3fc18c8013..ed9e72ea97c7 100644 --- a/sonic_platform_base/fan_drawer_base.py +++ b/sonic_platform_base/fan_drawer_base.py @@ -81,3 +81,13 @@ def get_status_led(self, color): A string, one of the predefined STATUS_LED_COLOR_* strings above """ raise NotImplementedError + + def get_maximum_consumed_power(self): + """ + Retrives the maximum power drawn by Fan Drawer + + Returns: + A float, with value of the maximum consumable power of the + component. + """ + raise NotImplementedError diff --git a/sonic_platform_base/module_base.py b/sonic_platform_base/module_base.py index 2c187c7cdfdb..88011dc07cda 100644 --- a/sonic_platform_base/module_base.py +++ b/sonic_platform_base/module_base.py @@ -186,6 +186,16 @@ def set_admin_state(self, up): """ raise NotImplementedError + def get_maximum_consumed_power(self): + """ + Retrives the maximum power drawn by this module + + Returns: + A float, with value of the maximum consumable power of the + module. + """ + raise NotImplementedError + ############################################## # Component methods ############################################## diff --git a/sonic_platform_base/psu_base.py b/sonic_platform_base/psu_base.py index 69a5fd214ac8..04aacd4c4e39 100644 --- a/sonic_platform_base/psu_base.py +++ b/sonic_platform_base/psu_base.py @@ -15,12 +15,6 @@ class PsuBase(device_base.DeviceBase): # Device type definition. Note, this is a constant. DEVICE_TYPE = "psu" - # Possible fan status LED colors - STATUS_LED_COLOR_GREEN = "green" - STATUS_LED_COLOR_AMBER = "amber" - STATUS_LED_COLOR_RED = "red" - STATUS_LED_COLOR_OFF = "off" - # List of FanBase-derived objects representing all fans # available on the PSU _fan_list = None @@ -32,6 +26,9 @@ class PsuBase(device_base.DeviceBase): # PSU class _thermal_list = [] + # Status of Master LED + psu_master_led_color = device_base.DeviceBase.STATUS_LED_COLOR_OFF + def __init__(self): self._fan_list = [] @@ -219,3 +216,35 @@ def get_voltage_low_threshold(self): e.g. 12.1 """ raise NotImplementedError + + def get_maximum_supplied_power(self): + """ + Retrieves the maximum supplied power by PSU + + Returns: + A float number, the maximum power output in Watts. + e.g. 1200.1 + """ + raise NotImplementedError + + @classmethod + def get_status_master_led(cls): + """ + Gets the state of the Master status LED for a given device-type + + Returns: + A string, one of the predefined STATUS_LED_COLOR_* strings. + """ + return cls.psu_master_led_color + + @classmethod + def set_status_master_led(cls, color): + """ + Gets the state of the Master status LED for a given device-type + + Returns: + bool: True if status LED state is set successfully, False if + not + """ + cls.psu_master_led_color = color + return True