Skip to main content

podman_api/opts/
containers.rs

1use crate::models;
2use crate::opts::ImageOpt;
3use containers_api::opts::{Filter, FilterItem};
4use containers_api::{
5    impl_field, impl_filter_func, impl_map_field, impl_opts_builder, impl_str_enum_field,
6    impl_str_field, impl_url_bool_field, impl_url_field, impl_url_str_field, impl_url_vec_field,
7    impl_vec_field,
8};
9use std::fmt;
10
11impl_opts_builder!(url =>
12    /// Adjust the list of returned containers with this options.
13    ContainerList
14);
15
16#[derive(Debug)]
17/// Used to filter listed containers by one of the variants.
18pub enum ContainerListFilter {
19    /// Images that are ancestors.
20    Ancestor(ImageOpt),
21    /// Container ID or name
22    Before(String),
23    /// <port>[/<proto>] or <startport-endport>/[<proto>]
24    Expose(String),
25    /// Containers with exit code of
26    Exited(i32),
27    Health(models::ContainerHealth),
28    /// A container's ID
29    Id(crate::Id),
30    IsTask(bool),
31    /// Container with key label.
32    LabelKey(String),
33    /// Container with key-value label.
34    LabelKeyVal(String, String),
35    /// Container without key label.
36    NoLabelKey(String),
37    /// Container without key-value label.
38    NoLabelKeyVal(String, String),
39    /// A container's name
40    Name(String),
41    /// Network ID or name
42    Network(String),
43    /// Pod ID or name
44    Pod(String),
45    /// <port>[/<proto>] or <startport-endport>/[<proto>]
46    Publish(String),
47    /// Container ID or name
48    Since(String),
49    Status(models::ContainerStatus),
50    /// Volume name or mount point destination
51    Volume(String),
52}
53
54impl Filter for ContainerListFilter {
55    fn query_item(&self) -> FilterItem {
56        use ContainerListFilter::*;
57        match &self {
58            Ancestor(ancestor) => FilterItem::new("ancestor", ancestor.to_string()),
59            Before(container) => FilterItem::new("before", container.clone()),
60            Expose(port) => FilterItem::new("expose", port.clone()),
61            Exited(code) => FilterItem::new("exited", code.to_string()),
62            Health(health) => FilterItem::new("health", health.as_ref().to_string()),
63            Id(id) => FilterItem::new("id", id.to_string()),
64            IsTask(is_task) => FilterItem::new("is-task", is_task.to_string()),
65            LabelKey(key) => FilterItem::new("label", key.clone()),
66            LabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
67            NoLabelKey(key) => FilterItem::new("label!", key.clone()),
68            NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{key}={val}",)),
69            Name(name) => FilterItem::new("name", name.clone()),
70            Network(net) => FilterItem::new("network", net.clone()),
71            Pod(pod) => FilterItem::new("pod", pod.clone()),
72            Publish(port) => FilterItem::new("publish", port.clone()),
73            Since(container) => FilterItem::new("since", container.clone()),
74            Status(status) => FilterItem::new("status", status.as_ref().to_string()),
75            Volume(vol) => FilterItem::new("volume", vol.clone()),
76        }
77    }
78}
79
80impl ContainerListOptsBuilder {
81    impl_url_bool_field!(
82        /// Return all containers. By default, only running containers are shown
83        all => "all"
84    );
85
86    impl_url_field!(
87        /// Return this number of most recently created containers, including non-running ones.
88        limit: usize => "limit"
89    );
90
91    impl_url_bool_field!(
92        /// Return the size of container as fields `size_rw` and `size_root_fs`.
93        size => "size"
94    );
95
96    impl_url_bool_field!(
97        /// Sync container state with OCI runtime
98        sync => "sync"
99    );
100
101    impl_filter_func!(ContainerListFilter);
102}
103
104impl_opts_builder!(url =>
105    /// Adjust the way a container is stopped.
106    ContainerStop
107);
108
109impl ContainerStopOptsBuilder {
110    impl_url_bool_field!(
111        /// Stop all containers
112        all => "all"
113    );
114
115    impl_url_bool_field!(
116        /// Do not return error if container is already stopped
117        ignore => "Ignore"
118    );
119
120    impl_url_field!(
121        /// number of seconds to wait before killing container
122        timeout: usize => "Timeout"
123    );
124}
125
126impl_opts_builder!(url =>
127    /// Adjust the way a container is deleted.
128    ContainerDelete
129);
130
131impl ContainerDeleteOptsBuilder {
132    impl_url_bool_field!(
133        /// Force delete the container.
134        force => "force"
135    );
136
137    impl_url_bool_field!(
138        /// Delete associated volumes.
139        volumes => "v"
140    );
141
142    impl_url_field!(
143        /// Delete associated volumes.
144        timeout: usize => "timeout"
145    );
146}
147
148impl_opts_builder!(url =>
149    /// Adjust the way a container is checkpointed.
150    ContainerCheckpoint
151);
152
153impl ContainerCheckpointOpts {
154    pub(crate) fn for_export(&self) -> Self {
155        let mut new = self.clone();
156        new.params.insert("export", true.to_string());
157        new
158    }
159}
160
161impl ContainerCheckpointOptsBuilder {
162    impl_url_bool_field!(
163        /// Export the checkpoint image to a tar.gz
164        export => "export"
165    );
166
167    impl_url_bool_field!(
168        /// Checkpoint a container with filelocks`
169        file_locks => "fileLocks"
170    );
171
172    impl_url_bool_field!(
173        /// Do not include root file-system changes when exporting
174        ignore_root_fs => "ignoreRootFS"
175    );
176
177    impl_url_bool_field!(
178        /// Do not include associated volumes. can only be used with export
179        ignore_volumes => "ignoreVolumes"
180    );
181
182    impl_url_bool_field!(
183        /// Keep all temporary checkpoint files
184        keep => "keep"
185    );
186
187    impl_url_bool_field!(
188        /// Leave the container running after writing checkpoint to disk
189        leave_running => "leaveRunning"
190    );
191
192    impl_url_bool_field!(
193        /// Dump the container's memory information only, leaving the container running. only works on runc 1.0-rc or higher
194        pre_checkpoint => "preCheckpoint"
195    );
196
197    impl_url_bool_field!(
198        /// Add checkpoint statistics to the returned CheckpointReport
199        print_stats => "printStats"
200    );
201
202    impl_url_bool_field!(
203        /// Checkpoint a container with established TCP connections
204        tcp_established => "tcpEstablished"
205    );
206
207    impl_url_bool_field!(
208        /// Check out the container with previous criu image files in pre-dump. only works on runc 1.0-rc or higher
209        with_previous => "withPrevious"
210    );
211}
212
213impl_opts_builder!(url =>
214    /// Adjust the way a new image is created from a container.
215    ContainerCommit
216);
217
218impl ContainerCommitOpts {
219    pub(crate) fn for_container(&self, container: crate::Id) -> Self {
220        let mut new = self.clone();
221        new.params.insert("container", container.to_string());
222        new
223    }
224}
225
226impl ContainerCommitOptsBuilder {
227    impl_url_str_field!(
228        /// Author of the image
229        author => "author"
230    );
231
232    impl_url_vec_field!(
233        /// Instructions to apply while committing in Dockerfile format (i.e. "CMD=/bin/foo")
234        changes => "changes"
235    );
236
237    impl_url_str_field!(
238        /// Commit message
239        comment => "comment"
240    );
241
242    impl_url_str_field!(
243        /// Format of the image manifest and metadata (default "oci")
244        format => "format"
245    );
246
247    impl_url_bool_field!(
248        /// Pause the container before committing it
249        pause => "pause"
250    );
251
252    impl_url_str_field!(
253        /// The repository name for the created image
254        repo => "repo"
255    );
256
257    impl_url_str_field!(
258        /// Tag name for the created image
259        tag => "tag"
260    );
261}
262
263impl_opts_builder!(url =>
264    /// Adjust how to wait for a container.
265    ContainerWait
266);
267
268impl ContainerWaitOptsBuilder {
269    pub fn conditions(
270        mut self,
271        conditions: impl IntoIterator<Item = models::ContainerStatus>,
272    ) -> Self {
273        self.vec_params.insert(
274            "condition",
275            conditions.into_iter().map(|c| c.as_ref().into()).collect(),
276        );
277        self
278    }
279
280    impl_url_str_field!(
281        /// Time Interval to wait before polling for completion. Example: `250ms`, `2s`
282        interval => "interval"
283    );
284}
285
286impl_opts_builder!(json =>
287    /// Adjust the created container.
288    ContainerCreate
289);
290
291#[derive(Debug, Clone, Copy, PartialEq, Eq)]
292/// Mode used to configure image volume with
293/// [`image_volume_mode`](ContainerCreateOptsBuilder::image_volume_mode).
294#[derive(Default)]
295pub enum ImageVolumeMode {
296    /// Do not create
297    Ignore,
298    /// Create a tmpfs
299    Tmpfs,
300    /// Create as anonymous volumes
301    #[default]
302    Anonymous,
303}
304
305impl AsRef<str> for ImageVolumeMode {
306    fn as_ref(&self) -> &str {
307        match self {
308            ImageVolumeMode::Ignore => "ignore",
309            ImageVolumeMode::Tmpfs => "tmpfs",
310            ImageVolumeMode::Anonymous => "anonymous",
311        }
312    }
313}
314
315impl fmt::Display for ImageVolumeMode {
316    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
317        write!(f, "{}", self.as_ref())
318    }
319}
320
321#[derive(Debug, Clone, Copy, PartialEq, Eq)]
322/// How to handle the `NOTIFY_SOCKET`. Used with
323/// [`sdnotify_mode`](ContainerCreateOptsBuilder::sdnotify_mode).
324pub enum SocketNotifyMode {
325    /// Let the OCI runtime deal with it, advertise conmon's MAINPID.
326    Container,
327    /// Advertise conmon's MAINPID, send READY when started, don't pass to OCI.
328    Conmon,
329    /// Unset `NOTIFY_SOCKET`
330    Ignore,
331}
332
333impl AsRef<str> for SocketNotifyMode {
334    fn as_ref(&self) -> &str {
335        match self {
336            SocketNotifyMode::Container => "container",
337            SocketNotifyMode::Conmon => "conmon",
338            SocketNotifyMode::Ignore => "ignore",
339        }
340    }
341}
342
343impl fmt::Display for SocketNotifyMode {
344    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
345        write!(f, "{}", self.as_ref())
346    }
347}
348
349#[derive(Debug, Clone, Copy, PartialEq, Eq)]
350/// Used with [`ContainerCreateOptsBuilder::seccomp_policy`](ContainerCreateOptsBuilder::seccomp_policy).
351#[derive(Default)]
352pub enum SeccompPolicy {
353    Empty,
354    #[default]
355    Default,
356    Image,
357}
358
359impl AsRef<str> for SeccompPolicy {
360    fn as_ref(&self) -> &str {
361        match self {
362            SeccompPolicy::Empty => "empty",
363            SeccompPolicy::Default => "default",
364            SeccompPolicy::Image => "image",
365        }
366    }
367}
368
369impl fmt::Display for SeccompPolicy {
370    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
371        write!(f, "{}", self.as_ref())
372    }
373}
374
375#[derive(Debug, Clone, Copy, PartialEq, Eq)]
376/// Used with [`ContainerCreateOptsBuilder::systemd`](ContainerCreateOptsBuilder::systemd).
377#[derive(Default)]
378pub enum SystemdEnabled {
379    True,
380    #[default]
381    False,
382    Always,
383}
384
385impl AsRef<str> for SystemdEnabled {
386    fn as_ref(&self) -> &str {
387        match self {
388            SystemdEnabled::True => "true",
389            SystemdEnabled::False => "false",
390            SystemdEnabled::Always => "always",
391        }
392    }
393}
394
395impl fmt::Display for SystemdEnabled {
396    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
397        write!(f, "{}", self.as_ref())
398    }
399}
400
401#[derive(Debug, Clone, Copy, PartialEq, Eq)]
402/// Used with
403/// [`ContainerCreateOptsBuilder::restart_policy`](ContainerCreateOptsBuilder::restart_policy).
404#[derive(Default)]
405pub enum ContainerRestartPolicy {
406    Always,
407    #[default]
408    No,
409    OnFailure,
410    UnlessStopped,
411}
412
413impl AsRef<str> for ContainerRestartPolicy {
414    fn as_ref(&self) -> &str {
415        match self {
416            ContainerRestartPolicy::Always => "always",
417            ContainerRestartPolicy::No => "no",
418            ContainerRestartPolicy::OnFailure => "on-failure",
419            ContainerRestartPolicy::UnlessStopped => "unless-stopped",
420        }
421    }
422}
423
424impl fmt::Display for ContainerRestartPolicy {
425    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
426        write!(f, "{}", self.as_ref())
427    }
428}
429
430impl ContainerCreateOptsBuilder {
431    impl_map_field!(json
432        /// Annotations are key-value options passed into the container runtime that can be used to
433        /// trigger special behavior.
434        annotations => "annotations"
435    );
436
437    impl_str_field!(
438        /// ApparmorProfile is the name of the Apparmor profile the container will use.
439        apparmor_profile => "apparmor_profile"
440    );
441
442    impl_vec_field!(
443        /// Capabilities which will be added to the container. Conflicts with
444        /// [`privileged`](ContainerCreateOptsBuilder::privileged).
445        add_capabilities => "cap_add"
446    );
447
448    impl_vec_field!(
449        /// Capabilities which will be removed from the container. Conflicts with
450        /// [`privileged`](ContainerCreateOptsBuilder::privileged).
451        drop_capabilities => "cap_drop"
452    );
453
454    impl_str_field!(
455        /// Set the container's CGroup parent. If not set, the default for the current cgroup driver
456        /// will be used.
457        cgroup_parent => "cgroup_parent"
458    );
459
460    impl_field!(
461        /// Namespace to use for cgroups.
462        cgroup_namespace: models::Namespace => "cgroupns"
463    );
464
465    impl_str_field!(
466        /// Sets a policy for how cgroups will be created in the container, including the ability
467        /// to disable creation entirely.
468        cgroup_mode => "cgroups_mode"
469    );
470
471    impl_vec_field!(
472        /// Additional set of directories that need to be treated as root directories.
473        /// Standard bind mounts will be mounted into paths relative to these directories.
474        chroot_directories => "chroot_directories"
475    );
476
477    impl_vec_field!(
478        /// Command that the container should run. If not given and Image is specified, this will
479        /// be populated by the image's configuration.
480        command => "command"
481    );
482
483    impl_str_field!(
484        /// A path at which a PID file for Conmon will be placed. If not given, a default location
485        /// will be used.
486        common_pid_file => "common_pid_file"
487    );
488
489    impl_vec_field!(
490        /// The command that was used to create this container. This will be returned when
491        /// inspecting the container.
492        create_command => "containerCreateCommand"
493    );
494
495    impl_field!(
496        /// CPU period of the cpuset
497        cpu_period: u64 => "cpu_period"
498    );
499
500    impl_field!(
501        /// CPU quota of the cpuset
502        cpu_quota: i64 => "cpu_quota"
503    );
504
505    impl_field!(
506        /// Create the working directory if it doesn't exist. If unset, it doesn't create it.
507        create_working_dir: bool => "create_working_dir"
508    );
509
510    impl_vec_field!(
511        /// An array of containers this container depends on. Dependency containers must be started
512        /// before this container. Dependencies can be specified by name or full/partial ID.
513        dependency_containers => "dependencyContainers"
514    );
515
516    impl_vec_field!(
517        /// DeviceCgroupRule are device cgroup rules that allow containers to use additional types of devices.
518        device_cgroup_rule : models::LinuxDeviceCgroup => "device_cgroup_rule"
519    );
520
521    impl_vec_field!(
522        /// Devices are devices that will be added to the container.
523        devices : models::LinuxDevice => "devices"
524    );
525
526    impl_vec_field!(
527        /// A way to ensure your container inherits device specific information from another container.
528        devices_from => "device_from"
529    );
530
531    impl_vec_field!(
532        /// A set of DNS options that will be used in the container's resolv.conf, replacing the host's
533        /// DNS options which are used by default. Conflicts with
534        /// [`use_image_resolve_conf`](ContainerCreateOptsBuilder::use_image_resolve_conf).
535        dns_option => "dns_option"
536    );
537
538    impl_vec_field!(
539        /// A set of DNS search domains that will be used in the container's resolv.conf, replacing
540        /// the host's DNS search domains which are used by default. Conflicts with
541        /// [`use_image_resolve_conf`](ContainerCreateOptsBuilder::use_image_resolve_conf).
542        dns_search => "dns_search"
543    );
544
545    impl_vec_field!(
546        /// A set of DNS servers that will be used in the container's resolv.conf, replacing the
547        /// host's DNS Servers which are used by default. Conflicts with
548        /// [`use_image_resolve_conf`](ContainerCreateOptsBuilder::use_image_resolve_conf).
549        dns_server => "dns_server"
550    );
551
552    impl_vec_field!(
553        /// Container's entrypoint. If not given and Image is specified, this will be populated by
554        /// the image's configuration.
555        entrypoint => "entrypoint"
556    );
557
558    impl_map_field!(json
559        /// A list of environment variables that will be set in the container.
560        env => "env"
561    );
562
563    impl_field!(
564        /// Indicates that the host environment should be added to container.
565        env_host: bool => "env_host"
566    );
567
568    impl_vec_field!(
569        /// Takes the specified environment variables from image and preprocess them before injecting them into the container.
570        envmerge => "envmerge"
571    );
572
573    impl_vec_field!(
574        /// Groups are a list of supplemental groups the container's user will be granted access to.
575        groups => "groups"
576    );
577
578    impl_field!(
579        /// Defines how Podman reacts when a container's health status turns unhealthy.
580        health_check_on_failure_action: i64 => "health_check_on_failure_action"
581    );
582
583    impl_field!(
584        /// Health config which holds configuration settings for the HEALTHCHECK feature, from
585        /// docker/docker/api/types/container.
586        health_config: models::Schema2HealthConfig => "healthconfig"
587    );
588
589    impl_vec_field!(
590        /// The bits have the same definition on all systems, so that information about files can be moved from one system to another portably.
591        /// Not all bits apply to all systems. The only required bit is ModeDir for directories.
592        host_device_list : models::LinuxDevice => "host_device_list"
593    );
594
595    impl_vec_field!(
596        /// A set of hosts which will be added to the container's etc/hosts file. Conflicts with
597        /// [`use_image_hosts`](ContainerCreateOptsBuilder::use_image_hosts).
598        hosts_add => "hostadd"
599    );
600
601    impl_str_field!(
602        /// If not set, the hostname will not be modified (if UtsNS is not private) or will be set
603        /// to the container ID (if UtsNS is private). Conflicts with UtsNS if UtsNS is not set to
604        /// private.
605        hostname => "hostname"
606    );
607
608    impl_vec_field!(
609        /// List of host usernames or UIDs to add to the container etc/passwd file.
610        hostusers => "hostusers"
611    );
612
613    impl_field!(
614        /// Indicates that the http host proxy environment variables should be added to container.
615        http_proxy: bool => "httpproxy"
616    );
617
618    impl_field!(
619        /// Used for specifying how ID mapping should be set up for a layer or container.
620        id_mappings: models::IdMappingOptions => "idmappings"
621    );
622
623    impl_str_field!(
624        /// Image is the image the container will be based on. The image will be used as the
625        /// container's root filesystem, and its environment vars, volumes, and other configuration
626        /// will be applied to the container. Conflicts with [`rootfs`](ContainerCreateOptsBuilder::rootfs).
627        ///
628        /// At least one of [`image`](ContainerCreateOptsBuilder::image) or
629        /// [`rootfs`](ContainerCreateOptsBuilder::rootfs) must be specified.
630        image => "image"
631    );
632
633    impl_str_field!(
634        /// User-specified image architecture
635        image_arch => "image_arch"
636    );
637
638    impl_str_field!(
639        /// User-specified image OS
640        image_os => "image_os"
641    );
642
643    impl_str_field!(
644        /// User-specified image variant
645        image_variant => "image_variant"
646    );
647
648    impl_str_enum_field!(
649        /// Indicates how image volumes will be created. The default if unset is
650        /// [`anonymous`](ImageVolumeMode::Anonymous).
651        image_volume_mode: ImageVolumeMode => "image_volume_mode"
652    );
653
654    impl_vec_field!(
655        /// Image volumes bind-mount a container-image mount into the container.
656        image_volumes : models::ImageVolume => "image_volumes"
657    );
658
659    impl_field!(
660        /// Specifies that an init binary will be mounted into the container, and will be used as
661        /// PID1.
662        init: bool => "init"
663    );
664
665    impl_str_field!(
666        /// Describes if this container is an init container and if so, what type: always or once.
667        init_container_type => "init_container_type"
668    );
669
670    impl_str_field!(
671        /// Specifies the path to the init binary that will be added if
672        /// [`init`](ContainerCreateOptsBuilder::init) is specified above. If not specified, the
673        /// default set in the Libpod config will be used. Ignored if
674        /// [`init`](ContainerCreateOptsBuilder::init) is not set.
675        init_path => "init_path"
676    );
677
678    impl_field!(
679        /// Namespace to use for IPC.
680        ipc_namespace: models::Namespace => "ipcns"
681    );
682
683    impl_map_field!(json
684        /// A list of labels that will be assigned to the container.
685        labels => "labels"
686    );
687
688    impl_field!(
689        /// Logging configuration for the container.
690        log_configuration: models::LogConfig => "log_configuration"
691    );
692
693    impl_field!(
694        /// Container run option that determines if we are validating users/groups before
695        /// running the container.
696        manage_password: bool => "manage_password"
697    );
698
699    impl_vec_field!(
700        /// The path we want to mask in the container. This masks the paths given in addition to
701        /// the default list.
702        mask => "mask"
703    );
704
705    impl_vec_field!(
706        /// Mounts that will be added to the container. These will supersede
707        /// [`image_volumes`](ContainerCreateOptsBuilder::image_volumes) and
708        /// [`volumes_from`](ContainerCreateOptsBuilder::volumes_from) volumes where there
709        /// are conflicts.
710        mounts: models::ContainerMount => "mounts"
711    );
712
713    impl_str_field!(
714        /// The name the container will be given. If no name is provided, one will be randomly
715        /// generated.
716        name => "name"
717    );
718
719    impl_str_field!(
720        /// The libpod namespace the container will be placed in.
721        namespace => "namespace"
722    );
723
724    impl_field!(
725        /// Namespace to use for network.
726        net_namespace: models::Namespace => "netns"
727    );
728
729    impl_map_field!(json
730        /// Additional options for each network.
731        network_options => "network_options"
732    );
733
734    impl_map_field!(json
735        /// Map of networks names or ids that the container should join.
736        /// You can request additional settings for each network, you can set network aliases,
737        /// static ips, static mac address and the network interface name for this container on the specific network.
738        /// If the map is empty and the bridge network mode is set the container will be joined to the default network.
739        networks => "Networks"
740    );
741
742    impl_field!(
743        /// Whether the container will set the no new privileges flag on create, which disables
744        /// gaining additional privileges (e.g. via setuid) in the container.
745        no_new_privilages: bool => "no_new_privilages"
746    );
747
748    impl_str_field!(
749        /// The name of the OCI runtime that will be used to create the container. If not
750        /// specified, the default will be used.
751        oci_runtime => "oci_runtime"
752    );
753
754    impl_field!(
755        /// Adjusts the score used by the OOM killer to determine processes to kill for the container's process.
756        oom_score_adj: i64 => "oom_score_adj"
757    );
758
759    impl_vec_field!(
760        /// Overlay volumes are named volumes that will be added to the container.
761        overlay_volumes : models::OverlayVolume => "overlay_volumes"
762    );
763
764    impl_str_field!(
765        /// Specifies arbitrary data to append to a file.
766        passwd_entry => "passwd_entry"
767    );
768
769    impl_field!(
770        /// Specify the Linux personality syscall input.
771        personality: models::LinuxPersonality => "personality"
772    );
773
774    impl_field!(
775        /// Namespace to use for pids.
776        pid_namespace: models::Namespace => "pidns"
777    );
778
779    impl_str_field!(
780        /// ID of the pod the container should join.
781        pod => "pod"
782    );
783
784    impl_vec_field!(
785        /// Set of ports to map into the container. Only available if NetNS is set to bridge or
786        /// slirp.
787        portmappings: models::PortMapping => "portmappings"
788    );
789
790    impl_field!(
791        /// Whether the container is privileged. Privileged does the following: Adds all devices on
792        /// the system to the container. Adds all capabilities to the container. Disables Seccomp,
793        /// SELinux, and Apparmor confinement. (Though SELinux can be manually re-enabled).
794        privileged: bool => "privileged"
795    );
796
797    impl_vec_field!(
798        /// The options used for the proc mount.
799        procfs_opts => "procfs_opts"
800    );
801
802    impl_field!(
803        /// If set to true the ports specified in the image will be published to random unused ports
804        /// (guaranteed to be above 1024) on the host. This is based on ports set in Expose below,
805        /// and any ports specified by the Image (if one is given). Only available if
806        /// [`net_namespace`](ContainerCreateOptsBuilder::net_namespace) is set to Bridge or Slirp.
807        publish_image_ports: bool => "publish_image_ports"
808    );
809
810    impl_vec_field!(
811        /// Rlimits are POSIX rlimits to apply to the container. Optional.
812        r_limits : models::PosixRlimit => "r_limits"
813    );
814
815    impl_str_field!(
816        /// The user-specified and unprocessed input referring to a local or a remote image.
817        raw_image_name => "raw_image_name"
818    );
819
820    impl_field!(
821        /// If set to true everything will be mounted as read-only.
822        read_only_fs: bool => "read_only_filesystem"
823    );
824
825    impl_field!(
826        /// If set to true the container will be removed upon exitting.
827        remove: bool => "remove"
828    );
829
830    impl_field!(
831        /// Set the container runtime resource contstraints.
832        resource_limits: models::LinuxResources => "resource_limits"
833    );
834
835    impl_str_enum_field!(
836        /// An action which will be taken when the container exits. If not given, the default
837        /// policy, which does nothing, will be used.
838        restart_policy: ContainerRestartPolicy => "restart_policy"
839    );
840
841    impl_field!(
842        /// The number of attempts that will be made to restart the container. Only available
843        /// when [`restart_policy`](ContainerCreateOptsBuilder::restart_policy) is set to `on-failure`.
844        restart_tries: u64 => "restart_tries"
845    );
846
847    impl_str_field!(
848        /// The path to a directory that will be used as the container's root filesystem. No
849        /// modification will be made to the directory, it will be directly mounted into the
850        /// container as root. Conflicts with [`image`](ContainerCreateOptsBuilder::image).
851        ///
852        /// At least one of [`image`](ContainerCreateOptsBuilder::image) or
853        /// [`rootfs`](ContainerCreateOptsBuilder::rootfs) must be specified.
854        rootfs => "rootfs"
855    );
856
857    impl_field!(
858        /// Tells if rootfs is actuall an overlay on top of base path.
859        rootfs_overlay: bool => "rootfs_overlay"
860    );
861
862    impl_str_field!(
863        /// The rootfs propagation mode for the container. If not set, the default of rslave will
864        /// be used.
865        rootfs_propagation => "rootfs_propagation"
866    );
867
868    impl_str_enum_field!(
869        /// Determine how to handle `NOTIFY_SOCKET`.
870        sdnotify_mode: SocketNotifyMode => "sdnotifyMode"
871    );
872
873    impl_str_enum_field!(
874        /// Determines which seccomp profile gets applied the container.
875        seccomp_policy: SeccompPolicy => "seccomp_policy"
876    );
877
878    impl_str_field!(
879        /// The path to a JSON file containing the container's Seccomp profile. If not specified,
880        /// no Seccomp profile will be used.
881        seccomp_profile_path => "seccomp_profile_path"
882    );
883
884    impl_map_field!(json
885        /// A list of secrets that will be set as environment variables.
886        secret_env => "secret_env"
887    );
888
889    impl_vec_field!(
890        /// Secrets are the secrets that will be added to the container.
891        secrets :models::Secret => "secrets"
892    );
893
894    impl_vec_field!(
895        /// The process label the container will use. if SELinux is enabled and this is not
896        /// specified, a label will be automatically generated if not specified.
897        selinux_opts => "selinux_opts"
898    );
899
900    impl_field!(
901        /// The size of the tmpfs to mount in at /dev/shm, in bytes.
902        shm_size: i64 => "shm_size"
903    );
904
905    impl_field!(
906        /// Whether the container should keep it's STDIN open.
907        stdin: bool => "stdin"
908    );
909
910    impl_field!(
911        /// A number describing a process signal.
912        stop_signal: i64 => "stop_signal"
913    );
914
915    impl_field!(
916        /// A timeout between the container's stop signal being sent and SIGKILL being sent. If not
917        /// provided, the default will be used. If 0 is used, stop signal will not be sent, and
918        /// SIGKILL will be sent instead.
919        stop_timeout: u64 => "stop_timeout"
920    );
921
922    impl_map_field!(json
923        /// A list of container's storage options.
924        storage_opts => "storage_opts"
925    );
926
927    impl_map_field!(json
928        /// A list of kernel parameters to set in the container.
929        sysctl => "sysctl"
930    );
931
932    impl_str_enum_field!(
933        systemd: SystemdEnabled => "systemd"
934    );
935
936    impl_field!(
937        /// Whether the container will create a PTY.
938        terminal: bool => "terminal"
939    );
940
941    impl_map_field!(json
942        /// IO read rate limit per cgroup per device, bytes per second
943        throttle_read_bps_device => "throttleReadBpsDevice"
944    );
945
946    impl_map_field!(json
947        ///IO read rate limit per cgroup per device, IO per second
948        throttle_read_iops_device => "throttleReadIOPSDevice"
949    );
950
951    impl_map_field!(json
952        /// IO write rate limit per cgroup per device, bytes per second
953        throttle_write_bps_device => "throttleWriteBpsDevice"
954    );
955
956    impl_map_field!(json
957        /// IO write rate limit per cgroup per device, IO per second
958        throttle_write_iops_device => "throttleWriteIOPSDevice"
959    );
960
961    impl_field!(
962        /// A maximum time in seconds the container will run before main process is sent SIGKILL.
963        /// If 0 is used, signal will not be sent.
964        timeout: u64 => "timeout"
965    );
966
967    impl_str_field!(
968        /// The timezone inside the container. Local means it has the same timezone as the host
969        /// machine.
970        timezone => "timezone"
971    );
972
973    impl_str_field!(
974        /// The umask the init process of the container will be run with.
975        umask => "umask"
976    );
977
978    impl_map_field!(json
979        /// A list of key-value options passed into the container runtime that are used to
980        /// configure cgroup v2.
981        unified => "unified"
982    );
983
984    impl_vec_field!(
985        /// The path we want to unmask in the container. To override all the default paths that are
986        /// masked, set unmask=ALL.
987        unmask => "unmask"
988    );
989
990    impl_vec_field!(
991        /// A list of environment variables to unset if specified in the image or from buildin or
992        /// containers.conf
993        unset_env => "unsetenv"
994    );
995
996    impl_field!(
997        /// If true all environment variables from the image or from buldin or containers.conf will
998        /// get unset.
999        unset_env_all: bool => "unsetenvall"
1000    );
1001
1002    impl_field!(
1003        /// Indicates that /etc/hosts should not be managed by Podman, and instead sourced from the image.
1004        /// Conflicts with [`hosts_add`](ContainerCreateOptsBuilder::hosts_add).
1005        use_image_hosts: bool => "use_image_hosts"
1006    );
1007
1008    impl_field!(
1009        /// Indicates that /etc/hosts should not be managed by Podman, and instead sourced from the image.
1010        /// Conflicts with [`dns_server`](ContainerCreateOptsBuilder::dns_server),
1011        /// [`dns_search`](ContainerCreateOptsBuilder::dns_search),
1012        /// [`dns_option`](ContainerCreateOptsBuilder::dns_option).
1013        use_image_resolve_conf: bool => "use_image_resolve_conf"
1014    );
1015
1016    impl_str_field!(
1017        /// The user the container will be run as. Can be given as a UID or a username; if a username,
1018        /// it will be resolved within the container, using the container's /etc/passwd. If unset, the
1019        /// container will be run as root.
1020        user => "user"
1021    );
1022
1023    impl_field!(
1024        /// Namespace to use for users.
1025        user_namespace: models::Namespace => "userns"
1026    );
1027
1028    impl_field!(
1029        /// Namespace to use for uts.
1030        uts_namespace: models::Namespace => "utsns"
1031    );
1032
1033    impl_field!(
1034        /// Specifies whether the container storage can be optimized at the cost of not syncing all
1035        /// the dirty files in memory.
1036        volatile: bool => "volatile"
1037    );
1038
1039    impl_vec_field!(
1040        /// Specifies the container volume to use with this container.
1041        volumes: models::NamedVolume => "volumes"
1042    );
1043
1044    impl_vec_field!(
1045        /// Set of containers whose volumes will be added to this container. The name or ID of the
1046        /// container must be provided, and may optionally be followed by a : and then one or more
1047        /// comma-separated options. Valid options are 'ro', 'rw', and 'z'. Options will be used
1048        /// for all volumes sourced from the container.
1049        volumes_from => "volumes_from"
1050    );
1051
1052    impl_field!(
1053        /// Weight per cgroup per device.
1054        weight_device: models::LinuxWeightDevice => "weightDevice"
1055    );
1056
1057    impl_str_field!(
1058        /// Override the container's working directory. If unset, the default, `/`, will be used.
1059        work_dir => "work_dir"
1060    );
1061}
1062
1063impl_opts_builder!(url =>
1064    /// Adjust how to attach to a running container.
1065    ContainerAttach
1066);
1067
1068impl ContainerAttachOpts {
1069    pub(crate) fn stream(&self) -> Self {
1070        let mut new = self.clone();
1071        new.params.insert("stream", true.to_string());
1072        new
1073    }
1074}
1075
1076impl ContainerAttachOptsBuilder {
1077    impl_url_str_field!(
1078        /// Keys to use for detaching from the container.
1079        detach_keys => "detachKeys"
1080    );
1081
1082    impl_url_bool_field!(
1083        /// Attach to container STDERR
1084        stderr => "stderr"
1085    );
1086
1087    impl_url_bool_field!(
1088        /// Attach to container STDIN
1089        stdin => "stdin"
1090    );
1091
1092    impl_url_bool_field!(
1093        /// Attach to container STDOUT
1094        stdout => "stdout"
1095    );
1096}
1097
1098impl_opts_builder!(url =>
1099    /// Adjust how to attach to a running container.
1100    ContainerLogs
1101);
1102
1103impl ContainerLogsOptsBuilder {
1104    impl_url_bool_field!(
1105        /// Keep connection after returning logs.
1106        follow => "follow"
1107    );
1108
1109    impl_url_str_field!(
1110        /// Only return logs since this time, as a UNIX timestamp.
1111        since => "since"
1112    );
1113
1114    impl_url_bool_field!(
1115        /// Return logs from STDERR.
1116        stderr => "stderr"
1117    );
1118
1119    impl_url_bool_field!(
1120        /// Return logs from STDOUT.
1121        stdout => "stdout"
1122    );
1123
1124    impl_url_str_field!(
1125        /// Only return this number of log lines from the end of the logs. Default - `all`
1126        tail => "tail"
1127    );
1128
1129    impl_url_bool_field!(
1130        /// Add timestamps to every log line.
1131        timestamps => "timestamps"
1132    );
1133
1134    impl_url_str_field!(
1135        /// Only return logs before this time, as a UNIX timestamp.
1136        until => "until"
1137    );
1138}
1139
1140impl_opts_builder!(url =>
1141    /// Adjust how container stats are reported.
1142    ContainerStats
1143);
1144
1145impl ContainerStatsOpts {
1146    pub(crate) fn oneshot(&self) -> Self {
1147        let mut new = self.clone();
1148        new.params.insert("stream", false.to_string());
1149        new
1150    }
1151
1152    pub(crate) fn stream(&self) -> Self {
1153        let mut new = self.clone();
1154        new.params.insert("stream", true.to_string());
1155        new
1156    }
1157}
1158
1159impl ContainerStatsOptsBuilder {
1160    impl_url_vec_field!(
1161        /// Names or IDs of containers
1162        containers => "containers"
1163    );
1164
1165    impl_url_field!(
1166        /// Time in seconds between stats reports
1167        interval: usize => "interval"
1168    );
1169}
1170
1171impl_opts_builder!(url =>
1172    /// Adjust how container stats are reported.
1173    ContainerTop
1174);
1175
1176impl ContainerTopOpts {
1177    pub(crate) fn oneshot(&self) -> Self {
1178        let mut new = self.clone();
1179        new.params.insert("stream", false.to_string());
1180        new
1181    }
1182
1183    pub(crate) fn stream(&self) -> Self {
1184        let mut new = self.clone();
1185        new.params.insert("stream", true.to_string());
1186        new
1187    }
1188}
1189
1190impl ContainerTopOptsBuilder {
1191    impl_url_field!(
1192        /// if streaming, delay in seconds between updates. Must be >1. (As of version 4.0)
1193        delay: usize => "delay"
1194    );
1195
1196    impl_url_str_field!(
1197        /// Arguments to pass to ps such as aux. Requires ps(1) to be installed in the container
1198        /// if no ps(1) compatible AIX descriptors are used.
1199        ps_args => "ps_args"
1200    );
1201}
1202
1203#[derive(Debug)]
1204/// Used to filter removed images.
1205pub enum ContainerPruneFilter {
1206    /// Prune containers created before this timestamp. The <timestamp> can be Unix timestamps, date
1207    /// formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed relative to the
1208    /// daemon machine’s time.
1209    // #TODO: DateTime
1210    Until(String),
1211    /// Container with key label.
1212    LabelKey(String),
1213    /// Container with key-value label.
1214    LabelKeyVal(String, String),
1215    /// Container without key label.
1216    NoLabelKey(String),
1217    /// Container without key-value label.
1218    NoLabelKeyVal(String, String),
1219}
1220
1221impl Filter for ContainerPruneFilter {
1222    fn query_item(&self) -> FilterItem {
1223        use ContainerPruneFilter::*;
1224        match &self {
1225            Until(until) => FilterItem::new("until", until.to_string()),
1226            LabelKey(key) => FilterItem::new("label", key.clone()),
1227            LabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
1228            NoLabelKey(key) => FilterItem::new("label!", key.clone()),
1229            NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{key}={val}")),
1230        }
1231    }
1232}
1233
1234impl_opts_builder!(url =>
1235    /// Adjust how stopped containers are removed.
1236    ContainerPrune
1237);
1238
1239impl ContainerPruneOptsBuilder {
1240    impl_filter_func!(
1241        /// Filters to process on the prune list.
1242        ContainerPruneFilter
1243    );
1244}
1245
1246impl_opts_builder!(url =>
1247    /// Adjust how a container is restored.
1248    ContainerRestore
1249);
1250
1251impl ContainerRestoreOptsBuilder {
1252    impl_url_bool_field!(
1253        /// Do not include root file-system changes when exporting.
1254        ignore_root_fs => "ignoreRootFS"
1255    );
1256
1257    impl_url_bool_field!(
1258        /// Ignore IP address if set statically.
1259        ignore_static_ip => "ignoreStaticIP"
1260    );
1261
1262    impl_url_bool_field!(
1263        /// Ignore MAC address if set statically.
1264        ignore_static_mac => "ignoreStaticMac"
1265    );
1266
1267    impl_url_bool_field!(
1268        /// Import the restore from a checkpoint tar.gz.
1269        import => "import"
1270    );
1271
1272    impl_url_bool_field!(
1273        /// Keep all temporary checkpoint files.
1274        keep => "keep"
1275    );
1276
1277    impl_url_bool_field!(
1278        /// Leave the container running after writing checkpoint to disk.
1279        leave_running => "leaveRunning"
1280    );
1281
1282    impl_url_str_field!(
1283        /// The name of the container when restored from a tar. can only be used with import.
1284        name => "name"
1285    );
1286
1287    impl_url_str_field!(
1288        /// Pod to restore into.
1289        pod => "pod"
1290    );
1291
1292    impl_url_bool_field!(
1293        /// Add restore statistics to the response.
1294        print_stats => "printStats"
1295    );
1296
1297    impl_url_bool_field!(
1298        /// Checkpoint a container with established TCP connections.
1299        tcp_established => "tcpEstablished"
1300    );
1301}