Пример #1
0
    def reconnect(self, after=10, timeout=10, key_file=None, conn_attempts=10):
        """
        This method will attempt to reconnect with the host, maybe after a reboot action.

        The method will have a limit of 10 attempts to connect by default, for a total
        of 300 seconds before it gives up with the reconnection.

        """
        self.close()
        sleep(after)

        if conn_attempts:
            for i in range(conn_attempts):
                with ignored(ConnectionError):
                    logger.debug('Attempt %d of %d to re-connect to the host',
                                 i, conn_attempts)
                    self.connect(timeout=timeout, key_file=key_file)
                    self.connected = True
                    return True
        else:
            down = True
            i = 1
            while down:
                with ignored(ConnectionError):
                    logger.debug('Attempt %d of inf to re-connect to the host',
                                 i)
                    if self.connect(timeout=timeout, key_file=key_file):
                        down = False
                        self.connected = True
                    i += 1
            return True

        logger.error("Giving up, no attempts left to re-connect to host")
        return False
Пример #2
0
Файл: ssh.py Проект: mennis/oTTo
    def reconnect(self, after=10, timeout=10, key_file=None, conn_attempts=10):
        """
        This method will attempt to reconnect with the host, maybe after a reboot action.

        The method will have a limit of 10 attempts to connect by default, for a total
        of 300 seconds before it gives up with the reconnection.

        """
        self.close()
        sleep(after)

        if conn_attempts:
            for i in range(conn_attempts):
                with ignored(ConnectionError):
                    logger.debug('Attempt %d of %d to re-connect to the host', i, conn_attempts)
                    self.connect(timeout=timeout, key_file=key_file)
                    self.connected = True
                    return True
        else:
            down = True
            i = 1
            while down:
                with ignored(ConnectionError):
                    logger.debug('Attempt %d of inf to re-connect to the host', i)
                    if self.connect(timeout=timeout, key_file=key_file):
                        down = False
                        self.connected = True
                    i += 1
            return True

        logger.error("Giving up, no attempts left to re-connect to host")
        return False
Пример #3
0
    def reconnect(self, after=10, timeout=10, args=None):
        """
        attempts to reconnect to the host in a loop.  ?BUG: This will never give up.

        :param after:
        :type after: float
        :param timeout: length of time to wait each time
        :type timeout: float
        :param args: left in for compatibility with pexpect ssh
        :type args: None
        :return: True
        """
        while 1:
            with ignored(InitiatorError):
                time.sleep(after)
                if super(SolarisSsh, self).connect(timeout=timeout):
                    return True
Пример #4
0
    def reconnect(self, after=10, timeout=10, args=None):
        """
        attempts to reconnect to the host in a loop.  ?BUG: This will never give up.

        :param after:
        :type after: float
        :param timeout: length of time to wait each time
        :type timeout: float
        :param args: left in for compatibility with pexpect ssh
        :type args: None
        :return: True
        """
        while 1:
            with ignored(InitiatorError):
                time.sleep(after)
                if super(SolarisSsh, self).connect(timeout=timeout):
                    return True