|
| 1 | +# |
| 2 | +# psuutil.py |
| 3 | +# Platform-specific PSU status interface for SONiC |
| 4 | +# |
| 5 | + |
| 6 | + |
| 7 | +import os.path |
| 8 | + |
| 9 | +try: |
| 10 | + from sonic_psu.psu_base import PsuBase |
| 11 | +except ImportError as e: |
| 12 | + raise ImportError(str(e) + "- required module not found") |
| 13 | + |
| 14 | + |
| 15 | +class PsuUtil(PsuBase): |
| 16 | + """Platform-specific PSUutil class""" |
| 17 | + |
| 18 | + def __init__(self): |
| 19 | + PsuBase.__init__(self) |
| 20 | + |
| 21 | + def get_cpld_register(self, reg_name): |
| 22 | + cpld_dir = "/sys/devices/platform/dell-s6000-cpld.0" |
| 23 | + retval = 'ERR' |
| 24 | + reg_file = cpld_dir +'/' + reg_name |
| 25 | + if (not os.path.isfile(reg_file)): |
| 26 | + return retval |
| 27 | + |
| 28 | + try: |
| 29 | + with open(reg_file, 'r') as fd: |
| 30 | + retval = fd.read() |
| 31 | + except Exception as error: |
| 32 | + logging.error("Unable to open ", reg_file, "file !") |
| 33 | + |
| 34 | + retval = retval.rstrip('\r\n') |
| 35 | + return retval |
| 36 | + |
| 37 | + def get_num_psus(self): |
| 38 | + """ |
| 39 | + Retrieves the number of PSUs available on the device |
| 40 | + :return: An integer, the number of PSUs available on the device |
| 41 | + """ |
| 42 | + S6000_MAX_PSUS = 2 |
| 43 | + return S6000_MAX_PSUS |
| 44 | + |
| 45 | + def get_psu_status(self, index): |
| 46 | + """ |
| 47 | + Retrieves the oprational status of power supply unit (PSU) defined |
| 48 | + by index <index> |
| 49 | + :param index: An integer, index of the PSU of which to query status |
| 50 | + :return: Boolean, True if PSU is operating properly, False if PSU is\ |
| 51 | + faulty |
| 52 | + """ |
| 53 | + status = 0 |
| 54 | + psu_status = self.get_cpld_register('psu'+str(index - 1)+'_status') |
| 55 | + if (psu_status != 'ERR'): |
| 56 | + status = int(psu_status, 10) |
| 57 | + |
| 58 | + presence = self.get_psu_presence(index) |
| 59 | + |
| 60 | + return (status & presence) |
| 61 | + |
| 62 | + def get_psu_presence(self, index): |
| 63 | + """ |
| 64 | + Retrieves the presence status of power supply unit (PSU) defined |
| 65 | + by index <index> |
| 66 | + :param index: An integer, index of the PSU of which to query status |
| 67 | + :return: Boolean, True if PSU is plugged, False if not |
| 68 | + """ |
| 69 | + status = 0 |
| 70 | + psu_presence = self.get_cpld_register('psu'+str(index - 1)+'_prs') |
| 71 | + if (psu_presence != 'ERR'): |
| 72 | + status = int(psu_presence, 10) |
| 73 | + |
| 74 | + return status |
0 commit comments