|
9 | 9 | try:
|
10 | 10 | import sys
|
11 | 11 | from sonic_platform_base.chassis_base import ChassisBase
|
| 12 | + from sonic_platform_base.sonic_sfp.sfputilhelper import SfpUtilHelper |
| 13 | + from sonic_py_common import device_info |
| 14 | + from .event import SfpEvent |
12 | 15 | from .helper import APIHelper
|
13 | 16 | except ImportError as e:
|
14 | 17 | raise ImportError(str(e) + "- required module not found")
|
@@ -45,9 +48,14 @@ def __init__(self):
|
45 | 48 | self.__initialize_components()
|
46 | 49 |
|
47 | 50 | def __initialize_sfp(self):
|
| 51 | + sfputil_helper = SfpUtilHelper() |
| 52 | + port_config_file_path = device_info.get_path_to_port_config_file() |
| 53 | + sfputil_helper.read_porttab_mappings(port_config_file_path, 0) |
| 54 | + |
48 | 55 | from sonic_platform.sfp import Sfp
|
49 | 56 | for index in range(0, NUM_SFP):
|
50 |
| - sfp = Sfp(index) |
| 57 | + name_idx = 0 if index+1 == NUM_SFP else index+1 |
| 58 | + sfp = Sfp(index, sfputil_helper.logical[name_idx]) |
51 | 59 | self._sfp_list.append(sfp)
|
52 | 60 | self.sfp_module_initialized = True
|
53 | 61 |
|
@@ -141,6 +149,38 @@ def get_reboot_cause(self):
|
141 | 149 |
|
142 | 150 | return prev_reboot_cause
|
143 | 151 |
|
| 152 | + |
| 153 | + def get_change_event(self, timeout=0): |
| 154 | + """ |
| 155 | + Returns a nested dictionary containing all devices which have |
| 156 | + experienced a change at chassis level |
| 157 | + Args: |
| 158 | + timeout: Timeout in milliseconds (optional). If timeout == 0, |
| 159 | + this method will block until a change is detected. |
| 160 | + Returns: |
| 161 | + (bool, dict): |
| 162 | + - True if call successful, False if not; |
| 163 | + - A nested dictionary where key is a device type, |
| 164 | + value is a dictionary with key:value pairs in the format of |
| 165 | + {'device_id':'device_event'}, |
| 166 | + where device_id is the device ID for this device and |
| 167 | + device_event, |
| 168 | + status='1' represents device inserted, |
| 169 | + status='0' represents device removed. |
| 170 | + Ex. {'fan':{'0':'0', '2':'1'}, 'sfp':{'11':'0'}} |
| 171 | + indicates that fan 0 has been removed, fan 2 |
| 172 | + has been inserted and sfp 11 has been removed. |
| 173 | + """ |
| 174 | + # SFP event |
| 175 | + if not self.sfp_module_initialized: |
| 176 | + self.__initialize_sfp() |
| 177 | + |
| 178 | + sfp_event = SfpEvent(self._sfp_list).get_sfp_event(timeout) |
| 179 | + if sfp_event: |
| 180 | + return True, {'sfp': sfp_event} |
| 181 | + |
| 182 | + return False, {'sfp': {}} |
| 183 | + |
144 | 184 | ##############################################################
|
145 | 185 | ######################## SFP methods #########################
|
146 | 186 | ##############################################################
|
|
0 commit comments