mlos_bench.services.remote.ssh.ssh_service

A collection functions for interacting with SSH servers as file shares.

Classes

SshClient

Wrapper around SSHClient to help provide connection caching and reconnect logic.

SshClientCache

Manages a cache of SshClient connections.

SshService

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.

Parameters:
__repr__() str[source]
Return type:

str

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:

conn (asyncssh.connection.SSHClientConnection)

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:

str

static id_from_params(connect_params: dict) str[source]

Gets a unique id repr for the connection.

Parameters:

connect_params (dict)

Return type:

str

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.

__len__() int[source]
Return type:

int

__str__() str[source]
Return type:

str

cleanup() None[source]

Closes all cached connections.

Return type:

None

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:

Tuple[asyncssh.connection.SSHClientConnection, SshClient]

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.

classmethod clear_client_cache() None[source]

Clears the cache of client connections.

Note: This may cause in flight operations to fail.

Return type:

None