herolib_virt/nerdctl/container_types.rs
1// File: /root/code/git.threefold.info/herocode/sal/src/virt/nerdctl/container_types.rs
2
3use std::collections::HashMap;
4
5/// Container struct for nerdctl operations
6#[derive(Clone)]
7pub struct Container {
8 /// Name of the container
9 pub name: String,
10 /// Container ID
11 pub container_id: Option<String>,
12 /// Base image (if created from an image)
13 pub image: Option<String>,
14 /// Configuration options
15 pub config: HashMap<String, String>,
16 /// Port mappings
17 pub ports: Vec<String>,
18 /// Volume mounts
19 pub volumes: Vec<String>,
20 /// Environment variables
21 pub env_vars: HashMap<String, String>,
22 /// Network to connect to
23 pub network: Option<String>,
24 /// Network aliases
25 pub network_aliases: Vec<String>,
26 /// CPU limit
27 pub cpu_limit: Option<String>,
28 /// Memory limit
29 pub memory_limit: Option<String>,
30 /// Memory swap limit
31 pub memory_swap_limit: Option<String>,
32 /// CPU shares
33 pub cpu_shares: Option<String>,
34 /// Restart policy
35 pub restart_policy: Option<String>,
36 /// Health check
37 pub health_check: Option<HealthCheck>,
38 /// Whether to run in detached mode
39 pub detach: bool,
40 /// Snapshotter to use
41 pub snapshotter: Option<String>,
42 /// Runtime to use (e.g., "kata-runtime", "runc")
43 pub runtime: Option<String>,
44 /// Disk size limit (for Kata containers, sets VM block device size)
45 pub disk_limit: Option<String>,
46 /// OCI annotations (key-value pairs passed to runtime)
47 pub annotations: HashMap<String, String>,
48 /// Whether to run the container in privileged mode
49 pub privileged: bool,
50 /// Device mounts (e.g., "/dev/net/tun")
51 pub devices: Vec<String>,
52}
53
54/// Health check configuration for a container
55#[derive(Debug, Clone)]
56pub struct HealthCheck {
57 /// Command to run for health check
58 pub cmd: String,
59 /// Time between running the check (default: 30s)
60 pub interval: Option<String>,
61 /// Maximum time to wait for a check to complete (default: 30s)
62 pub timeout: Option<String>,
63 /// Number of consecutive failures needed to consider unhealthy (default: 3)
64 pub retries: Option<u32>,
65 /// Start period for the container to initialize before counting retries (default: 0s)
66 pub start_period: Option<String>,
67}
68
69/// Container status information
70#[derive(Debug, Clone)]
71pub struct ContainerStatus {
72 /// Container state (e.g., running, stopped)
73 pub state: String,
74 /// Container status
75 pub status: String,
76 /// Creation time
77 pub created: String,
78 /// Start time
79 pub started: String,
80 /// Health status (if health check is configured)
81 pub health_status: Option<String>,
82 /// Health check output (if health check is configured)
83 pub health_output: Option<String>,
84}
85
86/// Container resource usage information
87#[derive(Debug, Clone)]
88pub struct ResourceUsage {
89 /// CPU usage percentage
90 pub cpu_usage: String,
91 /// Memory usage
92 pub memory_usage: String,
93 /// Memory limit
94 pub memory_limit: String,
95 /// Memory usage percentage
96 pub memory_percentage: String,
97 /// Network input
98 pub network_input: String,
99 /// Network output
100 pub network_output: String,
101 /// Block input
102 pub block_input: String,
103 /// Block output
104 pub block_output: String,
105 /// PIDs
106 pub pids: String,
107}