srunx.ssh package#
Subpackages#
- srunx.ssh.cli package
- srunx.ssh.core package
- Submodules
- srunx.ssh.core.client module
SlurmJobSSHSlurmClientSSHSlurmClient.__init__()SSHSlurmClient.connect()SSHSlurmClient.disconnect()SSHSlurmClient.test_connection()SSHSlurmClient.execute_command()SSHSlurmClient.upload_file()SSHSlurmClient.cleanup_file()SSHSlurmClient.file_exists()SSHSlurmClient.validate_remote_script()SSHSlurmClient.submit_sbatch_job()SSHSlurmClient.submit_sbatch_file()SSHSlurmClient.cleanup_job_files()SSHSlurmClient.sync_project()SSHSlurmClient.get_job_status()SSHSlurmClient.get_job_output()SSHSlurmClient.get_job_output_detailed()SSHSlurmClient.monitor_job()SSHSlurmClient.tail_log()
- srunx.ssh.core.config module
MountConfigServerProfileConfigManagerConfigManager.__init__()ConfigManager.load_config()ConfigManager.save_config()ConfigManager.add_profile()ConfigManager.remove_profile()ConfigManager.get_profile()ConfigManager.list_profiles()ConfigManager.set_current_profile()ConfigManager.get_current_profile()ConfigManager.get_current_profile_name()ConfigManager.update_profile()ConfigManager.expand_path()ConfigManager.set_profile_env_var()ConfigManager.unset_profile_env_var()ConfigManager.add_profile_mount()ConfigManager.remove_profile_mount()
- srunx.ssh.core.proxy_client module
- srunx.ssh.core.ssh_config module
- Module contents
- srunx.ssh.helpers package
Submodules#
srunx.ssh.example module#
Module contents#
- class srunx.ssh.SSHSlurmClient(hostname, username, password=None, key_filename=None, port=22, proxy_jump=None, ssh_config_path=None, env_vars=None, verbose=False)[source]#
Bases:
object- __init__(hostname, username, password=None, key_filename=None, port=22, proxy_jump=None, ssh_config_path=None, env_vars=None, verbose=False)[source]#
- cleanup_job_files(job)[source]#
Cleanup temporary files for a job if it was a local script
- Return type:
None
- get_job_output(job_id, job_name=None, stdout_offset=0, stderr_offset=0)[source]#
Get job output from SLURM log files.
First tries
scontrol show jobto discover the actual StdOut/StdErr paths configured for the job. Falls back to pattern-based search if scontrol doesn’t return usable paths.When stdout_offset / stderr_offset are non-zero, only the bytes after that position are returned (tail-like incremental reads).
- Return type:
tuple[str,str,int,int]- Returns:
(stdout, stderr, new_stdout_offset, new_stderr_offset)
- get_job_output_detailed(job_id, job_name=None)[source]#
Get detailed job output information including found log files
- Return type:
dict[str,str|list[str] |None]
- monitor_job(job, poll_interval=10, timeout=None)[source]#
Monitor a job until completion
- Return type:
- submit_sbatch_file(script_path, job_name=None, cleanup=True)[source]#
Submit an sbatch job from a local or remote file
- Return type:
SlurmJob|None
- submit_sbatch_job(script_content, job_name=None, dependency=None)[source]#
Submit an sbatch job with script content
- Return type:
SlurmJob|None
- sync_project(local_path=None, remote_path=None, *, delete=True, dry_run=False, exclude_patterns=None)[source]#
Sync the local project directory to the remote workspace via rsync.
- Parameters:
local_path (
str|None) – Local project root to sync. If None, uses git toplevel or cwd.remote_path (
str|None) – Remote destination. If None, uses the default~/.config/srunx/workspace/{repo_name}/.delete (
bool) – Remove remote files not present locally (default True).dry_run (
bool) – Preview what would be transferred without syncing.exclude_patterns (
list[str] |None) – Additional exclude patterns for this sync.
- Return type:
str- Returns:
The remote project path (for use with
sbatch --chdir).- Raises:
RuntimeError – If rsync is not available or key-based auth is not configured.
- tail_log(job_id, job_name=None, follow=False, last_n=None, poll_interval=1.0)[source]#
Display job logs with optional real-time streaming via SSH.
- Parameters:
job_id (
str) – SLURM job IDjob_name (
str|None) – Job name for better log file detectionfollow (
bool) – If True, continuously stream new log lines (like tail -f)last_n (
int|None) – Show only the last N linespoll_interval (
float) – Polling interval in seconds for follow mode
- Returns:
success: Whether log retrieval was successful
log_content: Log content (empty in follow mode)
tail_command: Command to execute for follow mode (None in static mode)
status_message: Status or error message
log_file: Path to the primary log file
- Return type:
Dictionary with log information
- test_connection()[source]#
Test SSH connection and SLURM availability.
- Returns:
ssh_connected: Whether SSH connection succeeded
slurm_available: Whether SLURM commands are available
hostname: Remote hostname
user: Remote username
slurm_version: SLURM version if available
error: Error message if connection failed
- Return type:
Dictionary with test results including
- class srunx.ssh.SlurmJob(job_id, name, status='UNKNOWN', output_file=None, error_file=None, script_path=None, is_local_script=False, _cleanup=False)[source]#
Bases:
object- __init__(job_id, name, status='UNKNOWN', output_file=None, error_file=None, script_path=None, is_local_script=False, _cleanup=False)#
-
error_file:
str|None= None#
-
is_local_script:
bool= False#
-
output_file:
str|None= None#
-
script_path:
str|None= None#
-
status:
str= 'UNKNOWN'#
-
job_id:
str#
-
name:
str#