|
| 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, 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 | + # Get a mailbox register |
| 22 | + def get_pmc_register(self, reg_name): |
| 23 | + mailbox_dir = "/sys/devices/platform/dell_s6100_lpc" |
| 24 | + retval = 'ERR' |
| 25 | + mb_reg_file = mailbox_dir+'/' + reg_name |
| 26 | + if (not os.path.isfile(mb_reg_file)): |
| 27 | + print mb_reg_file, 'not found !' |
| 28 | + return retval |
| 29 | + |
| 30 | + try: |
| 31 | + with open(mb_reg_file, 'r') as fd: |
| 32 | + retval = fd.read() |
| 33 | + except Exception as error: |
| 34 | + logging.error("Unable to open ", mb_reg_file, "file !") |
| 35 | + |
| 36 | + retval = retval.rstrip('\r\n') |
| 37 | + return retval |
| 38 | + |
| 39 | + def get_num_psus(self): |
| 40 | + """ |
| 41 | + Retrieves the number of PSUs available on the device |
| 42 | + :return: An integer, the number of PSUs available on the device |
| 43 | + """ |
| 44 | + S6100_MAX_PSUS = 2 |
| 45 | + return S6100_MAX_PSUS |
| 46 | + |
| 47 | + def get_psu_status(self, index): |
| 48 | + """ |
| 49 | + Retrieves the oprational status of power supply unit (PSU) defined |
| 50 | + by index <index> |
| 51 | + :param index: An integer, index of the PSU of which to query status |
| 52 | + :return: Boolean, True if PSU is operating properly, False if PSU is\ |
| 53 | + faulty |
| 54 | + """ |
| 55 | + status = 0 |
| 56 | + psu_status = self.get_pmc_register('psu_'+str(index)+'_status') |
| 57 | + if (psu_status != 'ERR'): |
| 58 | + psu_status = int(psu_status, 16) |
| 59 | + # Check for PSU statuse |
| 60 | + if (~psu_status & 0b1000) or (psu_status & 0b0100): |
| 61 | + status = 1 |
| 62 | + |
| 63 | + return status |
| 64 | + |
| 65 | + def get_psu_presence(self, index): |
| 66 | + """ |
| 67 | + Retrieves the presence status of power supply unit (PSU) defined |
| 68 | + by index <index> |
| 69 | + :param index: An integer, index of the PSU of which to query status |
| 70 | + :return: Boolean, True if PSU is plugged, False if not |
| 71 | + """ |
| 72 | + status = 0 |
| 73 | + psu_presence = self.get_pmc_register('psu_'+str(index)+'_status') |
| 74 | + if (psu_presence != 'ERR'): |
| 75 | + psu_presence = int(psu_presence, 16) |
| 76 | + # Check for PSU presence |
| 77 | + if (~psu_presence & 0b1): |
| 78 | + status = 1 |
| 79 | + |
| 80 | + return status |
0 commit comments