podman_api/opts/pods.rs
1use crate::models;
2use containers_api::opts::{Filter, FilterItem};
3use containers_api::{
4 impl_field, impl_filter_func, impl_map_field, impl_opts_builder, impl_str_field,
5 impl_url_bool_field, impl_url_field, impl_url_str_field, impl_url_vec_field, impl_vec_field,
6};
7
8impl_opts_builder!(url =>
9 /// Adjust the list of returned pods with this options.
10 PodList
11);
12
13#[derive(Debug)]
14/// Used to filter listed pods by one of the variants.
15pub enum PodListFilter {
16 /// A pods's ID
17 Id(crate::Id),
18 /// Pods with key label.
19 LabelKey(String),
20 /// Pods with key=value label.
21 LabelKeyVal(String, String),
22 /// Pods without key label.
23 NoLabelKey(String),
24 /// Pods without key=value label.
25 NoLabelKeyVal(String, String),
26 /// A pods's name
27 Name(String),
28 /// List pods created before this timestamp. The <timestamp> can be Unix timestamps,
29 /// date formatted timestamps, or Go duration strings (e.g. 10m, 1h30m) computed
30 /// relative to the daemon machine’s time.
31 Until(String),
32 /// Name or full ID of network.
33 Network(String),
34 Status(models::PodStatus),
35 /// Container name within the pod.
36 ContainerName(String),
37 /// Container name within the pod.
38 ContainerId(crate::Id),
39 /// Container status within the pod.
40 ContainerStatus(models::ContainerStatus),
41 /// Number of containers within the pod.
42 ContainerNumber(usize),
43}
44
45impl Filter for PodListFilter {
46 fn query_item(&self) -> FilterItem {
47 use PodListFilter::*;
48 match &self {
49 Id(id) => FilterItem::new("id", id.to_string()),
50 LabelKey(key) => FilterItem::new("label", key.clone()),
51 LabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
52 NoLabelKey(key) => FilterItem::new("label!", key.clone()),
53 NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{key}={val}")),
54 Name(name) => FilterItem::new("name", name.clone()),
55 Until(until) => FilterItem::new("until", until.clone()),
56 Network(net) => FilterItem::new("network", net.clone()),
57 Status(status) => FilterItem::new("status", status.as_ref().to_string()),
58 ContainerName(name) => FilterItem::new("ctr-names", name.clone()),
59 ContainerId(id) => FilterItem::new("ctr-ids", id.to_string()),
60 ContainerStatus(status) => FilterItem::new("ctr-status", status.as_ref().to_string()),
61 ContainerNumber(n) => FilterItem::new("ctr-number", n.to_string()),
62 }
63 }
64}
65
66impl PodListOptsBuilder {
67 impl_filter_func!(PodListFilter);
68}
69
70impl_opts_builder!(url =>
71 /// Adjust how processes inside a pod are listed.
72 PodTop
73);
74
75impl PodTopOpts {
76 pub(crate) fn stream(&self) -> Self {
77 let mut new = self.clone();
78 new.params.insert("stream", true.to_string());
79 new
80 }
81}
82
83impl PodTopOptsBuilder {
84 impl_url_field!(
85 /// If streaming, delay in seconds between updates.
86 delay: usize => "delay"
87 );
88
89 impl_url_str_field!(
90 /// Arguments to pass to ps such as aux. Requires ps(1) to be installed in the container if
91 /// no ps(1) compatible AIX descriptors are used.
92 ps_args => "ps_args"
93 );
94}
95
96impl_opts_builder!(url =>
97 /// Adjust how stats of a process are listed.
98 PodStats
99);
100
101impl PodStatsOpts {
102 pub(crate) fn stream(&self) -> Self {
103 let mut new = self.clone();
104 new.params.insert("stream", true.to_string());
105 new
106 }
107}
108
109impl PodStatsOptsBuilder {
110 impl_url_bool_field!(
111 /// Provide statistics for all running pods.
112 all => "all"
113 );
114
115 impl_url_vec_field!(
116 /// Names or IDs of pods.
117 names_or_ids => "namesOrIds"
118 );
119}
120
121impl_opts_builder!(json =>
122 /// Adjust the way a pod is created.
123 PodCreate
124);
125
126impl PodCreateOptsBuilder {
127 impl_str_field!(
128 /// The parent for the CGroup that the pod will create. This pod cgroup will, in turn, be
129 /// the default cgroup parent for all containers in the pod.
130 cgroup_parent => "cgroup_parent"
131 );
132
133 impl_vec_field!(
134 /// List of CNI networks to join the container to. If this list is empty, the default CNI
135 /// network will be joined instead. If at least one entry is present, we will not join the
136 /// default network (unless it is part of this list). Only available if NetNS is set to
137 /// bridge. Optional. Deprecated: as of podman 4.0 use "Networks" instead.
138 cni_networks => "cni_networks"
139 );
140
141 impl_field!(
142 /// CPU period of the cpuset, determined by --cpus
143 cpu_period: u64 => "cpu_period"
144 );
145
146 impl_field!(
147 /// CPU quota of the cpuset, determined by --cpus
148 cpu_quota: i64 => "cpu_quota"
149 );
150
151 impl_vec_field!(
152 /// Set of DNS options that will be used in the infra container's resolv.conf, which
153 /// will, by default, be shared with all containers in the pod. Conflicts with
154 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true.
155 dns_option => "dns_option"
156 );
157
158 impl_vec_field!(
159 /// Set of DNS search domains that will be used in the infra container's resolv.conf,
160 /// which will, by default, be shared with all containers in the pod. If not provided, DNS
161 /// search domains from the host's resolv.conf will be used. Conflicts with
162 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true.
163 dns_search => "dns_search"
164 );
165
166 impl_vec_field!(
167 /// Set of DNS servers that will be used in the infra container's resolv.conf, which
168 /// will, by default, be shared with all containers in the pod. If not provided,
169 /// the host's DNS servers will be used, unless the only server set is a
170 /// localhost address. As the container cannot connect to the host's localhost,
171 /// a default server will instead be set. Conflicts with
172 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true.
173 dns_server => "dns_server"
174 );
175
176 impl_str_field!(
177 /// Determines the pod's exit and stop behaviour.
178 exit_policy => "exit_policy"
179 );
180
181 impl_vec_field!(
182 /// Set of hosts that will be added to the infra container's etc/hosts that will, by
183 /// default, be shared with all containers in the pod. Conflicts with
184 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true and
185 /// [`no_manage_hosts`](PodCreateOptsBuilder::no_manage_hosts).
186 add_hosts => "hostadd"
187 );
188
189 impl_str_field!(
190 /// The pod's hostname. If not set, the name of the pod will be used (if a name was not
191 /// provided here, the name auto-generated for the pod will be used). This will be used by
192 /// the infra container and all containers in the pod as long as the UTS namespace is
193 /// shared.
194 hostname => "hostname"
195 );
196
197 impl_field!(
198 /// Used for specifying how ID mapping should be set up for a layer or container.
199 idmappings: models::IdMappingOptions => "idmappings"
200 );
201
202 impl_vec_field!(
203 /// Image volumes bind-mount a container-image mount into the pod's infra container.
204 image_volumes: models::ImageVolume => "image_volumes"
205 );
206
207 impl_vec_field!(
208 /// Sets the command that will be used to start the infra container. If not set, the
209 /// default set in the Libpod configuration file will be used. Conflicts with
210 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true.
211 infra_command => "infra_command"
212 );
213
214 impl_str_field!(
215 /// Custom path to store the infra container's conmon PID.
216 infra_common_pid_file => "infra_common_pid_file"
217 );
218
219 impl_str_field!(
220 /// The image that will be used for the infra container. If not set, the default set
221 /// in the Libpod configuration file will be used. Conflicts with
222 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true.
223 infra_image => "infra_image"
224 );
225
226 impl_str_field!(
227 /// The name that will be used for the infra container. If not set, the default set in the
228 /// Libpod configuration file will be used. Conflicts with
229 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true.
230 infra_name => "infra_name"
231 );
232
233 impl_map_field!(json
234 /// Key-value pairs that are used to add metadata to a pod.
235 labels => "labels"
236 );
237
238 impl_vec_field!(
239 /// Mounts are mounts that will be added to the pod. These will supersede [`image_volumes`](PodCreateOptsBuilder::image_volumes)
240 /// and [`volumes_from`](PodCreateOptsBuilder::volumes_from) volumes where there are conflicts.
241 mounts: models::Mount => "mounts"
242 );
243
244 impl_str_field!(
245 /// The name of the pod. If not provided, a name will be generated when the pod is created.
246 name => "name"
247 );
248
249 impl_field!(
250 netns: models::Namespace => "netns"
251 );
252
253 impl_map_field!(json
254 /// Additional options for each network.
255 network_options => "network_options"
256 );
257
258 // TODO: network
259
260 impl_field!(
261 /// tells the pod not to create an infra container. If this is done, many
262 /// networking-related options will become unavailable. Conflicts with any
263 /// network or infra related settings.
264 no_infra: bool => "no_infra"
265 );
266
267 impl_field!(
268 /// Indicates that /etc/hosts should not be managed by the pod. Instead, each container
269 /// will create a separate /etc/hosts as they would if not in a pod. Conflicts with
270 /// [`add_hosts`](PodCreateOptsBuilder::add_hosts).
271 no_manage_hosts: bool => "no_manage_hosts"
272 );
273
274 impl_field!(
275 /// Indicates that /etc/resolv.conf should not be managed by the pod. Instead, each
276 /// container will create and manage a separate resolv.conf as if they had not joined a
277 /// pod. Conflicts with [`dns_server`](PodCreateOptsBuilder::dns_server),
278 /// [`dns_search`](PodCreateOptsBuilder::dns_search),
279 /// [`dns_option`](PodCreateOptsBuilder::dns_option),
280 /// [`no_infra`](PodCreateOptsBuilder::no_infra).
281 no_manage_resolv_conf: bool => "no_manage_resolv_conf"
282 );
283
284 impl_vec_field!(
285 /// Overlay volumes are named volumes that will be added to the pod.
286 overlay_volumes: models::OverlayVolume => "overlay_volumes"
287 );
288
289 impl_field!(
290 pidns: models::Namespace => "pidns"
291 );
292
293 impl_vec_field!(
294 /// The command used to create this pod. This will be shown in the output of Inspect() on
295 /// the pode and may also be used by some tools that wish to recreate the pod (e.g. podman
296 /// generate systemd --new).
297 pod_create_command => "pod_create_command"
298 );
299
300 impl_vec_field!(
301 /// User specified Devices to be added to the Pod.
302 pod_devices => "pod_devices"
303 );
304
305 impl_vec_field!(
306 /// PortMappings is a set of ports to map into the infra container. As, by default,
307 /// containers share their network with the infra container, this will forward
308 /// the ports to the entire pod. Only available if NetNS is set to Bridge or Slirp.
309 portmappings: models::PortMapping => "portmappings"
310 );
311
312 impl_field!(
313 /// Container runtime resource constraints.
314 resource_limits: models::LinuxResources => "resource_limits"
315 );
316
317 impl_vec_field!(
318 security_opt => "security_opt"
319 );
320
321 impl_vec_field!(
322 /// The ID of the pod's service container.
323 service_container_id => "serviceContainerID"
324 );
325
326 impl_field!(
327 /// ShareParent determines if all containers in the pod will share the pod's cgroup
328 /// as the cgroup parent.
329 share_parent: bool => "share_parent"
330 );
331
332 impl_vec_field!(
333 /// Instructs the pod to share a set of namespaces. Shared namespaces will be joined (by
334 /// default) by every container which joins the pod. If not set and NoInfra is false, the
335 /// pod will set a default set of namespaces to share. Conflicts with
336 /// [`no_infra`](PodCreateOptsBuilder::no_infra) == true.
337 shared_namespaces => "shared_namespaces"
338 );
339
340 impl_field!(
341 /// The size of the tmpfs to mount in at /dev/shm, in bytes.
342 shm_size: i64 => "shm_size"
343 );
344
345 // TODO: throttleReadBpsDevice
346
347 impl_field!(
348 userns: models::Namespace => "userns"
349 );
350
351 impl_field!(
352 utsns: models::Namespace => "utsns"
353 );
354
355 impl_vec_field!(
356 /// Volumes are named volumes that will be added to the pod. These will supersede
357 /// [`image_volumes`](PodCreateOptsBuilder::image_volumes) and [`volumes_from`](PodCreateOptsBuilder::volumes_from)
358 /// volumes where there are conflicts.
359 volumes: models::NamedVolume => "volumes"
360 );
361
362 impl_vec_field!(
363 /// Set of containers whose volumes will be added to this pod. The name or ID of the
364 /// container must be provided, and may optionally be followed by a : and then one or more
365 /// comma-separated options. Valid options are 'ro', 'rw', and 'z'. Options will be used
366 /// for all volumes sourced from the container.
367 volumes_from => "volumes_from"
368 );
369}