1use anyhow::Result;
16use owo_colors::OwoColorize;
17use std::path::Path;
18
19use crate::executor::ParallelExecutor;
20use crate::node::Node;
21use crate::ssh::known_hosts::StrictHostKeyChecking;
22use crate::ui::OutputFormatter;
23
24pub async fn ping_nodes(
25 nodes: Vec<Node>,
26 max_parallel: usize,
27 key_path: Option<&Path>,
28 strict_mode: StrictHostKeyChecking,
29 use_agent: bool,
30 use_password: bool,
31) -> Result<()> {
32 println!(
33 "{}",
34 OutputFormatter::format_command_header("ping", nodes.len())
35 );
36
37 let key_path = key_path.map(|p| p.to_string_lossy().to_string());
38 let executor = ParallelExecutor::new_with_all_options(
39 nodes.clone(),
40 max_parallel,
41 key_path,
42 strict_mode,
43 use_agent,
44 use_password,
45 );
46
47 let results = executor.execute("echo 'pong'").await?;
48
49 let mut success_count = 0;
50 let mut failed_count = 0;
51
52 println!("\n{} {}\n", "▶".cyan(), "Connection Test Results".bold());
53
54 for result in &results {
55 if result.is_success() {
56 success_count += 1;
57 println!(
58 " {} {} - {}",
59 "●".green(),
60 result.node.to_string().bold(),
61 "Connected".green()
62 );
63 } else {
64 failed_count += 1;
65 println!(
66 " {} {} - {}",
67 "●".red(),
68 result.node.to_string().bold(),
69 "Failed".red()
70 );
71 if let Err(e) = &result.result {
72 println!(" {} {}", "└".dimmed(), e.to_string().dimmed());
73 }
74 }
75 }
76
77 println!(
78 "{}",
79 OutputFormatter::format_summary(nodes.len(), success_count, failed_count)
80 );
81
82 Ok(())
83}