mlos_bench.services.remote.ssh.ssh_service
A collection functions for interacting with SSH servers as file shares.
Classes
Wrapper around SSHClient to help provide connection caching and reconnect logic. |
|
Manages a cache of SshClient connections. |
|
Base class for SSH services. |
Module Contents
- class mlos_bench.services.remote.ssh.ssh_service.SshClient(*args: tuple, **kwargs: dict)[source]
Bases:
asyncssh.SSHClient
Wrapper around SSHClient to help provide connection caching and reconnect logic.
Used by the SshService to try and maintain a single connection to hosts, handle reconnects if possible, and use that to run commands rather than reconnect for each command.
- async connection() asyncssh.connection.SSHClientConnection | None [source]
Waits for and returns the asyncssh.connection.SSHClientConnection to be established or lost.
- Return type:
Optional[asyncssh.connection.SSHClientConnection]
- connection_lost(exc: Exception | None) None [source]
Called when a connection is lost or closed
This method is called when a connection is closed. If the connection is shut down cleanly, exc will be None. Otherwise, it will be an exception explaining the reason for the disconnect.
- Parameters:
exc (
Exception
) – The exception which caused the connection to close, or None if the connection closed cleanly- Return type:
None
- connection_made(conn: asyncssh.connection.SSHClientConnection) None [source]
Override hook provided by asyncssh.SSHClient.
Changes the connection_id from _CONNECTION_PENDING to a unique id repr.
- Parameters:
- Return type:
None
- static id_from_connection(connection: asyncssh.connection.SSHClientConnection) str [source]
Gets a unique id repr for the connection.
- Parameters:
connection (asyncssh.connection.SSHClientConnection)
- Return type:
- class mlos_bench.services.remote.ssh.ssh_service.SshClientCache[source]
Manages a cache of SshClient connections.
Note: Only one per event loop thread supported. See additional details in SshService comments.
- enter() None [source]
Manages the cache lifecycle with reference counting.
To be used in the __enter__ method of a caller’s context manager.
- Return type:
None
- exit() None [source]
Manages the cache lifecycle with reference counting.
To be used in the __exit__ method of a caller’s context manager.
- Return type:
None
- async get_client_connection(connect_params: dict) Tuple[asyncssh.connection.SSHClientConnection, SshClient] [source]
Gets a (possibly cached) client connection.
- Parameters:
connect_params (dict) – Parameters to pass to asyncssh.create_connection.
- Returns:
A tuple of (SSHClientConnection, SshClient).
- Return type:
- class mlos_bench.services.remote.ssh.ssh_service.SshService(config: Dict[str, Any] | None = None, global_config: Dict[str, Any] | None = None, parent: mlos_bench.services.base_service.Service | None = None, methods: Dict[str, Callable] | List[Callable] | None = None)[source]
Bases:
mlos_bench.services.base_service.Service
Base class for SSH services.
Create a new service with a given config.
- Parameters:
config (dict) – Free-format dictionary that contains the service configuration. It will be passed as a constructor parameter of the class specified by class_name.
global_config (dict) – Free-format dictionary of global parameters.
parent (Service) – An optional parent service that can provide mixin functions.
methods (Union[Dict[str, Callable], List[Callable], None]) – New methods to register with the service.