Skip to main content

podman_api/opts/
volumes.rs

1use containers_api::opts::{Filter, FilterItem};
2use containers_api::{impl_filter_func, impl_map_field, impl_opts_builder, impl_str_field};
3
4impl_opts_builder!(url =>
5    /// Adjust the list of returned volumes with this options.
6    VolumeList
7);
8
9#[derive(Debug)]
10/// Used to filter listed volumes by one of the variants.
11pub enum VolumeListFilter {
12    /// Match a volume based on a driver.
13    Driver(String),
14    /// Volumes with a label.
15    LabelKey(String),
16    /// Volumes with a key=value label.
17    LabelKeyVal(String, String),
18    /// Volumes without a label.
19    NoLabelKey(String),
20    /// Volumes without a key=value label.
21    NoLabelKeyVal(String, String),
22    /// Volume with name
23    Name(String),
24    /// Volumes with storage driver opts
25    Opt(String),
26    /// The <timestamp> can be Unix timestamps, date formatted timestamps, or Go
27    /// duration strings (e.g. 10m, 1h30m) computed relative to the daemon machine’s time.
28    Until(String),
29}
30
31impl Filter for VolumeListFilter {
32    fn query_item(&self) -> FilterItem {
33        use VolumeListFilter::*;
34        match &self {
35            Driver(driver) => FilterItem::new("driver", driver.clone()),
36            LabelKey(key) => FilterItem::new("label", key.clone()),
37            LabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
38            NoLabelKey(key) => FilterItem::new("label!", key.clone()),
39            NoLabelKeyVal(key, val) => FilterItem::new("label!", format!("{key}={val}")),
40            Name(name) => FilterItem::new("name", name.clone()),
41            Opt(opt) => FilterItem::new("opt", opt.clone()),
42            Until(t) => FilterItem::new("until", t.clone()),
43        }
44    }
45}
46
47impl VolumeListOptsBuilder {
48    impl_filter_func!(VolumeListFilter);
49}
50
51impl_opts_builder!(json =>
52    /// Adjust how a volume is created
53    VolumeCreate
54);
55
56impl VolumeCreateOptsBuilder {
57    impl_str_field!(
58        /// Storage driver to use.
59        driver => "Driver"
60    );
61
62    impl_map_field!(json
63        /// Key/value user-defined metadatada.
64        labels => "Labels"
65    );
66
67    impl_str_field!(
68        /// Name for the volume.
69        name => "Name"
70    );
71
72    impl_map_field!(json
73        /// Mapping of storage driver options and values
74        options => "Options"
75    );
76}
77
78impl_opts_builder!(url =>
79    /// Adjust how volumes will be pruned.
80    VolumePrune
81);
82
83#[derive(Debug)]
84/// Used to filter pruned volumes.
85pub enum VolumePruneFilter {
86    /// Volumes with a label.
87    LabelKey(String),
88    /// Volumes with a key=value label.
89    LabelKeyVal(String, String),
90    /// Volumes without a label.
91    NoLabelKey(String),
92    /// Volumes without a key=value label.
93    NoLabelKeyVal(String, String),
94    /// The <timestamp> can be Unix timestamps, date formatted timestamps, or Go
95    /// duration strings (e.g. 10m, 1h30m) computed relative to the daemon machine’s time.
96    Until(String),
97}
98
99impl Filter for VolumePruneFilter {
100    fn query_item(&self) -> FilterItem {
101        use VolumePruneFilter::*;
102        match &self {
103            LabelKey(key) => FilterItem::new("label", key.clone()),
104            LabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
105            NoLabelKey(key) => FilterItem::new("label", key.clone()),
106            NoLabelKeyVal(key, val) => FilterItem::new("label", format!("{key}={val}")),
107            Until(t) => FilterItem::new("until", t.clone()),
108        }
109    }
110}
111
112impl VolumePruneOptsBuilder {
113    impl_filter_func!(VolumePruneFilter);
114}