|
| 1 | +# |
| 2 | +# chassis_base.py |
| 3 | +# |
| 4 | +# Base class for implementing a platform-specific class with which |
| 5 | +# to interact with a chassis device in SONiC. |
| 6 | +# |
| 7 | + |
| 8 | +import sys |
| 9 | +from . import device_base |
| 10 | + |
| 11 | + |
| 12 | +class ChassisBase(device_base.DeviceBase): |
| 13 | + """ |
| 14 | + Base class for interfacing with a platform chassis |
| 15 | + """ |
| 16 | + |
| 17 | + # Possible reboot causes |
| 18 | + REBOOT_CAUSE_POWER_LOSS = "power_loss" |
| 19 | + REBOOT_CAUSE_THERMAL_OVERLOAD_CPU = "thermal_overload_cpu" |
| 20 | + REBOOT_CAUSE_THERMAL_OVERLOAD_ASIC = "thermal_overload_asic" |
| 21 | + REBOOT_CAUSE_THERMAL_OVERLOAD_OTHER = "thermal_overload_other" |
| 22 | + REBOOT_CAUSE_INSUFFICIENT_FAN = "insufficient_fan" |
| 23 | + REBOOT_CAUSE_WATCHDOG = "watchdog" |
| 24 | + REBOOT_CAUSE_HARDWARE_OTHER = "hardware_other" |
| 25 | + REBOOT_CAUSE_NON_HARDWARE = "non_hardware" |
| 26 | + |
| 27 | + # List of ModuleBase-derived objects representing all modules |
| 28 | + # available on the chassis (for use with modular chassis) |
| 29 | + _module_list = [] |
| 30 | + |
| 31 | + # List of FanBase-derived objects representing all fans |
| 32 | + # available on the chassis |
| 33 | + _fan_list = [] |
| 34 | + |
| 35 | + # List of PsuBase-derived objects representing all power supply units |
| 36 | + # available on the chassis |
| 37 | + _psu_list = [] |
| 38 | + |
| 39 | + # Object derived from WatchdogBase for interacting with hardware watchdog |
| 40 | + _watchdog = None |
| 41 | + |
| 42 | + def get_base_mac(self): |
| 43 | + """ |
| 44 | + Retrieves the base MAC address for the chassis |
| 45 | +
|
| 46 | + Returns: |
| 47 | + A string containing the MAC address in the format |
| 48 | + 'XX:XX:XX:XX:XX:XX' |
| 49 | + """ |
| 50 | + raise NotImplementedError |
| 51 | + |
| 52 | + def get_reboot_cause(self): |
| 53 | + """ |
| 54 | + Retrieves the cause of the previous reboot |
| 55 | +
|
| 56 | + Returns: |
| 57 | + A tuple (string, string) where the first element is a string |
| 58 | + containing the cause of the previous reboot. This string must be |
| 59 | + one of the predefined strings in this class. If the first string |
| 60 | + is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used |
| 61 | + to pass a description of the reboot cause. |
| 62 | + """ |
| 63 | + raise NotImplementedError |
| 64 | + |
| 65 | + def get_component_versions(self): |
| 66 | + """ |
| 67 | + Retrieves platform-specific hardware/firmware versions for chassis |
| 68 | + componenets such as BIOS, CPLD, FPGA, etc. |
| 69 | +
|
| 70 | + Returns: |
| 71 | + A string containing platform-specific component versions |
| 72 | + """ |
| 73 | + raise NotImplementedError |
| 74 | + |
| 75 | + ############################################## |
| 76 | + # Module methods |
| 77 | + ############################################## |
| 78 | + |
| 79 | + def get_num_modules(self): |
| 80 | + """ |
| 81 | + Retrieves the number of modules available on this chassis |
| 82 | +
|
| 83 | + Returns: |
| 84 | + An integer, the number of modules available on this chassis |
| 85 | + """ |
| 86 | + return len(self._module_list) |
| 87 | + |
| 88 | + def get_all_modules(self): |
| 89 | + """ |
| 90 | + Retrieves all modules available on this chassis |
| 91 | +
|
| 92 | + Returns: |
| 93 | + A list of objects derived from ModuleBase representing all |
| 94 | + modules available on this chassis |
| 95 | + """ |
| 96 | + return self._module_list |
| 97 | + |
| 98 | + def get_module(self, index): |
| 99 | + """ |
| 100 | + Retrieves module represented by (0-based) index <index> |
| 101 | +
|
| 102 | + Args: |
| 103 | + index: An integer, the index (0-based) of the module to |
| 104 | + retrieve |
| 105 | +
|
| 106 | + Returns: |
| 107 | + An object dervied from ModuleBase representing the specified |
| 108 | + module |
| 109 | + """ |
| 110 | + module = None |
| 111 | + |
| 112 | + try: |
| 113 | + module = self._module_list[index] |
| 114 | + except IndexError: |
| 115 | + sys.stderr.write("Module index {} out of range (0-{})\n".format( |
| 116 | + index, len(self._module_list)-1)) |
| 117 | + |
| 118 | + return module |
| 119 | + |
| 120 | + ############################################## |
| 121 | + # Fan methods |
| 122 | + ############################################## |
| 123 | + |
| 124 | + def get_num_fans(self): |
| 125 | + """ |
| 126 | + Retrieves the number of fans available on this chassis |
| 127 | +
|
| 128 | + Returns: |
| 129 | + An integer, the number of fan modules available on this chassis |
| 130 | + """ |
| 131 | + return len(self._fan_list) |
| 132 | + |
| 133 | + def get_all_fans(self): |
| 134 | + """ |
| 135 | + Retrieves all fan modules available on this chassis |
| 136 | +
|
| 137 | + Returns: |
| 138 | + A list of objects derived from FanBase representing all fan |
| 139 | + modules available on this chassis |
| 140 | + """ |
| 141 | + return self._fan_list |
| 142 | + |
| 143 | + def get_fan(self, index): |
| 144 | + """ |
| 145 | + Retrieves fan module represented by (0-based) index <index> |
| 146 | +
|
| 147 | + Args: |
| 148 | + index: An integer, the index (0-based) of the fan module to |
| 149 | + retrieve |
| 150 | +
|
| 151 | + Returns: |
| 152 | + An object dervied from FanBase representing the specified fan |
| 153 | + module |
| 154 | + """ |
| 155 | + fan = None |
| 156 | + |
| 157 | + try: |
| 158 | + fan = self._fan_list[index] |
| 159 | + except IndexError: |
| 160 | + sys.stderr.write("Fan index {} out of range (0-{})\n".format( |
| 161 | + index, len(self._fan_list)-1)) |
| 162 | + |
| 163 | + return fan |
| 164 | + |
| 165 | + ############################################## |
| 166 | + # PSU methods |
| 167 | + ############################################## |
| 168 | + |
| 169 | + def get_num_psus(self): |
| 170 | + """ |
| 171 | + Retrieves the number of power supply units available on this chassis |
| 172 | +
|
| 173 | + Returns: |
| 174 | + An integer, the number of power supply units available on this |
| 175 | + chassis |
| 176 | + """ |
| 177 | + return len(self._psu_list) |
| 178 | + |
| 179 | + def get_all_psus(self): |
| 180 | + """ |
| 181 | + Retrieves all power supply units available on this chassis |
| 182 | +
|
| 183 | + Returns: |
| 184 | + A list of objects derived from PsuBase representing all power |
| 185 | + supply units available on this chassis |
| 186 | + """ |
| 187 | + return self._psu_list |
| 188 | + |
| 189 | + def get_psu(self, index): |
| 190 | + """ |
| 191 | + Retrieves power supply unit represented by (0-based) index <index> |
| 192 | +
|
| 193 | + Args: |
| 194 | + index: An integer, the index (0-based) of the power supply unit to |
| 195 | + retrieve |
| 196 | +
|
| 197 | + Returns: |
| 198 | + An object dervied from PsuBase representing the specified power |
| 199 | + supply unit |
| 200 | + """ |
| 201 | + psu = None |
| 202 | + |
| 203 | + try: |
| 204 | + psu = self._psu_list[index] |
| 205 | + except IndexError: |
| 206 | + sys.stderr.write("PSU index {} out of range (0-{})\n".format( |
| 207 | + index, len(self._psu_list)-1)) |
| 208 | + |
| 209 | + return psu |
| 210 | + |
| 211 | + ############################################## |
| 212 | + # Other methods |
| 213 | + ############################################## |
| 214 | + |
| 215 | + def get_watchdog(self): |
| 216 | + """ |
| 217 | + Retreives hardware watchdog device on this chassis |
| 218 | +
|
| 219 | + Returns: |
| 220 | + An object derived from WatchdogBase representing the hardware |
| 221 | + watchdog device |
| 222 | + """ |
| 223 | + return _watchdog |
0 commit comments