-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Mellanox] [201911] Fix issue: set fan led in certain order causes in…
…correct physical fan led color (#6019) * Fix issue: fan led colo status * Fix LGTM warning * Support fan led management for non-swapable fan
- Loading branch information
1 parent
33a6e56
commit 37eb088
Showing
2 changed files
with
94 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
class Led(object): | ||
STATUS_LED_COLOR_GREEN = 'green' | ||
STATUS_LED_COLOR_GREEN_BLINK = 'green_blink' | ||
STATUS_LED_COLOR_RED = 'red' | ||
STATUS_LED_COLOR_RED_BLINK = 'red_blink' | ||
STATUS_LED_COLOR_ORANGE = 'orange' | ||
STATUS_LED_COLOR_ORANGE_BLINK = 'orange_blink' | ||
STATUS_LED_COLOR_OFF = 'off' | ||
|
||
|
||
class SharedLed(object): | ||
LED_PRIORITY = { | ||
Led.STATUS_LED_COLOR_RED: 0, | ||
Led.STATUS_LED_COLOR_GREEN: 1 | ||
} | ||
|
||
def __init__(self): | ||
self._virtual_leds = [] | ||
self._target_color = Led.STATUS_LED_COLOR_GREEN | ||
|
||
def add_virtual_leds(self, led): | ||
self._virtual_leds.append(led) | ||
|
||
def update_status_led(self): | ||
target_color = Led.STATUS_LED_COLOR_GREEN | ||
for virtual_led in self._virtual_leds: | ||
if SharedLed.LED_PRIORITY[virtual_led.get_led_color()] < SharedLed.LED_PRIORITY[target_color]: | ||
target_color = virtual_led.get_led_color() | ||
|
||
self._target_color = target_color | ||
return True | ||
|
||
def get_status(self): | ||
return self._target_color | ||
|
||
|
||
class ComponentFaultyIndicator(object): | ||
def __init__(self, shared_led): | ||
self._color = Led.STATUS_LED_COLOR_GREEN | ||
self._shared_led = shared_led | ||
self._shared_led.add_virtual_leds(self) | ||
|
||
def set_status(self, color): | ||
self._color = color | ||
return self._shared_led.update_status_led() | ||
|
||
def get_led_color(self): | ||
return self._color | ||
|
||
def get_status(self): | ||
return self._shared_led.get_status() |