Skip to content

Remote

Remote

Used to run commands over SSH asynchronously in subprocesses while sharing an SSH connection.

This doesn't work on Windows, as it assumes that the SSH client has SSH multiplexing support (ControlMaster, ControlPath and ControlPersist).

connect

connect(hostname: str) -> Self

Async 'constructor'.

Using this once explicitly before running lots of commands in parallel can be useful, since otherwise the 2FA prompt might happen for each individual command.

TODO: cache this function's result using an async-compatible version of functools.cache maybe?

get_output

get_output(
    command: str,
    *,
    display: bool = False,
    warn: bool = False,
    hide: Hide = True,
) -> str

Runs the command asynchronously and returns the stripped output string.

run

run(
    program_and_args: tuple[str, ...],
    input: str | None = None,
    warn: bool = False,
    hide: Hide = False,
    _stacklevel: int = 2,
    _display: bool | str = False,
) -> CompletedProcess[str]

Runs the command asynchronously in a subprocess and returns the result.

Parameters

program_and_args: The program and arguments to pass to it. This is a tuple of strings, same as in subprocess.Popen. input: The optional 'input' argument to subprocess.Popen.communicate(). warn: When True and an exception occurs, warn instead of raising the exception. hide: Controls the printing of the subprocess' stdout and stderr.

Returns

A subprocess.CompletedProcess object with the result of the asyncio.Process.

Raises

subprocess.CalledProcessError If an error occurs when running the command and warn is False.

control_socket_is_running

control_socket_is_running(host: str) -> bool

Asynchronously checks whether the control socket at the given path is running.

get_ssh_options_for_host

get_ssh_options_for_host(hostname: str) -> dict[str, str]

Returns the dictionary of ssh options for a given host (taken from ssh -G <hostname>).