ssh_process_lifetime_manager_paramiko
drunc.processes.ssh_process_lifetime_manager_paramiko
Provides SSH connection and lifetime management
Classes
SSHProcessLifetimeManagerParamiko(disable_host_key_check=False, disable_localhost_host_key_check=False, logger=None, on_process_exit=None)
Bases: ProcessLifetimeManager
Supports process lifecycle management of processes started via SSH, output capture, and exit code tracking.
Initialise SSH connection manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
disable_host_key_check
|
bool
|
Disable SSH host key verification for all hosts |
False
|
disable_localhost_host_key_check
|
bool
|
Disable SSH host key verification for localhost |
False
|
logger
|
Optional[Logger]
|
Logger instance for real-time output logging |
None
|
on_process_exit
|
Optional[Callable[[str, Optional[int], Optional[Exception]], None]]
|
Optional callback function(uuid, exit_code, exception) invoked when process exits |
None
|
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
Functions
cleanup_all()
Clean up all processes and resources.
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
cleanup_process(uuid)
Clean up process resources.
Terminates the process (if still running) and releases all associated resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to clean up |
required |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
get_active_process_keys()
get_exit_code(uuid)
Get process exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID |
required |
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Exit code if process has terminated, None if still running or not found |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
get_process_stderr(uuid)
Get stderr from process.
Note: With output redirection to log files, stderr capture is minimal.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Accumulated stderr content as string, None if not found |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
get_process_stdout(uuid)
Get stdout from process.
Note: With output redirection to log files, stdout capture is minimal. This primarily captures the initial "SSHPM: Starting process..." message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID |
required |
Returns:
| Type | Description |
|---|---|
Optional[str]
|
Accumulated stdout content as string, None if not found |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
is_process_alive(uuid)
Check if SSH process is alive.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to check |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if process is alive, False otherwise |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
read_log_file(hostname, user, log_file, num_lines=100)
Read remote log file via SSH.
Creates a temporary SSH connection to read the log file and returns the last N lines.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hostname
|
str
|
Target hostname |
required |
user
|
str
|
SSH username |
required |
log_file
|
str
|
Remote log file path |
required |
num_lines
|
int
|
Number of lines to read from end of file |
100
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List of log lines |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
start_process(uuid, boot_request)
Start a remote process via SSH using the boot request configuration.
Extracts all necessary parameters from the boot request and delegates to _execute_ssh_command for SSH connection and process execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Unique identifier for this process |
required |
boot_request
|
BootRequest
|
BootRequest containing process configuration, metadata, environment variables, and execution parameters |
required |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If SSH connection or process execution fails |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
terminate_process(uuid, timeout=10.0)
Terminate SSH process by closing the connection.
The PTY allocation ensures the remote process receives SIGHUP when the SSH connection closes, causing graceful termination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to terminate |
required |
timeout
|
float
|
Timeout for graceful termination (used for waiting) |
10.0
|
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
validate_host_connection(host, auth_method, user=getpass.getuser())
Validate SSH connections for all hosts in the collected applications.
This method attempts to establish an SSH connection to the specified host and execute a simple command to verify connectivity. Used to validate access.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
host
|
str
|
Target hostname |
required |
auth_method
|
str
|
Authentication method to use ('publickey' or 'gssapi-with-mic') |
required |
user
|
str
|
SSH username (default: current user) |
getuser()
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If SSH connection or command execution fails |