mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
lib.ec.SSHClient.ssh_client(): Add type parameter
ssh_client() tries a predefined order of client class implementations until it finds a workable candidate. For testing all, it's desirable to be able to target the exact class. Add a "type" parameter to achieve that. I'm aware that type is also a function. But the semantics look so compelling to me that I'm using the variable name anyway. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
bafc7fed2a
commit
a58220a131
1 changed files with 4 additions and 2 deletions
|
|
@ -129,10 +129,12 @@ class SSHClient(ExecContext):
|
||||||
def username(self) -> str:
|
def username(self) -> str:
|
||||||
return self.__username
|
return self.__username
|
||||||
|
|
||||||
def ssh_client(*args, **kwargs) -> SSHClient: # export
|
def ssh_client(*args, type=['AsyncSSH', 'Paramiko', 'Exec'], **kwargs) -> SSHClient: # export
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
errors: list[str] = []
|
errors: list[str] = []
|
||||||
for name in ['AsyncSSH', 'Paramiko', 'Exec']:
|
if isinstance(type, str):
|
||||||
|
type = [type]
|
||||||
|
for name in type:
|
||||||
try:
|
try:
|
||||||
ret = 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}"')
|
log(INFO, f'Using SSH-client "{name}"')
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue