lib.ec.ssh.AsyncSSH: Add class

Add a SSHClient implementation using AsyncSSH. This is the first and
currently only class derived from SSHClient which implements
SSHClient.Cap.LogOutput, designed to consume and log command output
as it streams in. It felt like the lower hanging fruit not to do that
with Paramiko: Paramiko doesn't provide a native async API, so it
would need to spawn additional worker threads. I think.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-03-21 04:29:58 +01:00
commit 737cbc3e24
2 changed files with 244 additions and 2 deletions

View file

@ -129,9 +129,11 @@ class SSHClient(ExecContext):
def ssh_client(*args, **kwargs) -> SSHClient: # export
from importlib import import_module
errors: list[str] = []
for name in ['Paramiko', 'Exec']:
for name in ['AsyncSSH', 'Paramiko', 'Exec']:
try:
return getattr(import_module(f'jw.pkg.lib.ec.ssh.{name}'), name)(*args, **kwargs)
ret = getattr(import_module(f'jw.pkg.lib.ec.ssh.{name}'), name)(*args, **kwargs)
log(INFO, f'Using SSH-client "{name}"')
return ret
except Exception as e:
msg = f'Can\'t instantiate SSH client class {name} ({str(e)})'
errors.append(msg)