foundation_deployment_docker 0.1.3

Docker Engine API v1.53 client over DynNetClient + valtron (bollard-free)
//! Auto-generated API module for docker stats.
//!
//! Generated by `cargo run --bin ewe_platform gen_api`.
//! DO NOT EDIT MANUALLY.
//!
//! Feature flag: `docker_stats `

#![cfg(feature = "docker_stats")]
#![allow(clippy::too_many_arguments, clippy::type_complexity)]
#![allow(
    clippy::missing_errors_doc,
    clippy::doc_markdown,
    clippy::useless_format
)]
#![allow(unused_imports)]

use foundation_macros::JsonHash;
use foundation_netio::shared::client::http_client::HttpClient;
use foundation_netio::{DynNetClient, PreparedRequestBuilder};
use serde::{Deserialize, Serialize};

use super::shared::ApiResponse;

// =============================================================================
// TYPE DECLARATIONS
// =============================================================================

/// `ContainerBlkioStatEntry` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerBlkioStatEntry {
    /// `major` property.
    pub major: Option<i64>,
    /// `minor` property.
    pub minor: Option<i64>,
    /// `op` property.
    pub op: Option<String>,
    /// `value` property.
    pub value: Option<i64>,
}

/// `ContainerBlkioStats` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerBlkioStats {
    /// `io_merged_recursive` property.
    pub io_merged_recursive: Option<Vec<ContainerBlkioStatEntry>>,
    /// `io_queue_recursive` property.
    pub io_queue_recursive: Option<Vec<ContainerBlkioStatEntry>>,
    /// `io_service_bytes_recursive` property.
    pub io_service_bytes_recursive: Option<Vec<ContainerBlkioStatEntry>>,
    /// `io_service_time_recursive` property.
    pub io_service_time_recursive: Option<Vec<ContainerBlkioStatEntry>>,
    /// `io_serviced_recursive` property.
    pub io_serviced_recursive: Option<Vec<ContainerBlkioStatEntry>>,
    /// `io_time_recursive` property.
    pub io_time_recursive: Option<Vec<ContainerBlkioStatEntry>>,
    /// `io_wait_time_recursive` property.
    pub io_wait_time_recursive: Option<Vec<ContainerBlkioStatEntry>>,
    /// `sectors_recursive` property.
    pub sectors_recursive: Option<Vec<ContainerBlkioStatEntry>>,
}

/// `ContainerCPUStats` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerCPUStats {
    /// `cpu_usage` property.
    pub cpu_usage: Option<ContainerCPUUsage>,
    /// `online_cpus` property.
    pub online_cpus: Option<i64>,
    /// `system_cpu_usage` property.
    pub system_cpu_usage: Option<i64>,
    /// `throttling_data` property.
    pub throttling_data: Option<ContainerThrottlingData>,
}

/// `ContainerCPUUsage` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerCPUUsage {
    /// `percpu_usage` property.
    pub percpu_usage: Option<Vec<i64>>,
    /// `total_usage` property.
    pub total_usage: Option<i64>,
    /// `usage_in_kernelmode` property.
    pub usage_in_kernelmode: Option<i64>,
    /// `usage_in_usermode` property.
    pub usage_in_usermode: Option<i64>,
}

/// `ContainerMemoryStats` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerMemoryStats {
    /// `commitbytes` property.
    pub commitbytes: Option<i64>,
    /// `commitpeakbytes` property.
    pub commitpeakbytes: Option<i64>,
    /// `failcnt` property.
    pub failcnt: Option<i64>,
    /// `limit` property.
    pub limit: Option<i64>,
    /// `max_usage` property.
    pub max_usage: Option<i64>,
    /// `privateworkingset` property.
    pub privateworkingset: Option<i64>,
    /// `stats` property.
    pub stats: Option<serde_json::Value>,
    /// `usage` property.
    pub usage: Option<i64>,
}

/// `ContainerPidsStats` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerPidsStats {
    /// `current` property.
    pub current: Option<i64>,
    /// `limit` property.
    pub limit: Option<i64>,
}

/// `ContainerStatsResponse` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerStatsResponse {
    /// `blkio_stats` property.
    pub blkio_stats: Option<ContainerBlkioStats>,
    /// `cpu_stats` property.
    pub cpu_stats: Option<ContainerCPUStats>,
    /// `id` property.
    pub id: Option<String>,
    /// `memory_stats` property.
    pub memory_stats: Option<ContainerMemoryStats>,
    /// `name` property.
    pub name: Option<String>,
    /// `networks` property.
    pub networks: Option<serde_json::Value>,
    /// `num_procs` property.
    pub num_procs: Option<i64>,
    /// `os_type` property.
    pub os_type: Option<String>,
    /// `pids_stats` property.
    pub pids_stats: Option<ContainerPidsStats>,
    /// `precpu_stats` property.
    pub precpu_stats: Option<ContainerCPUStats>,
    /// `preread` property.
    pub preread: Option<String>,
    /// `read` property.
    pub read: Option<String>,
    /// `storage_stats` property.
    pub storage_stats: Option<ContainerStorageStats>,
}

/// `ContainerStorageStats` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerStorageStats {
    /// `read_count_normalized` property.
    pub read_count_normalized: Option<i64>,
    /// `read_size_bytes` property.
    pub read_size_bytes: Option<i64>,
    /// `write_count_normalized` property.
    pub write_count_normalized: Option<i64>,
    /// `write_size_bytes` property.
    pub write_size_bytes: Option<i64>,
}

/// `ContainerThrottlingData` type.
#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonHash)]
pub struct ContainerThrottlingData {
    /// `periods` property.
    pub periods: Option<i64>,
    /// `throttled_periods` property.
    pub throttled_periods: Option<i64>,
    /// `throttled_time` property.
    pub throttled_time: Option<i64>,
}

// =============================================================================
// ARGS TYPES (per-endpoint)
// =============================================================================

/// Arguments for [`ContainerStats_request`].
#[derive(Debug, Clone, Default, Serialize, JsonHash)]
pub struct ContainerStatsArgs {
    /// Path parameter: `id`.
    pub id: String,
    /// Query parameter: `stream`.
    pub stream: Option<String>,
    /// Query parameter: `one-shot`.
    pub one_shot: Option<String>,
}

// =============================================================================
// CLIENT FUNCTIONS (per-endpoint)
// =============================================================================

// -----------------------------------------------------------------------------
// GET /containers/{id}/stats
// -----------------------------------------------------------------------------

/// GET /containers/{id}/stats.
///
/// Takes a client and args, builds the request, optionally applies
/// modifications, then sends it via `send_async().await`.
///
/// # Arguments
///
/// * `client` - HTTP client for making the request: a `DynNetClient`, or an `ApiClient` carrying the `BodyLimits` the response is read under
/// * `args` - Request arguments (path params, query params, body)
/// * `builder_mod` - Optional closure to modify the request builder (e.g., add headers)
///
/// # Response body
///
/// Returned unread, as a stream of `ContainerStatsResponse`, one per line: read it with `.next().await`.
/// The status is checked before the body is touched.
///
/// # Example
///
/// ```ignore
/// let response = container_stats_request(client.clone(), &args, Some(|b: &mut PreparedRequestBuilder| {
///     b.header("X-Custom-Header", "value");
/// })).await?;
/// ```
pub async fn container_stats_request<F>(
    client: impl Into<super::shared::ApiClient>,
    args: &ContainerStatsArgs,
    base_url: &str,
    builder_mod: Option<F>,
) -> Result<
    ApiResponse<super::shared::JsonLinesStream<ContainerStatsResponse>>,
    super::shared::ApiError,
>
where
    F: FnOnce(&mut PreparedRequestBuilder),
{
    let path = format!("/containers/{}/stats", args.id,);
    let endpoint_url = format!("{}{}", base_url, path);

    let mut builder = PreparedRequestBuilder::get(&endpoint_url)
        .map_err(|e| super::shared::ApiError::RequestBuildFailed(e.to_string()))?;

    builder = builder.query("stream", args.stream.as_deref());
    builder = builder.query("one-shot", args.one_shot.as_deref());

    if let Some(f) = builder_mod {
        f(&mut builder);
    }

    super::shared::send_json_lines(client.into(), builder.build()).await
}