soprano.hpc.submitter.utils#

Utilities for remote submission, especially using Paramiko for SSH

Classes

RemoteTarget(host[, timeout])

RemoteTarget object

RemoteTargetContext(rT)

RemoteTargetContext object

class soprano.hpc.submitter.utils.RemoteTarget(host, timeout=1.0)[source]#

Bases: object

RemoteTarget object

Uses Paramiko to embed into one single object all we need to connect and send orders to some remote machine. It will accept a single host name as an argument and requires it to be present in the ~/.ssh/config file with all relevant parameters. It also must have an ssh key configurated for access (passwords are NOT accepted as they can’t be stored and passed safely) and must have already been added to known_hosts (in other words, you must already have connected to it from the shell).

Initialize the RemoteTarget

Args:
host (str): the name of the target to connect to, as present
in the ~/.ssh/config file
timeout (Optional[float]): connection timeout in seconds (default
is 1 second)
property context#

Returns a context using this RemoteTarget to connect. This is done this way so that we only need to instantiate the Target once to avoid pointless overhead but still can handle the connection securely by making sure it’s closed no matter what.

class soprano.hpc.submitter.utils.RemoteTargetContext(rT)[source]#

Bases: object

RemoteTargetContext object

Works as a context to be used with the ‘with’ statement. Should usually just be created by a RemoteTarget through the appropriate property.

run_cmd(cmd, cwd=None, stdin=None)[source]#

Run a command on the remote machine.

Args:
cmd (str): command to run remotely
cwd (Optional[str]): working directory in which to run the command
stdin (Optional[str]): content to communicate to the command’s
stdin
Returns:
stdout, stderr (str): string representations of output and error
messages from the command
soprano.hpc.submitter.utils._ensure_open_sftp(f)[source]#

Decorator for SFTP related functions in RemoteTargetContext