//! # Docker Module //! //! This module provides Docker integration for WatcherAgent, including container enumeration, statistics, and lifecycle management. //! //! ## Responsibilities //! - **Container Management:** Lists, inspects, and manages Docker containers relevant to the agent. //! - **Statistics Aggregation:** Collects network and CPU statistics for all managed containers. //! - **Lifecycle Operations:** Supports container restart and ID lookup for agent self-management. //! pub mod container; pub mod serverclientcomm; use std::error::Error; use crate::models::DockerContainer; /// Aggregated Docker statistics for all managed containers. /// /// # Fields /// - `number`: Number of running containers (optional) /// - `net_in_total`: Total network receive rate in **bytes per second (B/s)** (optional) /// - `net_out_total`: Total network transmit rate in **bytes per second (B/s)** (optional) /// - `dockers`: List of [`DockerContainer`] statistics (optional) #[derive(Debug, Clone)] pub struct DockerInfo { pub number: Option, pub net_in_total: Option, pub net_out_total: Option, pub dockers: Option>, } impl DockerInfo { /// Collects Docker statistics for all managed containers. /// /// # Returns /// * `Result>` - Aggregated Docker statistics or error if collection fails. pub async fn collect() -> Result> { Ok(Self { number: None, net_in_total: None, net_out_total: None, dockers: None }) } } impl DockerContainer { /* /// Restarts the specified Docker container by ID. /// /// # Arguments /// * `docker` - Reference to a Bollard Docker client /// /// # Returns /// * `Result<(), Box>` - Ok if restarted successfully, error otherwise. pub async fn restart_container(docker: &Docker) -> Result<(), Box> { // ...existing code... } */ /// Returns the container ID for a given [`DockerContainer`]. /// /// # Arguments /// * `container` - Reference to a [`DockerContainer`] /// /// # Returns /// * `Result>` - Container ID as integer. pub async fn get_docker_container_id(container: DockerContainer) -> Result> { Ok(container.ID) } /// Returns the image name for a given [`DockerContainer`]. /// /// # Arguments /// * `container` - Reference to a [`DockerContainer`] /// /// # Returns /// * `Result>` - Image name as string. pub async fn get_docker_container_image(container: DockerContainer) -> Result> { Ok(container.image) } }