apc.py 文件源码

python
阅读 18 收藏 0 点赞 0 评论 0

项目:pynoc 作者: SimplicityGuy 项目源码 文件源码
def outlet_command(self, outlet, operation):
        """Send command to an outlet in the PDU.

        :param outlet: outlet number
        :param operation: one of ['on', 'off', 'reboot']
        :return: did the operation complete successfully?
        """
        valid_operations = ['on', 'off', 'reboot']
        if operation not in valid_operations:
            raise ValueError(
                '"%s" is an invalid operation. Valid operations are: %s',
                str(operation), str(valid_operations)
            )

        operations = {
            'on': 1,
            'off': 2,
            'reboot': 3,
        }

        if 1 <= outlet <= self._num_outlets:
            self._logger.info(
                'Setting outlet %d to %s state', outlet, operation
            )
            self.__set(
                self.Q_OUTLET_COMMAND_RW + (outlet,), operations[operation]
            )

            try:
                if operation in ('on', 'reboot'):
                    success = self.__wait_for_state(outlet, 'on')
                else:
                    success = self.__wait_for_state(outlet, 'off')
            except RetryError:
                # If the operation timed out, no determination of the result
                # can be made.
                success = False

            return success
        else:
            raise IndexError(
                'Only %d outlets exist. "%s" is an invalid outlet.',
                self._num_outlets, str(outlet)
            )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号