How to use the flintrock.exceptions.SSHError function in Flintrock

To help you get started, we’ve selected a few Flintrock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nchammas / flintrock / flintrock / core.py View on Github external
]

    for command in possible_cmds:
        try:
            output = ssh_check_output(
                client=client,
                command=command)
            tokens = output.split()
            # First line of the output is like: 'java version "1.8.0_20"'
            # Get the version string and strip out the first two parts of the
            # version as a tuple: (1, 8)
            if len(tokens) >= 3:
                version_parts = tokens[2].strip('"').split(".")
                if len(version_parts) >= 2:
                    return tuple(int(part) for part in version_parts[:2])
        except SSHError:
            pass

    return None
github nchammas / flintrock / flintrock / ssh.py View on Github external
get_pty=True,
        timeout=timeout_seconds)

    # NOTE: Paramiko doesn't clearly document this, but we must read() before
    #       calling recv_exit_status().
    #       See: https://github.com/paramiko/paramiko/issues/448#issuecomment-159481997
    stdout_output = stdout.read().decode('utf8').rstrip('\n')
    stderr_output = stderr.read().decode('utf8').rstrip('\n')
    exit_status = stdout.channel.recv_exit_status()

    if exit_status:
        # TODO: Return a custom exception that includes the return code.
        #       See: https://docs.python.org/3/library/subprocess.html#subprocess.check_output
        # NOTE: We are losing the output order here since output from stdout and stderr
        #       may be interleaved.
        raise SSHError(
            host=client.get_transport().getpeername()[0],
            message=stdout_output + stderr_output)

    return stdout_output
github nchammas / flintrock / flintrock / ssh.py View on Github external
raise
            logger.debug("[{h}] SSH exception: {e}".format(h=host, e=e))
            time.sleep(5)
        # We get this exception during startup with CentOS but not Amazon Linux,
        # for some reason.
        except paramiko.ssh_exception.AuthenticationException as e:
            logger.debug("[{h}] SSH AuthenticationException.".format(h=host))
            time.sleep(5)
        except paramiko.ssh_exception.SSHException as e:
            raise SSHError(
                host=host,
                message="SSH protocol error. Possible causes include using "
                "the wrong key file or username.",
            ) from e
    else:
        raise SSHError(
            host=host,
            message="Could not connect via SSH.")

    return client