|
1 |
| -#!/usr/bin/env python |
2 |
| -# |
3 |
| -# led_control.py |
4 |
| -# |
5 |
| -# Platform-specific LED control functionality for SONiC |
6 |
| -# |
7 |
| - |
8 | 1 | try:
|
9 |
| - from sonic_led.led_control_base import LedControlBase |
10 |
| - import swsssdk |
| 2 | + import arista.utils.sonic_leds as arista_leds |
11 | 3 | except ImportError, e:
|
12 |
| - raise ImportError (str(e) + " - required module not found") |
13 |
| - |
14 |
| - |
15 |
| -class LedControl(LedControlBase): |
16 |
| - """Platform specific LED control class""" |
17 |
| - PORT_TABLE_PREFIX = "PORT_TABLE:" |
18 |
| - |
19 |
| - SONIC_PORT_NAME_PREFIX = "Ethernet" |
20 |
| - |
21 |
| - LED_SYSFS_PATH_BREAKOUT_CAPABLE = "/sys/class/leds/qsfp{0}_{1}/brightness" |
22 |
| - LED_SYSFS_PATH_NO_BREAKOUT = "/sys/class/leds/qsfp{0}/brightness" |
23 |
| - |
24 |
| - QSFP_BREAKOUT_START_IDX = 1 |
25 |
| - QSFP_BREAKOUT_END_IDX = 24 |
26 |
| - QSFP_NO_BREAKOUT_START_IDX = 25 |
27 |
| - QSFP_NO_BREAKOUT_END_IDX = 32 |
28 |
| - |
29 |
| - LED_COLOR_OFF = 0 |
30 |
| - LED_COLOR_GREEN = 1 |
31 |
| - LED_COLOR_YELLOW = 2 |
32 |
| - |
33 |
| - # Helper method to map SONiC port name to Arista QSFP index |
34 |
| - def _port_name_to_qsfp_index(self, port_name): |
35 |
| - # Strip "Ethernet" off port name |
36 |
| - if not port_name.startswith(self.SONIC_PORT_NAME_PREFIX): |
37 |
| - return -1 |
38 |
| - |
39 |
| - sonic_port_num = int(port_name[len(self.SONIC_PORT_NAME_PREFIX):]) |
40 |
| - |
41 |
| - swss = swsssdk.SonicV2Connector() |
42 |
| - swss.connect(swss.APPL_DB) |
43 |
| - |
44 |
| - lanes = swss.get(swss.APPL_DB, self.PORT_TABLE_PREFIX + port_name, 'lanes') |
45 |
| - |
46 |
| - # SONiC port nums are 0-based and increment by 4 |
47 |
| - # Arista QSFP indices are 1-based and increment by 1 |
48 |
| - return (((sonic_port_num/4) + 1), sonic_port_num%4, len(lanes.split(','))) |
49 |
| - |
50 |
| - # Concrete implementation of port_link_state_change() method |
51 |
| - def port_link_state_change(self, port, state): |
52 |
| - qsfp_index, lane_index, lanes = self._port_name_to_qsfp_index(port) |
53 |
| - |
54 |
| - # Ignore invalid QSFP indices |
55 |
| - if qsfp_index <= 0 or lanes <= 0 or lanes > 4: |
56 |
| - return |
57 |
| - |
58 |
| - # QSFP indices 1-24 are breakout-capable and have four LEDs, and each LED indicate one lane. |
59 |
| - # whereas indices 25-32 are not breakout-capable, and only have one |
60 |
| - if qsfp_index <= self.QSFP_BREAKOUT_END_IDX: |
61 |
| - # assuming 40G, then we need to control four lanes |
62 |
| - led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, i) for i in range(lane_index + 1, lane_index + 1 + lanes) ] |
63 |
| - else: |
64 |
| - led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) ] |
65 |
| - |
66 |
| - for led_sysfs_path in led_sysfs_paths: |
67 |
| - led_file = open(led_sysfs_path, "w") |
68 |
| - |
69 |
| - if state == "up": |
70 |
| - led_file.write("%d" % self.LED_COLOR_GREEN) |
71 |
| - else: |
72 |
| - led_file.write("%d" % self.LED_COLOR_OFF) |
73 |
| - |
74 |
| - led_file.close() |
75 |
| - |
76 |
| - # Constructor |
77 |
| - def __init__(self): |
78 |
| - # Initialize all front-panel status LEDs to green |
79 |
| - with open("/sys/class/leds/status/brightness", "w") as f: |
80 |
| - f.write("1") |
81 |
| - with open("/sys/class/leds/fan_status/brightness", "w") as f: |
82 |
| - f.write("1") |
83 |
| - with open("/sys/class/leds/psu1/brightness", "w") as f: |
84 |
| - f.write("1") |
85 |
| - with open("/sys/class/leds/psu2/brightness", "w") as f: |
86 |
| - f.write("1") |
87 |
| - |
88 |
| - # Initialize: Turn all front panel QSFP LEDs off |
89 |
| - for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1): |
90 |
| - for lane in range(1, 5): |
91 |
| - led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index, lane) |
92 |
| - with open(led_sysfs_path, 'w') as led_file: |
93 |
| - led_file.write("%d" % self.LED_COLOR_OFF) |
| 4 | + raise ImportError (str(e) + "- required module not found") |
94 | 5 |
|
95 |
| - for qsfp_index in range(self.QSFP_NO_BREAKOUT_START_IDX, self.QSFP_NO_BREAKOUT_END_IDX + 1): |
96 |
| - led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index) |
97 |
| - with open(led_sysfs_path, 'w') as led_file: |
98 |
| - led_file.write("%d" % self.LED_COLOR_OFF) |
| 6 | +LedControl = arista_leds.getLedControl() |
0 commit comments