mlos_bench.services.remote.ssh.ssh_service module

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

class mlos_bench.services.remote.ssh.ssh_service.SshClient(*args: tuple, **kwargs: dict)

Bases: 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.

Methods

auth_banner_received(msg, lang)

An incoming authentication banner was received

auth_completed()

Authentication was completed successfully

connection()

Waits for and returns the SSHClientConnection to be established or lost.

connection_lost(exc)

Called when a connection is lost or closed

connection_made(conn)

Override hook provided by asyncssh.SSHClient.

debug_msg_received(msg, lang, always_display)

A debug message was received on this connection

id_from_connection(connection)

Gets a unique id repr for the connection.

id_from_params(connect_params)

Gets a unique id repr for the connection.

kbdint_auth_requested()

Keyboard-interactive authentication has been requested

kbdint_challenge_received(name, ...)

A keyboard-interactive auth challenge has been received

password_auth_requested()

Password authentication has been requested

password_change_failed()

The requested password change has failed

password_change_requested(prompt, lang)

A password change has been requested

password_changed()

The requested password change was successful

public_key_auth_requested()

Public key authentication has been requested

validate_host_ca_key(host, addr, port, key)

Return whether key is an authorized CA key for this host

validate_host_public_key(host, addr, port, key)

Return whether key is an authorized key for this host

async connection() SSHClientConnection | None

Waits for and returns the SSHClientConnection to be established or lost.

connection_lost(exc: Exception | None) None

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

connection_made(conn: SSHClientConnection) None

Override hook provided by asyncssh.SSHClient.

Changes the connection_id from _CONNECTION_PENDING to a unique id repr.

static id_from_connection(connection: SSHClientConnection) str

Gets a unique id repr for the connection.

static id_from_params(connect_params: dict) str

Gets a unique id repr for the connection.

class mlos_bench.services.remote.ssh.ssh_service.SshClientCache

Bases: object

Manages a cache of SshClient connections.

Note: Only one per event loop thread supported. See additional details in SshService comments.

Methods

cleanup()

Closes all cached connections.

enter()

Manages the cache lifecycle with reference counting.

exit()

Manages the cache lifecycle with reference counting.

get_client_connection(connect_params)

Gets a (possibly cached) client connection.

cleanup() None

Closes all cached connections.

enter() None

Manages the cache lifecycle with reference counting.

To be used in the __enter__ method of a caller’s context manager.

exit() None

Manages the cache lifecycle with reference counting.

To be used in the __exit__ method of a caller’s context manager.

async get_client_connection(connect_params: dict) Tuple[SSHClientConnection, SshClient]

Gets a (possibly cached) client connection.

Parameters:
connect_params: dict

Parameters to pass to asyncssh.create_connection.

Returns:
Tuple[SSHClientConnection, SshClient]

A tuple of (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: Service | None = None, methods: Dict[str, Callable] | List[Callable] | None = None)

Bases: Service

Base class for SSH services.

Attributes:
config_loader_service

Return a config loader service.

Methods

clear_client_cache()

Clears the cache of client connections.

export()

Return a dictionary of functions available in this service.

merge_methods(ext_methods, local_methods)

Merge methods from the external caller with the local ones.

new(class_name[, config, global_config, parent])

Factory method for a new service with a given config.

pprint()

Produce a human-readable string listing all public methods of the service.

register(services)

Register new mix-in services.

classmethod clear_client_cache() None

Clears the cache of client connections.

Note: This may cause in flight operations to fail.