SSH/SCP connection to a single remote host via the system ssh/scp.
More...
#include <JobScheduler.hpp>
|
| struct | Secrets |
| | SSH credentials; never exposed outside this class. More...
|
| |
|
| | ClusterConnection (std::string host, std::string user, std::string key_path, int port=22, bool shell_capable=true) |
| | Stores connection parameters; opens no connection.
|
| |
| | ~ClusterConnection () |
| | Closes the multiplexed master via terminate_connection().
|
| |
| bool | start_connection () |
| | Opens (and pins) the multiplexed SSH master with a no-op command.
|
| |
| bool | terminate_connection () |
| | Tears down the multiplexed master via ssh -O exit (best effort).
|
| |
| bool | copy_remote (const std::string &local_filepath, const std::string &remote_dir, const std::string &remote_name="") |
| | Uploads a local file to a remote directory via SCP.
|
| |
| bool | copy_files (const std::vector< std::string > &local_filepaths, const std::string &remote_dir) |
| | Uploads several local files to a remote directory in one SCP session.
|
| |
| bool | fetch_remote (const std::string &remote_filepath, const std::string &local_dir) |
| | Downloads a single remote file into a local directory via SCP.
|
| |
| std::string | execute_remote_command (const std::string &command) |
| | Executes a shell command on the remote host and returns its stdout.
|
| |
SSH/SCP connection to a single remote host via the system ssh/scp.
Auth uses the operator's SSH certificate already in place (ssh-agent, or a key file whose matching *-cert.pub ssh picks up). Host keys are verified against CLUSTER_KNOWN_HOSTS; host-key checking is never disabled.
Lifecycle: construct, start_connection() (opens a multiplexed ControlMaster, retrying CINECA's flaky handshakes), then copy_remote() / fetch_remote() / execute_remote_command() reuse that socket, then terminate_connection() (the destructor also does it).
- Note
- Not copyable; holds the per-host
ControlPath socket template.
◆ ClusterConnection()
| ClusterConnection::ClusterConnection |
( |
std::string |
host, |
|
|
std::string |
user, |
|
|
std::string |
key_path, |
|
|
int |
port = 22, |
|
|
bool |
shell_capable = true |
|
) |
| |
Stores connection parameters; opens no connection.
- Parameters
-
| host | Hostname or IP of the remote node. |
| user | SSH username. |
| key_path | Path passed to ssh -i; empty to rely on the ssh-agent. |
| port | TCP port (default 22). |
| shell_capable | false for hosts that reject shell commands (e.g. the CINECA data-mover): start/terminate become no-ops and SCP runs without ControlMaster, so no shell session is opened. |
◆ ~ClusterConnection()
| ClusterConnection::~ClusterConnection |
( |
| ) |
|
◆ copy_files()
| bool ClusterConnection::copy_files |
( |
const std::vector< std::string > & |
local_filepaths, |
|
|
const std::string & |
remote_dir |
|
) |
| |
Uploads several local files to a remote directory in one SCP session.
Equivalent to calling copy_remote() once per file, but issues a single scp f1 f2 ... user@host:remote_dir/ so only one connection (and, for the data-mover, one handshake) is paid for the whole set. Each file keeps its basename on the remote — callers needing a rename must stage the file under the desired name locally first.
- Parameters
-
| local_filepaths | Paths to upload; all must exist or the call fails. |
| remote_dir | Absolute destination directory on the remote host. |
- Returns
true if every file transferred successfully.
◆ copy_remote()
| bool ClusterConnection::copy_remote |
( |
const std::string & |
local_filepath, |
|
|
const std::string & |
remote_dir, |
|
|
const std::string & |
remote_name = "" |
|
) |
| |
Uploads a local file to a remote directory via SCP.
- Parameters
-
| local_filepath | Absolute or relative path to the source file. |
| remote_dir | Absolute path of the destination directory on the remote. Must be an absolute path — env vars such as $SCRATCH are not expanded on the data-mover node. |
| remote_name | If non-empty, the file is stored under this name instead of the original filename. Used to avoid concurrent-job collisions for batch files. |
- Returns
true on success.
◆ execute_remote_command()
| std::string ClusterConnection::execute_remote_command |
( |
const std::string & |
command | ) |
|
Executes a shell command on the remote host and returns its stdout.
- Parameters
-
| command | The command string run via the system ssh binary over a multiplexed master connection. |
- Returns
- The captured stdout, or an empty string if the channel could not be opened or the exec failed.
- Warning
- SECURITY:
command must be built from compile-time constants or env-var secrets set at startup — never from incoming data (e.g. MQTT payloads).
◆ fetch_remote()
| bool ClusterConnection::fetch_remote |
( |
const std::string & |
remote_filepath, |
|
|
const std::string & |
local_dir |
|
) |
| |
Downloads a single remote file into a local directory via SCP.
- Parameters
-
| remote_filepath | Absolute path to the file on the remote host. |
| local_dir | Local directory where the file will be written (filename is preserved from the remote path). |
- Returns
true if the file was downloaded, or if it simply does not exist on the remote (a benign "nothing to fetch" — logged once, not retried); false only on a transport error (retried within the budget first).
◆ start_connection()
| bool ClusterConnection::start_connection |
( |
| ) |
|
Opens (and pins) the multiplexed SSH master with a no-op command.
Retries with backoff to absorb CINECA's flaky handshakes. Once it succeeds, later transfers/commands reuse the master socket.
- Returns
true if the master could be established within the retry budget; otherwise false with a diagnostic on std::clog.
◆ terminate_connection()
| bool ClusterConnection::terminate_connection |
( |
| ) |
|
Tears down the multiplexed master via ssh -O exit (best effort).
Safe to call multiple times; failures are ignored.
- Returns
- Always
true.
◆ control_path
| std::string ClusterConnection::control_path |
|
private |
-o ControlPath= socket template for multiplexing.
◆ secrets
◆ shell_capable_
| bool ClusterConnection::shell_capable_ |
|
private |
False for transfer-only hosts (data-mover).
The documentation for this class was generated from the following files: