moved container functions into new mod

This commit is contained in:
2025-09-28 18:54:17 +02:00
parent 1f23c303c1
commit d2efc64487
6 changed files with 92 additions and 80 deletions

View File

@@ -0,0 +1,64 @@
use bollard::query_parameters::{ListContainersOptions};
use bollard::Docker;
// Add this function to debug the Docker connection and environment
pub async fn get_available_container(docker: &Docker) {
println!("=== DOCKER ENVIRONMENT DEBUG ===");
// List containers to see what's available - CORRECTED
let options = Some(ListContainersOptions {
all: true, // include stopped containers
..Default::default()
});
match docker.list_containers(options).await {
Ok(containers) => {
println!("Available containers ({}):", containers.len());
for container in containers {
if let Some(id) = container.id {
let short_id = if id.len() > 12 { &id[..12] } else { &id };
println!(" - ID: {}, Image: {:?}", short_id, container.image);
// Also print the names for easier identification
if let Some(names) = container.names {
println!(" Names: {:?}", names);
}
}
}
}
Err(e) => {
eprintln!("Failed to list containers: {}", e);
}
}
}
pub fn extract_container_id(line: &str) -> Option<String> {
// Split by slashes and take the last part
if let Some(last_part) = line.split('/').last() {
let last_part = last_part.trim();
// Remove common suffixes
let clean_id = last_part
.trim_end_matches(".scope")
.trim_start_matches("docker-")
.trim_start_matches("crio-")
.trim_start_matches("containerd-");
// Check if it looks like a container ID (hex characters)
if clean_id.chars().all(|c| c.is_ascii_hexdigit()) && clean_id.len() >= 12 {
return Some(clean_id.to_string());
}
// If it's not pure hex, try to extract hex sequence
let hex_part: String = clean_id.chars()
.take_while(|c| c.is_ascii_hexdigit())
.collect();
if hex_part.len() >= 12 {
return Some(hex_part);
}
}
None
}