stackify_docker_api/opts/
volume.rs

1use containers_api::opts::{Filter, FilterItem};
2use containers_api::{
3    impl_field, impl_filter_func, impl_map_field, impl_opts_builder, impl_opts_required_builder,
4    impl_str_field,
5};
6
7impl_opts_builder!(json => VolumeCreate);
8
9impl VolumeCreateOptsBuilder {
10    impl_str_field!(
11        /// The new volume's name. If not specified, Docker generates a name.
12        name => "Name"
13    );
14
15    impl_str_field!(
16        /// Name of the volume driver to use.
17        driver => "Driver"
18    );
19
20    impl_map_field!(json
21        /// A mapping of driver options and values.
22        /// These options are passed directly to the driver and are driver specific.
23        driver_opts => "DriverOpts");
24
25    impl_map_field!(json
26        /// User-defined key/value metadata.
27        labels => "Labels"
28    );
29
30    impl_field!(
31        /// Cluster-specific options used to create the volume.
32        cluster_spec: crate::models::ClusterVolumeSpec => "ClusterVolumeSpec"
33    );
34}
35
36impl_opts_builder!(url => VolumePrune);
37
38impl_opts_builder!(url => VolumeList);
39
40/// Filter type used to filter volumes by one of the variants.
41pub enum VolumeFilter {
42    /// When set to `true`, returns all volumes that are not in use by a container.
43    /// When set to `false`, only volumes that are in use by one or more containers are returned.
44    Dangling(bool),
45    /// Matches volumes based on their driver.
46    Driver(String),
47    /// Label in the form of `label=key`.
48    LabelKey(String),
49    /// Label in the form of `label=key=val`.
50    Label { key: String, val: String },
51    /// Matches all or part of a volume name.
52    Name(String),
53}
54
55impl Filter for VolumeFilter {
56    fn query_item(&self) -> FilterItem {
57        use VolumeFilter::*;
58        match &self {
59            Dangling(dangling) => FilterItem::new("dangling", dangling.to_string()),
60            Driver(driver) => FilterItem::new("driver", driver.to_owned()),
61            LabelKey(label) => FilterItem::new("label", label.to_owned()),
62            Label { key, val } => FilterItem::new("label", format!("{key}:{val}")),
63            Name(name) => FilterItem::new("name", name.to_owned()),
64        }
65    }
66}
67
68impl VolumePruneOptsBuilder {
69    impl_filter_func!(
70        /// Filter pruned volumes by one of the variants of the filter enum.
71        VolumeFilter
72    );
73}
74
75impl VolumeListOptsBuilder {
76    impl_filter_func!(
77        /// Filter listed volumes by one of the variants of the filter enum.
78        VolumeFilter
79    );
80}
81
82impl_opts_required_builder!(json =>
83    /// Update swarm cluster volume
84    ClusterVolumeUpdate,
85    /// The version number of the volume being updated. This is required to avoid conflicting writes. Found in the volume's ClusterVolume field.
86    version: i64 => "version"
87);
88
89impl ClusterVolumeUpdateOptsBuilder {
90    impl_str_field!(
91        /// Group defines the volume group of this volume. Volumes belonging to the same group can be referred to by group name when creating Services.
92        /// Referring to a volume by group instructs Swarm to treat volumes in that group interchangeably for the purpose of scheduling. Volumes with
93        /// an empty string for a group technically all belong to the same, emptystring group.
94        group => "Group"
95    );
96
97    impl_field!(
98        /// Defines how the volume is used by tasks.
99        access_mode: serde_json::Value => "AccessMode"
100    );
101}