Refactor dnsmasq leases-based guest IP discovery and bump version to 0.1.8

- Update IP selection logic to prefer the latest lease based on epoch timestamp.
- Remove redundant IP discovery logic in `net-dhcp-leases`.
- Increment orchestrator version to 0.1.8 for release.

Signed-off-by: Till Wegmueller <toasterson@gmail.com>
This commit is contained in:
Till Wegmueller 2025-11-17 22:00:46 +01:00
parent a6ed0f0c69
commit f1d161655f
No known key found for this signature in database
2 changed files with 9 additions and 5 deletions

View file

@ -1,6 +1,6 @@
[package] [package]
name = "orchestrator" name = "orchestrator"
version = "0.1.7" version = "0.1.8"
edition = "2024" edition = "2024"
build = "build.rs" build = "build.rs"

View file

@ -464,16 +464,21 @@ async fn discover_guest_ip_virsh(domain: &str, timeout: Duration) -> Option<Stri
let path = format!("/var/lib/libvirt/dnsmasq/{}.leases", net); let path = format!("/var/lib/libvirt/dnsmasq/{}.leases", net);
let content_opt = task::spawn_blocking(move || std::fs::read_to_string(path)).await.ok().and_then(|r| r.ok()); let content_opt = task::spawn_blocking(move || std::fs::read_to_string(path)).await.ok().and_then(|r| r.ok());
if let Some(content) = content_opt { if let Some(content) = content_opt {
let mut best_ip: Option<String> = None;
let mut best_epoch: i64 = -1;
for line in content.lines() { for line in content.lines() {
// Format: epoch MAC IP hostname clientid // Format: epoch MAC IP hostname clientid
let parts: Vec<&str> = line.split_whitespace().collect(); let parts: Vec<&str> = line.split_whitespace().collect();
if parts.len() >= 3 && parts[1].eq_ignore_ascii_case(mac_s.as_str()) { if parts.len() >= 3 && parts[1].eq_ignore_ascii_case(mac_s.as_str()) {
let ip = parts[2].to_string(); let epoch: i64 = parts[0].parse::<i64>().unwrap_or(0);
debug!(domain=%domain, method="dnsmasq.leases", ip=%ip, "discovered IP"); if epoch > best_epoch {
return Some(ip); best_epoch = epoch;
best_ip = Some(parts[2].to_string());
} }
} }
} }
if let Some(ip) = best_ip { debug!(domain=%domain, method="dnsmasq.leases", ip=%ip, "discovered IP"); return Some(ip); }
}
} }
// 2b) Try virsh net-dhcp-leases <network> // 2b) Try virsh net-dhcp-leases <network>
if let Some(net) = net_name.clone() { if let Some(net) = net_name.clone() {
@ -487,7 +492,6 @@ async fn discover_guest_ip_virsh(domain: &str, timeout: Duration) -> Option<Stri
} }
} }
} }
if let Some(ip) = parse_ipv4_from_text(&att_leases.stdout) { debug!(domain=%domain, method="net-dhcp-leases-any", ip=%ip, "discovered IP"); return Some(ip); }
} }
last_attempts.push(att_leases); last_attempts.push(att_leases);
} }