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
get_active_process_keys()
get_metadata_file_path(uuid)
staticmethod
Generate metadata file path for a given process UUID.
Uses XDG_RUNTIME_DIR if available, otherwise falls back to /tmp. The path will be expanded on the remote host when the command executes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to generate metadata file path for |
required |
Returns:
| Type | Description |
|---|---|
str
|
Shell-expandable path string containing environment variable reference |
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
kill_all_processes()
Clean up all processes and resources.
Terminates all managed processes and releases all associated resources. Safe to call multiple times.
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
kill_process(uuid, timeout=ProcessLifetimeManager.DEFAULT_TIMEOUT_FOR_KILLING_PROCESS)
Kill a remote process and clean up associated resources upon successful termination.
Sends termination signals to the remote process and waits for it to die. If the process terminates successfully, cleans up all associated resources including remote metadata files and internal tracking. If termination fails, forcibly closes the SSH channel to send a SIGHUP to the remote process.
Safe to call multiple times - subsequent calls will have no effect if resources have already been cleaned up.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID to terminate |
required |
timeout
|
float
|
Timeout for graceful termination in seconds |
DEFAULT_TIMEOUT_FOR_KILLING_PROCESS
|
Returns:
| Type | Description |
|---|---|
Optional[int]
|
Exit code of the terminated process, or None if not found or still running |
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 | |
kill_processes(uuids, process_timeouts=None)
not implemented in paramiko manager
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
kill_processes_by_role(role, candidate_uuids, process_timeouts=None)
not implemented in paramiko manager
Source code in drunc/processes/ssh_process_lifetime_manager_paramiko.py
pop_early_exit_code(uuid)
Get process exit code. Cleaning up all process resources if the exit code is found. The only way this doesn't return None is if the process is dead without kill_process being called.
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
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
read_process_metadata(uuid, metadata_file, hostname, user, timeout=ProcessLifetimeManager.DEFAULT_TIMEOUT_FOR_READING_METADATA)
Read process metadata from remote JSON file with retry logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uuid
|
str
|
Process UUID |
required |
metadata_file
|
str
|
Remote path to metadata file (may contain shell variables) |
required |
hostname
|
str
|
Target hostname |
required |
user
|
str
|
SSH username |
required |
timeout
|
float
|
Maximum time to wait for metadata file in seconds |
DEFAULT_TIMEOUT_FOR_READING_METADATA
|
Returns:
| Type | Description |
|---|---|
Optional[ProcessMetadata]
|
ProcessMetadata instance if file exists and is valid, None otherwise |
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
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 |