1#[cfg(feature = "chrono")]
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use std::collections::HashMap;
7
8#[derive(Clone, Debug, Serialize, Deserialize)]
9pub struct SearchResult {
10 pub description: String,
11 pub is_official: bool,
12 pub is_automated: bool,
13 pub name: String,
14 pub star_count: u64,
15}
16
17#[derive(Clone, Debug, Serialize, Deserialize)]
18#[serde(rename_all = "PascalCase")]
19pub struct Image {
20 #[cfg(feature = "chrono")]
21 #[serde(deserialize_with = "datetime_from_unix_timestamp")]
22 pub created: DateTime<Utc>,
23 #[cfg(not(feature = "chrono"))]
24 pub created: u64,
25 pub id: String,
26 pub parent_id: String,
27 pub labels: Option<HashMap<String, String>>,
28 pub repo_tags: Option<Vec<String>>,
29 pub repo_digests: Option<Vec<String>>,
30 pub virtual_size: u64,
31}
32
33#[derive(Clone, Debug, Serialize, Deserialize)]
34#[serde(rename_all = "PascalCase")]
35pub struct ImageDetails {
36 pub architecture: String,
37 pub author: String,
38 pub comment: String,
39 pub config: Config,
40 #[cfg(feature = "chrono")]
41 pub created: DateTime<Utc>,
42 #[cfg(not(feature = "chrono"))]
43 pub created: String,
44 pub docker_version: String,
45 pub id: String,
46 pub os: String,
47 pub parent: String,
48 pub size: u64,
49 pub virtual_size: u64,
50}
51
52#[derive(Clone, Debug, Serialize, Deserialize)]
53#[serde(rename_all = "PascalCase")]
54pub struct Container {
55 #[cfg(feature = "chrono")]
56 #[serde(deserialize_with = "datetime_from_unix_timestamp")]
57 pub created: DateTime<Utc>,
58 #[cfg(not(feature = "chrono"))]
59 pub created: u64,
60 pub command: String,
61 pub id: String,
62 pub image: String,
63 pub labels: HashMap<String, String>,
64 pub names: Vec<String>,
65 pub ports: Vec<Port>,
66 pub status: String,
67 pub size_rw: Option<u64>,
68 pub size_root_fs: Option<u64>,
69}
70
71#[derive(Clone, Debug, Serialize, Deserialize)]
72#[serde(rename_all = "PascalCase")]
73pub struct ContainerDetails {
74 pub app_armor_profile: String,
75 pub args: Vec<String>,
76 pub config: Config,
77 #[cfg(feature = "chrono")]
78 pub created: DateTime<Utc>,
79 #[cfg(not(feature = "chrono"))]
80 pub created: String,
81 pub driver: String,
82 pub host_config: HostConfig,
84 pub hostname_path: String,
85 pub hosts_path: String,
86 pub log_path: String,
87 pub id: String,
88 pub image: String,
89 pub mount_label: String,
90 pub name: String,
91 pub network_settings: NetworkSettings,
92 pub path: String,
93 pub process_label: String,
94 pub resolv_conf_path: String,
95 pub restart_count: u64,
96 pub state: State,
97 pub mounts: Vec<Mount>,
98}
99
100#[derive(Clone, Debug, Serialize, Deserialize)]
101#[serde(rename_all = "PascalCase")]
102pub struct Mount {
103 pub source: String,
104 pub destination: String,
105 pub mode: String,
106 #[serde(rename = "RW")]
107 pub rw: bool,
108}
109
110#[derive(Clone, Debug, Serialize, Deserialize)]
111#[serde(rename_all = "PascalCase")]
112pub struct State {
113 pub error: String,
114 pub exit_code: u64,
115 #[cfg(feature = "chrono")]
116 pub finished_at: DateTime<Utc>,
117 #[cfg(not(feature = "chrono"))]
118 pub finished_at: String,
119 #[serde(rename = "OOMKilled")]
120 pub oom_killed: bool,
121 pub paused: bool,
122 pub pid: u64,
123 pub restarting: bool,
124 pub running: bool,
125 #[cfg(feature = "chrono")]
126 pub started_at: DateTime<Utc>,
127 #[cfg(not(feature = "chrono"))]
128 pub started_at: String,
129}
130
131type PortDescription = HashMap<String, Option<Vec<HashMap<String, String>>>>;
132
133#[derive(Clone, Debug, Serialize, Deserialize)]
134#[serde(rename_all = "PascalCase")]
135pub struct NetworkSettings {
136 pub bridge: String,
137 pub gateway: String,
138 #[serde(rename = "IPAddress")]
139 pub ip_address: String,
140 #[serde(rename = "IPPrefixLen")]
141 pub ip_prefix_len: u64,
142 pub mac_address: String,
143 pub ports: Option<PortDescription>,
144 pub networks: HashMap<String, NetworkEntry>,
145}
146
147#[derive(Clone, Debug, Serialize, Deserialize)]
148#[serde(rename_all = "PascalCase")]
149pub struct NetworkEntry {
150 #[serde(rename = "NetworkID")]
151 pub network_id: String,
152 #[serde(rename = "EndpointID")]
153 pub endpoint_id: String,
154 pub gateway: String,
155 #[serde(rename = "IPAddress")]
156 pub ip_address: String,
157 #[serde(rename = "IPPrefixLen")]
158 pub ip_prefix_len: u64,
159 #[serde(rename = "IPv6Gateway")]
160 pub ipv6_gateway: String,
161 #[serde(rename = "GlobalIPv6Address")]
162 pub global_ipv6_address: String,
163 #[serde(rename = "GlobalIPv6PrefixLen")]
164 pub global_ipv6_prefix_len: u64,
165 pub mac_address: String,
166}
167
168#[derive(Clone, Debug, Serialize, Deserialize)]
169#[serde(rename_all = "PascalCase")]
170pub struct HostConfig {
171 pub cgroup_parent: Option<String>,
172 #[serde(rename = "ContainerIDFile")]
173 pub container_id_file: String,
174 pub cpu_shares: Option<u64>,
175 pub cpuset_cpus: Option<String>,
176 pub memory: Option<u64>,
177 pub memory_swap: Option<i64>,
178 pub network_mode: String,
179 pub pid_mode: Option<String>,
180 pub port_bindings: Option<HashMap<String, Vec<HashMap<String, String>>>>,
181 pub privileged: bool,
182 pub publish_all_ports: bool,
183 pub readonly_rootfs: Option<bool>, }
188
189#[derive(Clone, Debug, Serialize, Deserialize)]
190#[serde(rename_all = "PascalCase")]
191pub struct Config {
192 pub attach_stderr: bool,
193 pub attach_stdin: bool,
194 pub attach_stdout: bool,
195 pub cmd: Option<Vec<String>>,
196 pub domainname: String,
197 pub entrypoint: Option<Vec<String>>,
198 pub env: Option<Vec<String>>,
199 pub exposed_ports: Option<HashMap<String, HashMap<String, String>>>,
200 pub hostname: String,
201 pub image: String,
202 pub labels: Option<HashMap<String, String>>,
203 pub on_build: Option<Vec<String>>,
205 pub open_stdin: bool,
207 pub stdin_once: bool,
208 pub tty: bool,
209 pub user: String,
210 pub working_dir: String,
211}
212
213impl Config {
214 pub fn env(&self) -> HashMap<String, String> {
215 let mut map = HashMap::new();
216 if let Some(ref vars) = self.env {
217 for e in vars {
218 let pair: Vec<&str> = e.split('=').collect();
219 map.insert(pair[0].to_owned(), pair[1].to_owned());
220 }
221 }
222 map
223 }
224}
225
226#[derive(Clone, Debug, Serialize, Deserialize)]
227#[serde(rename_all = "PascalCase")]
228pub struct Port {
229 pub ip: Option<String>,
230 pub private_port: u64,
231 pub public_port: Option<u64>,
232 #[serde(rename = "Type")]
233 pub typ: String,
234}
235
236#[derive(Clone, Debug, Serialize, Deserialize)]
237pub struct Stats {
238 pub read: String,
239 pub networks: HashMap<String, Network>,
240 pub memory_stats: MemoryStats,
241 pub blkio_stats: BlkioStats,
242 pub cpu_stats: CpuStats,
243}
244
245#[derive(Clone, Debug, Serialize, Deserialize)]
246pub struct Network {
247 pub rx_dropped: u64,
248 pub rx_bytes: u64,
249 pub rx_errors: u64,
250 pub tx_packets: u64,
251 pub tx_dropped: u64,
252 pub rx_packets: u64,
253 pub tx_errors: u64,
254 pub tx_bytes: u64,
255}
256
257#[derive(Clone, Debug, Serialize, Deserialize)]
258#[serde(rename_all = "PascalCase")]
259pub struct IPAM {
260 pub driver: String,
261 pub config: Vec<HashMap<String, String>>,
262 pub options: Option<HashMap<String, String>>,
263}
264
265#[derive(Clone, Debug, Serialize, Deserialize)]
266#[serde(rename_all = "PascalCase")]
267pub struct NetworkDetails {
268 pub name: String,
269 pub id: String,
270 pub scope: String,
271 pub driver: String,
272 #[serde(rename = "EnableIPv6")]
273 pub enable_ipv6: bool,
274 #[serde(rename = "IPAM")]
275 pub ipam: IPAM,
276 pub internal: bool,
277 pub attachable: bool,
278 pub containers: HashMap<String, NetworkContainerDetails>,
279 pub options: Option<HashMap<String, String>>,
280 pub labels: Option<HashMap<String, String>>,
281}
282
283#[derive(Clone, Debug, Serialize, Deserialize)]
284#[serde(rename_all = "PascalCase")]
285pub struct NetworkContainerDetails {
286 pub endpoint_id: String,
287 pub mac_address: String,
288 #[serde(rename = "IPv4Address")]
289 pub ipv4_address: String,
290 #[serde(rename = "IPv6Address")]
291 pub ipv6_address: String,
292}
293
294#[derive(Clone, Debug, Serialize, Deserialize)]
295#[serde(rename_all = "PascalCase")]
296pub struct NetworkCreateInfo {
297 pub id: String,
298 pub warning: String,
299}
300
301#[derive(Clone, Debug, Serialize, Deserialize)]
302pub struct MemoryStats {
303 pub max_usage: u64,
304 pub usage: u64,
305 pub failcnt: Option<u64>,
306 pub limit: u64,
307 pub stats: MemoryStat,
308}
309
310#[derive(Clone, Debug, Serialize, Deserialize)]
311pub struct MemoryStat {
312 pub total_pgmajfault: u64,
313 pub cache: u64,
314 pub mapped_file: u64,
315 pub total_inactive_file: u64,
316 pub pgpgout: u64,
317 pub rss: u64,
318 pub total_mapped_file: u64,
319 pub writeback: u64,
320 pub unevictable: u64,
321 pub pgpgin: u64,
322 pub total_unevictable: u64,
323 pub pgmajfault: u64,
324 pub total_rss: u64,
325 pub total_rss_huge: u64,
326 pub total_writeback: u64,
327 pub total_inactive_anon: u64,
328 pub rss_huge: u64,
329 pub hierarchical_memory_limit: u64,
330 pub hierarchical_memsw_limit: u64,
331 pub total_pgfault: u64,
332 pub total_active_file: u64,
333 pub active_anon: u64,
334 pub total_active_anon: u64,
335 pub total_pgpgout: u64,
336 pub total_cache: u64,
337 pub inactive_anon: u64,
338 pub active_file: u64,
339 pub pgfault: u64,
340 pub inactive_file: u64,
341 pub total_pgpgin: u64,
342}
343
344#[derive(Clone, Debug, Serialize, Deserialize)]
345pub struct CpuStats {
346 pub cpu_usage: CpuUsage,
347 pub system_cpu_usage: u64,
348 pub throttling_data: ThrottlingData,
349}
350
351#[derive(Clone, Debug, Serialize, Deserialize)]
352pub struct CpuUsage {
353 pub percpu_usage: Vec<u64>,
354 pub usage_in_usermode: u64,
355 pub total_usage: u64,
356 pub usage_in_kernelmode: u64,
357}
358
359#[derive(Clone, Debug, Serialize, Deserialize)]
360pub struct ThrottlingData {
361 pub periods: u64,
362 pub throttled_periods: u64,
363 pub throttled_time: u64,
364}
365
366#[derive(Clone, Debug, Serialize, Deserialize)]
367pub struct BlkioStats {
368 pub io_service_bytes_recursive: Vec<BlkioStat>,
369 pub io_serviced_recursive: Vec<BlkioStat>,
370 pub io_queue_recursive: Vec<BlkioStat>,
371 pub io_service_time_recursive: Vec<BlkioStat>,
372 pub io_wait_time_recursive: Vec<BlkioStat>,
373 pub io_merged_recursive: Vec<BlkioStat>,
374 pub io_time_recursive: Vec<BlkioStat>,
375 pub sectors_recursive: Vec<BlkioStat>,
376}
377
378#[derive(Clone, Debug, Serialize, Deserialize)]
379pub struct BlkioStat {
380 pub major: u64,
381 pub minor: u64,
382 pub op: String,
383 pub value: u64,
384}
385
386#[derive(Clone, Debug, Serialize, Deserialize)]
387#[serde(rename_all = "PascalCase")]
388pub struct Change {
389 pub kind: u64,
390 pub path: String,
391}
392
393#[derive(Clone, Debug, Serialize, Deserialize)]
394#[serde(rename_all = "PascalCase")]
395pub struct Top {
396 pub titles: Vec<String>,
397 pub processes: Vec<Vec<String>>,
398}
399
400#[derive(Clone, Debug, Serialize, Deserialize)]
401#[serde(rename_all = "PascalCase")]
402pub struct Version {
403 pub api_version: String,
404 pub version: String,
405 pub git_commit: String,
406 pub go_version: String,
407}
408
409#[derive(Clone, Debug, Serialize, Deserialize)]
410#[serde(rename_all = "PascalCase")]
411pub struct Info {
412 pub containers: u64,
413 pub images: u64,
414 pub driver: String,
415 pub docker_root_dir: String,
416 pub driver_status: Vec<Vec<String>>,
417 #[serde(rename = "ID")]
418 pub id: String,
419 pub kernel_version: String,
420 pub mem_total: u64,
422 pub memory_limit: bool,
423 #[serde(rename = "NCPU")]
424 pub n_cpu: u64,
425 pub n_events_listener: u64,
426 pub n_goroutines: u64,
427 pub name: String,
428 pub operating_system: String,
429 pub swap_limit: bool,
431 pub system_time: Option<String>,
432}
433
434#[derive(Clone, Debug, Serialize, Deserialize)]
435#[serde(rename_all = "PascalCase")]
436pub struct ContainerCreateInfo {
437 pub id: String,
438 pub warnings: Option<Vec<String>>,
439}
440
441#[derive(Clone, Debug, Serialize, Deserialize)]
442#[serde(rename_all = "PascalCase")]
443pub struct History {
444 pub id: String,
445 #[cfg(feature = "chrono")]
446 #[serde(deserialize_with = "datetime_from_unix_timestamp")]
447 pub created: DateTime<Utc>,
448 #[cfg(not(feature = "chrono"))]
449 pub created: u64,
450 pub created_by: String,
451}
452
453#[derive(Clone, Debug, Serialize, Deserialize)]
454#[serde(rename_all = "PascalCase")]
455pub struct Exit {
456 pub status_code: u64,
457}
458
459#[derive(Clone, Debug, Serialize, Deserialize)]
460pub struct Event {
461 #[serde(rename = "Type")]
462 pub typ: String,
463 #[serde(rename = "Action")]
464 pub action: String,
465 #[serde(rename = "Actor")]
466 pub actor: Actor,
467 pub status: Option<String>,
468 pub id: Option<String>,
469 pub from: Option<String>,
470 #[cfg(feature = "chrono")]
471 #[serde(deserialize_with = "datetime_from_unix_timestamp")]
472 pub time: DateTime<Utc>,
473 #[cfg(not(feature = "chrono"))]
474 pub time: u64,
475 #[cfg(feature = "chrono")]
476 #[serde(deserialize_with = "datetime_from_nano_timestamp", rename = "timeNano")]
477 pub time_nano: DateTime<Utc>,
478 #[cfg(not(feature = "chrono"))]
479 #[serde(rename = "timeNano")]
480 pub time_nano: u64,
481}
482
483#[derive(Clone, Debug, Serialize, Deserialize)]
484pub struct Actor {
485 #[serde(rename = "ID")]
486 pub id: String,
487 #[serde(rename = "Attributes")]
488 pub attributes: HashMap<String, String>,
489}
490
491#[derive(Clone, Debug, Serialize, Deserialize)]
492pub enum Status {
493 Untagged(String),
494 Deleted(String),
495}
496
497#[derive(Clone, Debug, Serialize, Deserialize)]
498#[serde(rename_all = "PascalCase")]
499pub struct VolumeCreateInfo {
500 pub name: String,
501}
502
503#[derive(Clone, Debug, Serialize, Deserialize)]
504#[serde(rename_all = "PascalCase")]
505pub struct Volumes {
506 pub volumes: Option<Vec<Volume>>,
507 pub warnings: Option<Vec<String>>,
508}
509
510#[derive(Clone, Debug, Serialize, Deserialize)]
511#[serde(rename_all = "PascalCase")]
512pub struct Volume {
513 #[cfg(feature = "chrono")]
514 pub created_at: DateTime<Utc>,
515 #[cfg(not(feature = "chrono"))]
516 pub created_at: String,
517 pub driver: String,
518 pub labels: Option<HashMap<String, String>>,
519 pub name: String,
520 pub mountpoint: String,
521 pub options: Option<HashMap<String, String>>,
522 pub scope: String,
523}
524
525#[cfg(feature = "chrono")]
526fn datetime_from_unix_timestamp<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
527where
528 D: serde::Deserializer<'de>,
529{
530 let timestamp = chrono::NaiveDateTime::from_timestamp(i64::deserialize(deserializer)?, 0);
531 Ok(DateTime::<Utc>::from_utc(timestamp, Utc))
532}
533
534#[cfg(feature = "chrono")]
535fn datetime_from_nano_timestamp<'de, D>(deserializer: D) -> Result<DateTime<Utc>, D::Error>
536where
537 D: serde::Deserializer<'de>,
538{
539 let timestamp_nano = u64::deserialize(deserializer)?;
540 let timestamp = chrono::NaiveDateTime::from_timestamp(
541 (timestamp_nano / 1_000_000_000) as i64,
542 (timestamp_nano % 1_000_000_000) as u32,
543 );
544 Ok(DateTime::<Utc>::from_utc(timestamp, Utc))
545}