API

RemoteMount

class rmount.main.RemoteMount(settings: Remote | S3, remote_path: Path | str, local_path: Path | str, refresh_interval_s: int = 10, timeout: int = 30, verbose: bool = False, error_callback: Callable | None = None)

The class creates a mount point between a remote_path and a local_path based on some configuration settings the interval by which to refresh the cache and robustness to errors via a user-specified timeout. The class manages and monitors an rclone process that is responsible for implementing the mount logic. The mount point is expected to be robust to errors caused by connectivity issues or dead mount points.

When it class encounters an error it triggers SIGKILL to terminate all relevant background processes and itself. For this reason, it is recommended you run it in its process.

Parameters:
  • settings (RemoteConfig) – A remote configuration object specific to the storage type and user preferences. Please see RemoteConfig

  • remote_path (Path | str) – The remote path to connect to the mount point

  • local_path (Path | str) – The local path to the mount point

  • refresh_interval_s (int, optional) – The interval by which to reset the cache, by default 10

  • timeout (int, optional) – The timeout after which many of the processes and functions will raise an error, by default TIMEOUT = 30

  • verbose (bool, optional) – Whether to print rclone logs to the console, by default False

  • error_callback (abc.Callable, optional) – A function called once the process encounters a non-recoverable error. If no call-back is set, and rmount encounters an error, it will send a SIGTERM to the active process which should terminate the entire program, by default None

Raises:

NotImplementedError – If the running OS is Windows.

is_alive(timeout: int | None = None) bool

Check whether the mount process is alive.

Parameters:

timeout (int | None, optional) – The timeout to apply when checking the status of the mounting process, by default None

Returns:

Whether the mount point is active.

Return type:

bool

mount()

Creates a mount point between local_path and remote_path based on the configuration settings. The function creates and monitors several processes that run in the background despite the state of the object. To terminate the background processes you will need to use unmount.

Warning: When the mount process faces a non-recoverable error, it terminates the process in which mount was called. As a result, it is recommended you instantiate a dedicated process for a RemoteMount object.

Raises:

RuntimeError – When the mount process dies with an irrecoverable error.

refresh()

Updates the timestamp file used to signal the health of the mount process.

unmount(timeout: int | None = None)

Tears down the current mount process and kills any related background processes gracefully.

Parameters:

timeout (int | None, optional) – The timeout to apply when unmounting and tearing down the main processes.

RemoteServer

class rmount.server.RemoteServer(local_path: Path | str | None = None, volume_name: str | None = None, public_key: str | None = None, public_key_file: Path | str | None = None, remote_path: Path | str | None = None, ssh_user: str = 'admin', container_name: str | None = None, verbose: bool = False)

A Remote SSH server that can be used for testing or as a safe way to store experiment artifacts without exposing the entire file system to a third party, aka an ABLATOR dashboard.

Parameters:
  • local_path (Path | str | None) – The local path that can be used to access the contents of the RemoteServer. Must be set if volume_name is None

  • volume_name (str | None) – The volume to use to mount the docker container that can be used to access the contents of the RemoteServer. Must be set if local_path is None

  • public_key (str | None) – The public key which allows access to the RemoteServer. Must be set if public_key_file is None

  • public_key_file (str | Path | None) – The path to the public key which allows access to the RemoteServer. Must be set if public_key is None

  • remote_path (Path | str | None, optional) – The remote path that can be used to map to the local_path and access the contents of the RemoteServer. When unspecified, it will be set the same as the local_path e.g. local_path:remote_path -> local_path:local_path, by default None

  • ssh_user (str, optional) – the ssh-user that can be used to access the RemoteServer, by default “admin”

  • container_name (str | None, optional) – The unique name of the container. RemoteServer will kill any other container by the same name to avoid network conflicts, by default rmount-ssh-server

  • verbose (bool, optional) – Whether to print the output of the container to stdout, by default False

ip_address

The local network IP address of the container.

Type:

None | str

ssh_command

The ssh command that can be used to connect to the container through the local network.

Type:

str

Examples

Connect to the SSH server

>>> DEFAULT_PUB_KEY = Path.home() / ".ssh" / "id_rsa.pub"
>>> server = RemoteServer(public_key_file=DEFAULT_PUB_KEY, local_path = "/tmp")
>>> server.start()
>>> assert server.is_alive()
>>> server.ssh_command
... ssh -p 2222 -o StrictHostKeyChecking=no admin@172.17.0.2

To connect and test the server (while the script is running):

$ ssh -p 2222 -o StrictHostKeyChecking=no admin@172.17.0.2

Raises:
  • ValueError – If incorrect arguments are provided.

  • RuntimeError – If the volume_name does not exist.

is_alive() bool

Is used to check whether the container is active and running.

Returns:

Whether the container is alive.

Return type:

bool

kill()

kill the currently running container.

property ssh_command: str

The ssh command that can be used to connect to the container through the local network.

Returns:

A command that can be run on the terminal.

Return type:

str

Raises:

RuntimeError – If the container has died.

start() RemoteServer

Starts the docker container configured by the RemoteServer object’s properties.

Returns:

The RemoteServer object.

Return type:

RemoteServer

Raises:

RuntimeError – If the container can not start succesfully.