예제 #1
0
    def get_speed(self):
        try:
            return int(self.__reg_speed_getter.decode())
        except Exception as e:
            logger.error(e.message)

        return 0
예제 #2
0
    def get_status(self):
        """
        Retrieves the operational status of the PSU

        Returns:
            bool: True if PSU is operating properly, False if not
        """
        # status = False
        # psu_status = self._get_pmc_register(self.psu_presence_reg)
        # if (psu_status != 'ERR'):
        #     psu_status = int(psu_status, 16)
        #     # Checking whether both bit 3 and bit 2 are not set
        #     if (~psu_status & 0b1000) and (~psu_status & 0b0100):
        #         status = True

        if self._hal_psu:
            return self._hal_psu.get_status()

        try:
            if isinstance(self.reg_status, Reg):
                psu_status = self.reg_status.decode()
                if psu_status == 1 or psu_status == "1":
                    return True
                elif psu_status == 0 or psu_status == "0":
                    return False
        except Exception as e:
            logger.error(e.message)

        return False
예제 #3
0
    def get_current(self):
        """
        Retrieves present electric current supplied by PSU

        Returns:
            A float number, electric current in amperes,
            e.g. 15.4
        """
        # psu_current = self._get_pmc_register(self.psu_current_reg)
        # if (psu_current != 'ERR') and self.get_presence():
        #     # Converting the value returned by driver which is in
        #     # milliamperes to amperes
        #     psu_current = float(psu_current) / 1000
        # else:
        #     psu_current = 0.0

        if self._hal_psu:
            pass

        try:
            if isinstance(self.__reg_out_cur, Reg):
                return self.__reg_out_cur.decode()
        except Exception as e:
            logger.error(e.message)

        return 0.0
예제 #4
0
    def get_voltage(self):
        """
        Retrieves current PSU voltage output

        Returns:
            A float number, the output voltage in volts,
            e.g. 12.1
        """
        # psu_voltage = self._get_pmc_register(self.psu_voltage_reg)
        # if (psu_voltage != 'ERR') and self.get_presence():
        #     # Converting the value returned by driver which is in
        #     # millivolts to volts
        #     psu_voltage = float(psu_voltage) / 1000
        # else:
        #     psu_voltage = 0.0

        if self._hal_psu:
            pass

        try:
            if isinstance(self.__reg_out_vol, Reg):
                return self.__reg_out_vol.decode()
        except Exception as e:
            logger.error(e.message)

        return 0.0
예제 #5
0
    def set_speed(self, speed):
        try:
            return self.__reg_speed_setter.encode(speed)
        except Exception as e:
            logger.error(e.message)

        return False
예제 #6
0
    def get_speed_percentage(self):
        try:
            speed = self.get_speed()
            return (100 * speed) / self.__speed_max
        except Exception as e:
            logger.error(e.message)

        return 0
예제 #7
0
    def get_firmware_version(self):
        """
        Retrieves the firmware version of the component

        Returns:
            A string containing the firmware version of the component
        """
        try:
            return self._reg_fm_ver.decode()
        except Exception as e:
            logger.error(str(e))

        return ""
예제 #8
0
    def get_high_threshold(self):
        """
        Retrieves the high threshold temperature of thermal

        Returns:
            A float number, the high threshold temperature of thermal in Celsius
            up to nearest thousandth of one degree Celsius, e.g. 30.125
        """
        try:
            if isinstance(self.__reg_high_thresnold, Reg):
                return float(self.__reg_high_thresnold.decode())
        except Exception as e:
            logger.error(e.message)

        return None
예제 #9
0
    def get_temperature(self):
        """
        Retrieves current temperature reading from thermal

        Returns:
            A float number of current temperature in Celsius up to nearest thousandth
            of one degree Celsius, e.g. 30.125 
        """
        try:
            if isinstance(self.__reg_temperature, Reg):
                return self.__reg_temperature.decode()
        except Exception as e:
            logger.error(e.message)

        return None
예제 #10
0
    def get_low_critical_threshold(self):
        """
        Retrieves the low critical threshold temperature of thermal

        Returns:
            A float number, the low critical threshold temperature of thermal in Celsius
            up to nearest thousandth of one degree Celsius, e.g. 30.125
        """
        try:
            if isinstance(self.__reg_crit_low_threshold, Reg):
                return float(self.__reg_crit_low_threshold.decode())
        except Exception as e:
            logger.error(str(e))

        return None
예제 #11
0
    def get_model(self):
        """
        Retrieves the part number of the FAN
        Returns:
            string: Part number of FAN
        """
        if self._hal_fan:
            return self._hal_fan.pn()

        try:
            if isinstance(self.__reg_pn, Reg):
                return self.__reg_pn.decode()
        except Exception as e:
            logger.error(str(e))

        return "NA"
예제 #12
0
    def get_serial(self):
        """
        Retrieves the serial number of the FAN
        Returns:
            string: Serial number of FAN
        """
        if self._hal_fan:
            return self._hal_fan.sn()

        try:
            if isinstance(self.__reg_sn, Reg):
                return self.__reg_sn.decode()
        except Exception as e:
            logger.error(str(e))

        return "NA"
예제 #13
0
    def get_serial(self):
        """
        Retrieves the serial number of the PSU

        Returns:
            string: Serial number of PSU
        """
        if self._hal_psu:
            return self._hal_psu.sn()

        try:
            if isinstance(self.__reg_sn, Reg):
                return self.__reg_sn.decode()
        except Exception as e:
            logger.error(e.message)

        return "NA"
예제 #14
0
    def get_model(self):
        """
        Retrieves the part number of the PSU

        Returns:
            string: Part number of PSU
        """

        if self._hal_psu:
            return self._hal_psu.pn()

        try:
            if isinstance(self.__reg_pn, Reg):
                return self.__reg_pn.decode()
        except Exception as e:
            logger.error(e.message)

        return "NA"
예제 #15
0
    def get_presence(self):
        """
        Retrieves the presence of the Power Supply Unit (PSU)

        Returns:
            bool: True if PSU is present, False if not
        """
        if self._hal_psu:
            pass

        try:
            if isinstance(self.__reg_present, Reg):
                psu_presence = self.__reg_present.decode()
                if psu_presence == 0 or psu_presence == "0":
                    return True
        except Exception as e:
            logger.error(e.message)

        return False
예제 #16
0
    def set_high_threshold(self, temperature):
        """
        Sets the high threshold temperature of thermal

        Args : 
            temperature: A float number up to nearest thousandth of one degree Celsius, 
            e.g. 30.125

        Returns:
            A boolean, True if threshold is set successfully, False if not
        """
        try:
            if isinstance(self.__reg_high_thresnold, Reg):
                temp_val = str(int(temperature * 1000))
                return self.__reg_high_thresnold.encode(temp_val)
        except Exception as e:
            logger.error(str(e))

        return False
예제 #17
0
    def get_power(self):
        """
        Retrieves current energy supplied by PSU

        Returns:
            A float number, the power in watts,
            e.g. 302.6
        """

        if self._hal_psu:
            pass

        try:
            if isinstance(self.__reg_out_pow, Reg):
                return self.__reg_out_pow.decode()
        except Exception as e:
            logger.error(e.message)

        return 0.0
예제 #18
0
    def get_presence(self):
        """
        Retrieves the presence of the FAN
        Returns:
            bool: True if fan is present, False if not
        """

        # print self.fan_presence_reg.decode()
        # return True if self.fan_presence_reg.decode() == 0 else False
        if self._hal_fan:
            return self._hal_fan.get_presence()

        try:
            if isinstance(self.__reg_present, Reg):
                present = self.__reg_present.decode()
                if present == 0 or present == "0":
                    return True
        except Exception as e:
            logger.error(str(e))

        return False
예제 #19
0
    def install_firmware(self, image_path):
        """
        Installs firmware to the component

        Args:
            image_path: A string, path to firmware image

        Returns:
            A boolean, True if install was successful, False if not
        """
        try:
            successtips = "CPLD Upgrade succeeded!"
            status, output = subprocess.getstatusoutput(
                "which firmware_upgrade")
            if status or len(output) <= 0:
                logger.error("no upgrade tool.")
                return False
            cmdstr = "%s %s cpld %d cpld" % (output, image_path, self.slot)
            ret, log = subprocess.getstatusoutput(cmdstr)
            if ret == 0 and successtips in log:
                return True
            logger.error("upgrade failed. ret:%d, log:\n%s" % (ret, log))
        except Exception as e:
            logger.error(str(e))
        return False
예제 #20
0
    def get_status_led(self):
        """
        Gets the state of the Fan status LED

        Returns:
            A string, one of the predefined STATUS_LED_COLOR_* strings.
        """
        # TODO
        if self.is_psu_fan:
            # No LED available for PSU Fan
            return None
        else:
            try:
                if isinstance(self.__reg_led, Reg):
                    led_color = self.__reg_led.decode()
                    for color, code in self.__led_colors.items():
                        if code ^ led_color == 0:
                            return color
            except Exception as e:
                logger.error(str(e))

            return None
예제 #21
0
    def get_reboot_cause(self):
        """
        Retrieves the cause of the previous reboot
        Returns:
            A tuple (string, string) where the first element is a string
            containing the cause of the previous reboot. This string must be
            one of the predefined strings in this class. If the first string
            is "REBOOT_CAUSE_HARDWARE_OTHER", the second string can be used
            to pass a description of the reboot cause.
        """
        try:
            is_power_loss = False
            # enable read
            subprocess.getstatusoutput(self.disable_write)
            subprocess.getstatusoutput(self.enable_read)
            ret, log = subprocess.getstatusoutput(self.read_value)
            if ret == 0 and "0x0a" in log:
                is_power_loss = True

            # erase i2c and e2
            subprocess.getstatusoutput(self.enable_erase)
            time.sleep(1)
            subprocess.getstatusoutput(self.disable_erase)
            # clear data
            subprocess.getstatusoutput(self.enable_write)
            subprocess.getstatusoutput(self.disable_read)
            subprocess.getstatusoutput(self.disable_write)
            subprocess.getstatusoutput(self.enable_read)
            # enable write and set data
            subprocess.getstatusoutput(self.enable_write)
            subprocess.getstatusoutput(self.disable_read)
            subprocess.getstatusoutput(self.write_value)
            if is_power_loss:
                return (self.REBOOT_CAUSE_POWER_LOSS, None)
        except Exception as e:
            logger.error(str(e))

        return (self.REBOOT_CAUSE_NON_HARDWARE, None)
예제 #22
0
 def set_status_led(self, color):
     """
     Set led to expected color
     Args:
         color: A string representing the color with which to set the
                fan module status LED
     Returns:
         bool: True if set success, False if fail.
     """
     # TODO
     if self.is_psu_fan:
         # No LED available for PSU Fan
         return False
     try:
         if color not in self.__led_colors:
             logger.error("color:%s not defined." % color)
             return False
         val = hex(self.__led_colors[color])
         if isinstance(self.__reg_led, Reg):
             return self.__reg_led.encode(val)
         return ret
     except Exception as e:
         logger.error(str(e))
     return False