graflag.ssh
SSH operations for GraFlag.
- graflag.ssh.remote_path(*parts: str) str[source]
Join path components and quote the result for the remote shell.
Every remote command is a string interpreted by the manager’s shell, so any component that comes from user input (experiment name, method name, dataset) must be quoted before interpolation. Use this for paths and
shlex.quote()for bare values.Separators are collapsed only at the join boundaries – the content of a component is never altered, so a name that happens to contain
/stays intact (and quoted) rather than being silently rewritten.
- graflag.ssh.SSH_FAILED = 255
Options that make ssh fail instead of asking. A client with nobody at the keyboard – the MCP server, whose stdin and stdout are the protocol – must not wait on a password or passphrase prompt: the tool call would hang until the client gave up, with nothing saying why. The exit status ssh uses for its own errors, as opposed to the remote command’s.
- graflag.ssh.require_rsync() None[source]
Raise a usable error when there is no local rsync.
Every copy and sync goes through rsync. Without it – native Windows ships OpenSSH but not rsync – the first copy died in subprocess with a bare FileNotFoundError that named neither the program nor a way out.
- class graflag.ssh.SSHManager(manager_ip: str, ssh_port: str = '22', ssh_key: str = None, batch_mode: bool = False, user: str = 'root', proxy_jump: str = None)[source]
Bases:
objectHandle SSH operations to remote manager.
- property destination: str
user@manager– the one place every ssh and rsync target is built.It was
root@{manager_ip}spelled out at five call sites, so a cluster whose manager takes another account, or sits behind a jump host, needed a hand-written ~/.ssh/config block to be usable at all.
- execute(command: str, capture_output: bool = True) CompletedProcess[source]
Execute command on manager via SSH.
The command is passed to ssh as a single argv element, so no local shell ever parses it. This keeps quoting, heredocs and newlines in
commandintact – the manager’s shell sees exactly what was built here. Callers are still responsible for quoting values they interpolate (seeremote_path()), because the remote shell does parse the string.
- path_exists(remote_shared_dir: str, path: str) bool[source]
Check if path exists on remote manager.
- claim_dir(remote_shared_dir: str, path: str) bool[source]
Create a directory that must not exist yet, atomically.
Returns True if this call created it and False if it was already there; raises on any other failure.
mkdirwithout-pis the atomic step: of two clients racing for the same name exactly one succeeds, which atest -efollowed bymkdir -pcannot promise.
- list_dir(remote_shared_dir: str, path: str) List[str][source]
List directory contents on remote manager.
- copy_files(source_paths, dest_path: str, recursive: bool = False, from_remote: bool = False) str[source]
Copy files/directories bidirectionally via rsync.
- Parameters:
source_paths – Source path(s) - can be single string or list
dest_path – Destination path
recursive – Accepted for compatibility; rsync -a always recurses
from_remote – If True, copy from remote to local; if False (default), copy from local to remote
- Returns:
Destination path