1use core::fmt;
2use std::collections::HashMap;
3
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6
7use crate::models::podman::common::{
8 blkio_weight_device::BlkioWeightDevice, health_check::HealthCheck,
9 inspect_device::InspectDevice, inspect_host_port::InspectHostPort, inspect_mount::InspectMount,
10 schema2_health_config::Schema2HealthConfig,
11};
12
13#[derive(Default)]
14pub struct ContainerInspectOptions<'a> {
15 pub name: &'a str,
16 pub size: Option<bool>,
17}
18
19#[derive(Deserialize, Serialize)]
20#[serde(rename_all = "PascalCase")]
21pub struct ContainerInspect {
22 pub app_armor_profile: String,
23 pub args: Vec<String>,
24 pub bounding_caps: Vec<String>,
25 pub config: ContainerInspectConfig,
26 pub conmon_pid_file: String,
27 pub created: DateTime<Utc>,
28 pub dependencies: Vec<String>,
29 pub driver: String,
30 pub effective_caps: Vec<String>,
31 #[serde(rename = "ExecIDs")]
32 pub exec_ids: Vec<String>,
33 pub graph_driver: ContainerInspectGraphDriver,
34 pub host_config: ContainerInspectHostConfig,
35 pub hostname_path: String,
36 pub hosts_path: String,
37 pub id: String,
38 pub image: String,
39 pub image_digest: String,
40 pub image_name: String,
41 pub is_infra: bool,
42 pub is_service: bool,
43 pub kube_exit_code_propagation: String,
44 #[serde(rename = "lockNumber")]
45 pub lock_number: u32,
46 pub mount_label: String,
47 pub mounts: Vec<InspectMount>,
48 pub name: String,
49 pub namespace: String,
50 pub network_settings: ContainerInspectNetworkSettings,
51 #[serde(rename = "OCIConfigPath")]
52 pub oci_config_path: String,
53 #[serde(rename = "OCIRuntime")]
54 pub oci_runtime: String,
55 pub path: String,
56 pub pid_file: String,
57 pub pod: String,
58 pub process_label: String,
59 pub resolv_conf_path: String,
60 pub restart_count: i32,
61 pub rootfs: String,
62 pub size_root_fs: i64,
63 pub size_rw: i64,
64 pub state: ContainerInspectState,
65 pub static_dir: String,
66 pub use_image_hostname: bool,
67 pub use_image_hosts: bool,
68}
69
70impl fmt::Debug for ContainerInspect {
71 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
72 let json = serde_json::to_string_pretty(self).map_err(|_| fmt::Error)?;
73 f.write_str(&json)
74 }
75}
76
77#[derive(Deserialize, Serialize)]
78#[serde(rename_all = "PascalCase")]
79pub struct ContainerInspectConfig {
80 pub annotations: HashMap<String, String>,
81 pub attach_stderr: bool,
82 pub attach_stdin: bool,
83 pub attach_stdout: bool,
84 pub chroot_dirs: Vec<String>,
85 pub cmd: Vec<String>,
86 pub create_command: Vec<String>,
87 pub domainname: String,
88 pub entrypoint: Vec<String>,
89 pub env: Vec<String>,
90 pub exposed_ports: HashMap<String, serde_json::Value>,
91 pub healthcheck: Schema2HealthConfig,
92 pub healthcheck_max_log_count: u64,
93 pub healthcheck_max_log_size: u64,
94 pub healthcheck_on_failure_action: String,
95 pub health_log_destination: String,
96 pub hostname: String,
97 pub image: String,
98 pub labels: HashMap<String, String>,
99 pub on_build: String,
100 pub open_stdin: bool,
101 pub passwd: bool,
102 #[serde(rename = "sdNotifyMode")]
103 pub sd_notify_mode: String,
104 #[serde(rename = "sdNotifySocket")]
105 pub sd_notify_socket: String,
106 pub secrets: Vec<ContainerInspectConfigSecret>,
107 pub startup_health_check: ContainerInspectConfigStartupHealthCheck,
108 pub stdin_once: bool,
109 pub stop_signal: String,
110 pub stop_timeout: u64,
111 pub systemd_mode: bool,
112 pub timeout: u64,
113 pub timezone: String,
114 pub tty: bool,
115 pub umask: String,
116 pub user: String,
117 pub volumes: HashMap<String, serde_json::Value>,
118 pub working_dir: String,
119}
120
121#[derive(Deserialize, Serialize)]
122#[serde(rename_all = "PascalCase")]
123pub struct ContainerInspectConfigSecret {
124 #[serde(rename = "GID")]
125 pub gid: u32,
126 #[serde(rename = "ID")]
127 pub id: String,
128 pub mode: u32,
129 pub name: String,
130 #[serde(rename = "UID")]
131 pub uid: u32,
132}
133
134#[derive(Deserialize, Serialize)]
135#[serde(rename_all = "PascalCase")]
136pub struct ContainerInspectConfigStartupHealthCheck {
137 pub interval: Option<i64>,
138 pub retries: Option<i64>,
139 pub start_interval: Option<i64>,
140 pub start_period: Option<i64>,
141 pub successes: Option<i64>,
142 pub test: Option<Vec<String>>,
143 pub timeout: Option<i64>,
144}
145
146#[derive(Deserialize, Serialize)]
147#[serde(rename_all = "PascalCase")]
148pub struct ContainerInspectGraphDriver {
149 pub data: HashMap<String, String>,
150 pub name: String,
151}
152
153#[derive(Deserialize, Serialize)]
154#[serde(rename_all = "PascalCase")]
155pub struct ContainerInspectHostConfig {
156 pub annotations: HashMap<String, String>,
157 pub auto_remove: bool,
158 pub auto_remove_image: bool,
159 pub binds: Vec<String>,
160 pub blkio_device_read_bps: Vec<ContainerInspectHostConfigBlkioThrottleDevice>,
161 #[serde(rename = "BlkioDeviceReadIOps")]
162 pub blkio_device_read_iops: Vec<ContainerInspectHostConfigBlkioThrottleDevice>,
163 pub blkio_device_write_bps: Vec<ContainerInspectHostConfigBlkioThrottleDevice>,
164 #[serde(rename = "BlkioDeviceWriteIOps")]
165 pub blkio_device_write_iops: Vec<ContainerInspectHostConfigBlkioThrottleDevice>,
166 pub blkio_weight: u16,
167 pub blkio_weight_device: Vec<BlkioWeightDevice>,
168 pub cap_add: Vec<String>,
169 pub cap_drop: Vec<String>,
170 pub cgroup: String,
171 pub cgroup_conf: HashMap<String, String>,
172 pub cgroup_manager: String,
173 pub cgroup_mode: String,
174 pub cgroup_parent: String,
175 pub cgroups: String,
176 pub console_size: Vec<u64>,
177 #[serde(rename = "ContainerIDFile")]
178 pub container_id_file: String,
179 pub cpu_count: u64,
180 pub cpu_percent: u64,
181 pub cpu_period: u64,
182 pub cpu_quota: i64,
183 pub cpu_realtime_period: u64,
184 pub cpu_realtime_runtime: i64,
185 pub cpuset_cpus: String,
186 pub cpuset_mems: String,
187 pub cpu_shares: u64,
188 pub devices: Vec<InspectDevice>,
189 pub disk_quota: u64,
190 pub dns: Vec<String>,
191 pub dns_options: Vec<String>,
192 pub dns_search: Vec<String>,
193 pub extra_hosts: Vec<String>,
194 pub group_add: Vec<String>,
195 pub hosts_file: String,
196 #[serde(rename = "IDMappings")]
197 pub id_mappings: ContainerInspectHostConfigIdMappings,
198 pub init: bool,
199 #[serde(rename = "IntelRdtClosID")]
200 pub intel_rdt_clos_id: String,
201 #[serde(rename = "IOMaximumBandwidth")]
202 pub io_maximum_bandwidth: u64,
203 #[serde(rename = "IOMaximumIOps")]
204 pub io_maximum_iops: u64,
205 pub ipc_mode: String,
206 pub isolation: String,
207 pub kernel_memory: i64,
208 pub links: Vec<String>,
209 pub log_config: ContainerInspectHostConfigLogConfig,
210 pub memory: i64,
211 pub memory_reservation: i64,
212 pub memory_swap: i64,
213 pub memory_swappiness: i64,
214 pub nano_cpus: i64,
215 pub network_mode: String,
216 pub oom_kill_disable: bool,
217 pub oom_score_adj: i64,
218 pub pid_mode: String,
219 pub pids_limit: i64,
220 pub port_bindings: HashMap<String, Vec<InspectHostPort>>,
221 pub privileged: bool,
222 pub publish_all_ports: bool,
223 pub readonly_rootfs: bool,
224 pub restart_policy: ContainerInspectHostConfigRestartPolicy,
225 pub runtime: String,
226 pub security_opt: Vec<String>,
227 pub shm_size: i64,
228 pub tmp_fs: HashMap<String, String>,
229 pub ulimits: Vec<ContainerInspectHostConfigUlimit>,
230 pub userns_mode: String,
231 #[serde(rename = "UTSMode")]
232 pub uts_mode: String,
233 pub volume_driver: String,
234 pub volumes_from: Vec<String>,
235}
236
237#[derive(Deserialize, Serialize)]
238#[serde(rename_all = "PascalCase")]
239pub struct ContainerInspectHostConfigBlkioThrottleDevice {
240 pub path: String,
241 pub rate: u64,
242}
243
244#[derive(Deserialize, Serialize)]
245#[serde(rename_all = "PascalCase")]
246pub struct ContainerInspectHostConfigIdMappings {
247 pub gid_map: Vec<String>,
248 pub uid_map: Vec<String>,
249}
250
251#[derive(Deserialize, Serialize)]
252#[serde(rename_all = "PascalCase")]
253pub struct ContainerInspectHostConfigLogConfig {
254 pub config: HashMap<String, String>,
255 pub path: String,
256 pub size: String,
257 pub tag: String,
258 pub r#type: String,
259}
260
261#[derive(Deserialize, Serialize)]
262#[serde(rename_all = "PascalCase")]
263pub struct ContainerInspectHostConfigRestartPolicy {
264 pub maximum_retry_count: u64,
265 pub name: String,
266}
267
268#[derive(Deserialize, Serialize)]
269#[serde(rename_all = "PascalCase")]
270pub struct ContainerInspectHostConfigUlimit {
271 pub hard: i64,
272 pub name: String,
273 pub soft: i64,
274}
275
276#[derive(Deserialize, Serialize)]
277#[serde(rename_all = "PascalCase")]
278pub struct ContainerInspectNetworkSettings {
279 #[serde(rename = "AdditionalMACAddresses")]
280 pub additional_mac_addresses: Vec<String>,
281 pub bridge: String,
282 #[serde(rename = "EndpointID")]
283 pub endpoint_id: String,
284 pub gateway: String,
285 #[serde(rename = "GlobalIPv6Address")]
286 pub global_ipv6_address: String,
287 #[serde(rename = "GlobalIPv6PrefixLen")]
288 pub global_ipb6_prefix_len: i64,
289 pub hairpin_mode: bool,
290 #[serde(rename = "IPAddress")]
291 pub ip_address: String,
292 #[serde(rename = "IPPrefixLen")]
293 pub ip_prefix_len: i64,
294 #[serde(rename = "IPv6Gateway")]
295 pub ipv6_gateway: String,
296 #[serde(rename = "LinkLocalIPv6Address")]
297 pub link_local_ipv6_address: String,
298 #[serde(rename = "LinkLocalIPv6PrefixLen")]
299 pub link_local_ipv6_prefix_len: i64,
300 pub mac_address: String,
301 pub networks: HashMap<String, ContainerInspectNetworkSettingsNetwork>,
302 pub ports: HashMap<String, Vec<InspectHostPort>>,
303 #[serde(rename = "SandboxID")]
304 pub sandbox_id: String,
305 pub sandbox_key: String,
306 pub secondary_ip_addresses: Vec<ContainerInspectNetworkSettingsSecondaryIPAddress>,
307 pub secondary_ipv6_addresses: Vec<ContainerInspectNetworkSettingsSecondaryIPAddress>,
308}
309
310#[derive(Deserialize, Serialize)]
311#[serde(rename_all = "PascalCase")]
312pub struct ContainerInspectNetworkSettingsNetwork {
313 #[serde(rename = "AdditionalMACAddresses")]
314 pub additional_mac_addresses: Vec<String>,
315 pub aliases: Vec<String>,
316 pub driver_opts: HashMap<String, String>,
317 #[serde(rename = "EndpointID")]
318 pub endpoint_id: String,
319 pub gateway: String,
320 #[serde(rename = "GlobalIPv6Address")]
321 pub global_ipv6_address: String,
322 #[serde(rename = "GlobalIPv6PrefixLen")]
323 pub global_ipv6_prefix_len: i64,
324 #[serde(rename = "IPAddress")]
325 pub ip_address: String,
326 #[serde(rename = "IPAMConfig")]
327 pub ipam_config: HashMap<String, String>,
328 #[serde(rename = "IPPrefixLen")]
329 pub ip_prefix_len: i64,
330 #[serde(rename = "IPv6Gateway")]
331 pub ipv6_gateway: String,
332 pub links: Vec<String>,
333 pub mac_address: String,
334 #[serde(rename = "NetworkID")]
335 pub network_id: String,
336 #[serde(rename = "SecondaryIPAddresses")]
337 pub secondary_ip_addresses: Vec<ContainerInspectNetworkSettingsSecondaryIPAddress>,
338 #[serde(rename = "SecondaryIPv6Addresses")]
339 pub secondary_ipv6_addresses: Vec<ContainerInspectNetworkSettingsSecondaryIPAddress>,
340}
341
342#[derive(Deserialize, Serialize)]
343#[serde(rename_all = "PascalCase")]
344pub struct ContainerInspectNetworkSettingsSecondaryIPAddress {
345 pub addr: String,
346 pub prefix_length: i64,
347}
348
349#[derive(Deserialize, Serialize)]
350#[serde(rename_all = "PascalCase")]
351pub struct ContainerInspectState {
352 pub cgroup_path: String,
353 pub checkpointed: bool,
354 pub checkpointed_at: DateTime<Utc>,
355 pub checkpoint_log: String,
356 pub checkpoint_path: String,
357 pub conmon_pid: i64,
358 pub dead: bool,
359 pub error: String,
360 pub exit_code: i32,
361 pub finished_at: DateTime<Utc>,
362 pub health: HealthCheck,
363 pub oci_version: String,
364 #[serde(rename = "OOMKilled")]
365 pub oom_killed: bool,
366 pub paused: bool,
367 pub pid: i64,
368 pub restarting: bool,
369 pub restored: bool,
370 pub restored_at: DateTime<Utc>,
371 pub restore_log: String,
372 pub running: bool,
373 pub started_at: DateTime<Utc>,
374 pub status: String,
375 pub stopped_by_user: bool,
376}