podman_api/opts/
mod.rs

1//! Options used for configuring the behavior of certain API endpoints
2
3mod containers;
4mod exec;
5mod images;
6mod manifests;
7mod networks;
8mod pods;
9mod volumes;
10
11pub use containers::*;
12pub use exec::*;
13pub use images::*;
14pub use manifests::*;
15pub use networks::*;
16pub use pods::*;
17pub use volumes::*;
18
19pub type EventsConstraint = (String, Vec<String>);
20
21use containers_api::{
22    impl_opts_builder, impl_opts_required_builder, impl_url_bool_field, impl_url_enum_field,
23    impl_url_field, impl_url_str_field, impl_url_vec_field,
24};
25use std::fmt;
26
27impl_opts_builder!(
28    url =>
29    /// Used to filter events returned by [Podman::events](crate::Podman::events).
30    Events
31);
32
33impl EventsOptsBuilder {
34    impl_url_str_field!(
35        /// Start streaming events from this time
36        since => "since"
37    );
38
39    impl_url_str_field!(
40        /// Stop streaming events later than this
41        until => "until"
42    );
43
44    impl_url_bool_field!(
45        /// when false, do not follow events
46        stream => "stream"
47    );
48
49    /// A list of constraints for events
50    pub fn filters(mut self, filters: impl IntoIterator<Item = EventsConstraint>) -> Self {
51        let filters: std::collections::HashMap<_, _> = filters.into_iter().collect();
52        self.params.insert(
53            "filters",
54            serde_json::to_string(&filters).unwrap_or_default(),
55        );
56        self
57    }
58}
59
60impl_opts_builder!(url =>
61    /// Adjust how filesystem changes inside a container or image are returned.
62    Changes
63);
64
65#[derive(Debug, Clone, Copy, PartialEq, Eq)]
66/// Used with [`ChangesOptsBuilder::diff_type`](ChangesOptsBuilder::diff_type).
67#[derive(Default)]
68pub enum DiffType {
69    #[default]
70    All,
71    Container,
72    Image,
73}
74
75impl AsRef<str> for DiffType {
76    fn as_ref(&self) -> &str {
77        match self {
78            DiffType::All => "all",
79            DiffType::Container => "container",
80            DiffType::Image => "image",
81        }
82    }
83}
84
85impl fmt::Display for DiffType {
86    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
87        write!(f, "{}", self.as_ref())
88    }
89}
90
91impl ChangesOptsBuilder {
92    impl_url_enum_field!(
93        /// Select what you want to match.
94        diff_type: DiffType => "diffType"
95    );
96
97    impl_url_str_field!(
98        /// Specify a second layer which is used to compare against it instead of the parent layer.
99        parent => "parent"
100    );
101}
102
103impl_opts_builder!(url =>
104    /// Adjust how systemd units are generated from a container or pod.
105    SystemdUnits
106);
107
108#[derive(Debug, Clone, Copy, PartialEq, Eq)]
109/// Used with [`SystemdUnitsOptsBuilder::restart_policy`](SystemdUnitsOptsBuilder::restart_policy).
110#[derive(Default)]
111pub enum SystemdRestartPolicy {
112    No,
113    OnSuccess,
114    #[default]
115    OnFailure,
116    OnAbnormal,
117    OnWatchdog,
118    OnAbort,
119    Always,
120}
121
122impl AsRef<str> for SystemdRestartPolicy {
123    fn as_ref(&self) -> &str {
124        use SystemdRestartPolicy::*;
125        match self {
126            No => "no",
127            OnSuccess => "on-success",
128            OnFailure => "on-failure",
129            OnAbnormal => "on-abnormal",
130            OnWatchdog => "on-watchdog",
131            OnAbort => "on-abort",
132            Always => "always",
133        }
134    }
135}
136
137impl fmt::Display for SystemdRestartPolicy {
138    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
139        write!(f, "{}", self.as_ref())
140    }
141}
142
143impl SystemdUnitsOptsBuilder {
144    impl_url_vec_field!(
145        /// Set environment variables to the systemd unit files.
146        additional_env_variables => "additionalEnvVariables"
147    );
148
149    impl_url_vec_field!(
150        /// Systemd After list for the container or pods.
151        after => "after"
152    );
153
154    impl_url_str_field!(
155        /// Systemd unit name prefix for containers.
156        container_prefix => "containerPrefix"
157    );
158
159    impl_url_bool_field!(
160        /// Create a new container instead of starting an existing one.
161        new => "new"
162    );
163
164    impl_url_bool_field!(
165        /// Do not generate the header including the Podman version and the timestamp.
166        no_header => "noHeader"
167    );
168
169    impl_url_str_field!(
170        /// Systemd unit name prefix for pods.
171        pod_prefix => "podPrefix"
172    );
173
174    impl_url_vec_field!(
175        /// Systemd Requires list for the container or pods.
176        requires => "requires"
177    );
178
179    impl_url_enum_field!(
180        /// Systemd restart-policy.
181        restart_policy: SystemdRestartPolicy => "restartPolicy"
182    );
183
184    impl_url_field!(
185        /// Configures the time to sleep before restarting a service.
186        restart_sec: usize => "restartSec"
187    );
188
189    impl_url_str_field!(
190        /// Systemd unit name separator between name/id and prefix.
191        separator => "separator"
192    );
193
194    impl_url_field!(
195        /// Start timeout in seconds.
196        start_timeout: usize => "startTimeout"
197    );
198
199    impl_url_field!(
200        /// Stop timeout in seconds.
201        stop_timeout: usize => "stopTimeout"
202    );
203
204    impl_url_bool_field!(
205        /// Use container/pod names instead of IDs.
206        use_name => "useName"
207    );
208
209    impl_url_vec_field!(
210        /// Systemd Wants list for the container or pods.
211        wants => "wants"
212    );
213}
214
215impl_opts_builder!(url =>
216    /// Adjust how a kubernetes YAML will create pods and containers.
217    PlayKubernetesYaml
218);
219
220impl PlayKubernetesYamlOptsBuilder {
221    impl_url_str_field!(
222        /// Logging driver for the containers in the pod.
223        log_driver => "logDriver"
224    );
225
226    impl_url_vec_field!(
227        /// Use the network mode or specify an array of networks.
228        network => "network"
229    );
230
231    impl_url_bool_field!(
232        /// Start the pod after creating it.
233        start => "start"
234    );
235
236    impl_url_vec_field!(
237        /// Static IPs used for the pods.
238        static_ips => "staticIPs"
239    );
240
241    impl_url_vec_field!(
242        /// Static MACs used for the pods.
243        static_macs => "static_macs"
244    );
245
246    impl_url_bool_field!(
247        /// Require HTTPS and verify signatures when contacting registries.
248        tls_verify => "tlsVerify"
249    );
250}
251
252//####################################################################################################
253//
254// Secrets
255//
256//####################################################################################################
257
258impl_opts_required_builder!(url =>
259    /// Used to create a [Secret](crate::api::Secret).
260    SecretCreate,
261    /// The name of the secret
262    name => "name"
263);
264
265impl SecretCreateOptsBuilder {
266    impl_url_str_field!(
267        /// Secret driver. Default is `file`.
268        driver => "driver"
269    );
270
271    impl_url_str_field!(
272        /// Secret driver options.
273        driver_opts => "driveropts"
274    );
275
276    impl_url_str_field!(
277        /// Labels on the secret.
278        labels => "labels"
279    );
280}