1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
use crate::api::Filter;

impl_opts_builder!(json => VolumeCreate);

impl VolumeCreateOptsBuilder {
    impl_str_field!(
        /// The new volume's name. If not specified, Docker generates a name.
        name: N => "Name"
    );

    impl_str_field!(
        /// Name of the volume driver to use.
        driver: D => "Driver"
    );

    impl_map_field!(json
        /// A mapping of driver options and values.
        /// These options are passed directly to the driver and are driver specific.
        driver_opts: O => "DriverOpts");

    impl_map_field!(json
        /// User-defined key/value metadata.
        labels: L => "Labels"
    );
}

impl_opts_builder!(url => VolumePrune);

impl_opts_builder!(url => VolumeList);

/// Filter type used to filter volumes by one of the variants.
pub enum VolumeFilter {
    /// When set to `true`, returns all volumes that are not in use by a container.
    /// When set to `false`, only volumes that are in use by one or more containers are returned.
    Dangling(bool),
    /// Matches volumes based on their driver.
    Driver(String),
    /// Label in the form of `label=key`.
    LabelKey(String),
    /// Label in the form of `label=key=val`.
    Label { key: String, val: String },
    /// Matches all or part of a volume name.
    Name(String),
}

impl Filter for VolumeFilter {
    fn query_key_val(&self) -> (&'static str, String) {
        use VolumeFilter::*;
        match &self {
            Dangling(dangling) => ("dangling", dangling.to_string()),
            Driver(driver) => ("driver", driver.to_owned()),
            LabelKey(label) => ("label", label.to_owned()),
            Label { key, val } => ("label", format!("{}:{}", key, val)),
            Name(name) => ("name", name.to_owned()),
        }
    }
}

impl VolumePruneOptsBuilder {
    impl_filter_func!(
        /// Filter pruned volumes by one of the variants of the filter enum.
        VolumeFilter
    );
}

impl VolumeListOptsBuilder {
    impl_filter_func!(
        /// Filter listed volumes by one of the variants of the filter enum.
        VolumeFilter
    );
}