Add Tailscale network support for host connections
All checks were successful
Build and Release / build-and-release (push) Successful in 1m31s
All checks were successful
Build and Release / build-and-release (push) Successful in 1m31s
Implement configurable network routing for both local and Tailscale networks. Dashboard now supports intelligent connection selection with automatic fallback between network types. Add IP configuration fields and connection routing logic for ZMQ and SSH operations. Features: - Host configuration with local and Tailscale IP addresses - Configurable connection types (local/tailscale/auto) - Automatic fallback between network connections - Updated ZMQ connection logic with retry support - SSH command routing through configured IP addresses
This commit is contained in:
@@ -84,13 +84,13 @@ impl ZmqConsumer {
|
||||
}
|
||||
}
|
||||
|
||||
/// Connect to predefined hosts
|
||||
pub async fn connect_to_predefined_hosts(&mut self, hosts: &[String]) -> Result<()> {
|
||||
/// Connect to predefined hosts using their configuration
|
||||
pub async fn connect_to_predefined_hosts(&mut self, hosts: &std::collections::HashMap<String, crate::config::HostDetails>) -> Result<()> {
|
||||
let default_port = self.config.subscriber_ports[0];
|
||||
|
||||
for hostname in hosts {
|
||||
// Try to connect, but don't fail if some hosts are unreachable
|
||||
if let Err(e) = self.connect_to_host(hostname, default_port).await {
|
||||
for (hostname, host_details) in hosts {
|
||||
// Try to connect using configured IP, but don't fail if some hosts are unreachable
|
||||
if let Err(e) = self.connect_to_host_with_details(hostname, host_details, default_port).await {
|
||||
warn!("Could not connect to {}: {}", hostname, e);
|
||||
}
|
||||
}
|
||||
@@ -104,6 +104,29 @@ impl ZmqConsumer {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Connect to a host using its configuration details with fallback support
|
||||
pub async fn connect_to_host_with_details(&mut self, hostname: &str, host_details: &crate::config::HostDetails, port: u16) -> Result<()> {
|
||||
// Get primary connection IP
|
||||
let primary_ip = host_details.get_connection_ip(hostname);
|
||||
|
||||
// Try primary connection
|
||||
if let Ok(()) = self.connect_to_host(&primary_ip, port).await {
|
||||
info!("Connected to {} via primary address: {}", hostname, primary_ip);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
// Try fallback IPs if primary fails
|
||||
let fallbacks = host_details.get_fallback_ips(hostname);
|
||||
for fallback_ip in fallbacks {
|
||||
if let Ok(()) = self.connect_to_host(&fallback_ip, port).await {
|
||||
info!("Connected to {} via fallback address: {}", hostname, fallback_ip);
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
Err(anyhow::anyhow!("Failed to connect to {} using all available addresses", hostname))
|
||||
}
|
||||
|
||||
/// Receive command output from any connected agent (non-blocking)
|
||||
pub async fn receive_command_output(&mut self) -> Result<Option<CommandOutputMessage>> {
|
||||
match self.subscriber.recv_bytes(zmq::DONTWAIT) {
|
||||
|
||||
Reference in New Issue
Block a user