support_kit/hosts/
host_control.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::{DeploymentConfig, ShellCommand, SshError};

use super::HostSession;

pub struct HostControl;

impl HostControl {
    #[tracing::instrument(skip(deployment), level = "trace")]
    pub async fn on_hosts(
        deployment: &DeploymentConfig,
        commands: Vec<ShellCommand>,
    ) -> Result<(), SshError> {
        tracing::trace!(
            "executing on {num_hosts} hosts",
            num_hosts = deployment.hosts.len()
        );

        for host in deployment.hosts.clone() {
            tracing::trace!(host = ?host, "connecting to host");
            let connection = HostSession::connect().host(host).call().await?;

            for command in commands.clone() {
                connection.run_cmd(command.command_and_args()).await?;
            }
        }

        Ok(())
    }
}