Skip to content

Commit ec850df

Browse files
Staphylolguohan
authored andcommitted
[devices]: Use arista library as led plugin for more platforms. (#1809)
This apply to arista_7050_qx32 and arista_7050_qx32s.
1 parent 07ea974 commit ec850df

File tree

2 files changed

+6
-185
lines changed

2 files changed

+6
-185
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,6 @@
1-
#!/usr/bin/env python
2-
#
3-
# led_control.py
4-
#
5-
# Platform-specific LED control functionality for SONiC
6-
#
7-
81
try:
9-
from sonic_led.led_control_base import LedControlBase
10-
import swsssdk
2+
import arista.utils.sonic_leds as arista_leds
113
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")
945

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()
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,6 @@
1-
#!/usr/bin/env python
2-
#
3-
# led_control.py
4-
#
5-
# Platform-specific LED control functionality for SONiC
6-
#
7-
81
try:
9-
from sonic_led.led_control_base import LedControlBase
2+
import arista.utils.sonic_leds as arista_leds
103
except ImportError, e:
11-
raise ImportError (str(e) + " - required module not found")
12-
13-
14-
class LedControl(LedControlBase):
15-
"""Platform specific LED control class"""
16-
17-
SONIC_PORT_NAME_PREFIX = "Ethernet"
18-
19-
LED_SYSFS_PATH_BREAKOUT_CAPABLE = "/sys/class/leds/qsfp{0}_{1}/brightness"
20-
LED_SYSFS_PATH_NO_BREAKOUT = "/sys/class/leds/qsfp{0}/brightness"
21-
22-
QSFP_BREAKOUT_START_IDX = 1
23-
QSFP_BREAKOUT_END_IDX = 24
24-
QSFP_NO_BREAKOUT_START_IDX = 25
25-
QSFP_NO_BREAKOUT_END_IDX = 32
26-
27-
LED_QSFP_OFFSET = 4
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-
# SONiC port nums are 0-based and increment by 4
42-
# Arista QSFP indices are 1-based and increment by 1
43-
return ((sonic_port_num/4) + 1)
44-
45-
# Concrete implementation of port_link_state_change() method
46-
def port_link_state_change(self, port, state):
47-
qsfp_index = self._port_name_to_qsfp_index(port)
48-
49-
# Ignore invalid QSFP indices
50-
if qsfp_index <= 0:
51-
return
52-
53-
# QSFP indices 1-24 are breakout-capable and have four LEDs, and each LED indicate one lane.
54-
# whereas indices 25-32 are not breakout-capable, and only have one
55-
if qsfp_index <= self.QSFP_BREAKOUT_END_IDX:
56-
# assuming 40G, then we need to control four lanes
57-
led_sysfs_paths = [ self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index + self.LED_QSFP_OFFSET, i) for i in range(1, 5) ]
58-
else:
59-
led_sysfs_paths = [ self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index + self.LED_QSFP_OFFSET) ]
60-
61-
for led_sysfs_path in led_sysfs_paths:
62-
led_file = open(led_sysfs_path, "w")
63-
64-
if state == "up":
65-
led_file.write("%d" % self.LED_COLOR_GREEN)
66-
else:
67-
led_file.write("%d" % self.LED_COLOR_OFF)
68-
69-
led_file.close()
70-
71-
# Constructor
72-
def __init__(self):
73-
# Initialize all front-panel status LEDs to green
74-
with open("/sys/class/leds/status/brightness", "w") as f:
75-
f.write("1")
76-
with open("/sys/class/leds/fan_status/brightness", "w") as f:
77-
f.write("1")
78-
with open("/sys/class/leds/psu1/brightness", "w") as f:
79-
f.write("1")
80-
with open("/sys/class/leds/psu2/brightness", "w") as f:
81-
f.write("1")
82-
83-
# Initialize: Turn all front panel QSFP LEDs off
84-
for qsfp_index in range(self.QSFP_BREAKOUT_START_IDX, self.QSFP_BREAKOUT_END_IDX + 1):
85-
for lane in range(1, 5):
86-
led_sysfs_path = self.LED_SYSFS_PATH_BREAKOUT_CAPABLE.format(qsfp_index + self.LED_QSFP_OFFSET, lane)
87-
with open(led_sysfs_path, 'w') as led_file:
88-
led_file.write("%d" % self.LED_COLOR_OFF)
4+
raise ImportError (str(e) + "- required module not found")
895

90-
for qsfp_index in range(self.QSFP_NO_BREAKOUT_START_IDX, self.QSFP_NO_BREAKOUT_END_IDX + 1):
91-
led_sysfs_path = self.LED_SYSFS_PATH_NO_BREAKOUT.format(qsfp_index + self.LED_QSFP_OFFSET)
92-
with open(led_sysfs_path, 'w') as led_file:
93-
led_file.write("%d" % self.LED_COLOR_OFF)
6+
LedControl = arista_leds.getLedControl()

0 commit comments

Comments
 (0)