docker_client_async/types/
mounts.rs

1/*
2 * Copyright 2020 Damian Peckett <damian@pecke.tt>.
3 * Copyright 2013-2018 Docker, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     https://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18use derive_builder::Builder;
19use serde::{Deserialize, Serialize};
20use std::collections::HashMap;
21
22/// MountPoint is the intersection point between a volume and a container. It
23/// specifies which volume is to be used and where inside a container it should
24/// be mounted.
25///
26/// Note that this type is embedded in `container.Container` object and persisted to disk.
27/// Changes to this struct need to by synced with on disk state.
28#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
29#[builder(default, setter(into))]
30pub struct MountPoint {
31    /// Source is the source path of the mount.
32    /// E.g. `mount --bind /foo /bar`, `/foo` is the `Source`.
33    #[serde(rename = "Source")]
34    #[serde(skip_serializing_if = "Option::is_none")]
35    pub source: Option<String>,
36    /// Destination is the path relative to the container root (`/`) to the mount point
37    /// It is where the `Source` is mounted to.
38    #[serde(rename = "Destination")]
39    #[serde(skip_serializing_if = "Option::is_none")]
40    pub destination: Option<String>,
41    /// RW is set to true when the mountpoint should be mounted as read-write.
42    #[serde(rename = "RW")]
43    #[serde(skip_serializing_if = "Option::is_none")]
44    pub rw: Option<bool>,
45    /// Name is the name reference to the underlying data defined by `Source`
46    /// e.g., the volume name.
47    #[serde(rename = "Name")]
48    #[serde(skip_serializing_if = "Option::is_none")]
49    pub name: Option<String>,
50    /// Driver is the volume driver used to create the volume (if it is a volume).
51    #[serde(rename = "Driver")]
52    #[serde(skip_serializing_if = "Option::is_none")]
53    pub driver: Option<String>,
54    // Type of mount to use, see `Type<foo>` definitions in github.com/docker/docker/api/types/mount.
55    #[serde(rename = "Type")]
56    #[serde(skip_serializing_if = "Option::is_none")]
57    pub mount_type: Option<MountType>,
58    /// mode is the comma separated list of options supplied by the user when creating
59    /// the bind/volume mount.
60    /// Note mode is not used on Windows
61    #[serde(rename = "Mode", alias = "Relabel")]
62    #[serde(skip_serializing_if = "Option::is_none")]
63    pub mode: Option<String>,
64    /// Propagation describes how the mounts are propagated from the host into the
65    /// mount point, and vice-versa.
66    /// See https://www.kernel.org/doc/Documentation/filesystems/sharedsubtree.txt
67    /// Note Propagation is not used on Windows
68    #[serde(rename = "Propagation")]
69    #[serde(skip_serializing_if = "Option::is_none")]
70    pub propagation: Option<MountPropagation>,
71    /// ID is the opaque ID used to pass to the volume driver.
72    /// This should be set by calls to `Mount` and unset by calls to `Unmount`
73    #[serde(rename = "ID")]
74    #[serde(skip_serializing_if = "Option::is_none")]
75    pub id: Option<String>,
76    /// Spec is a copy of the API request that created this mount.
77    #[serde(rename = "Spec")]
78    #[serde(skip_serializing_if = "Option::is_none")]
79    pub spec: Option<Mount>,
80    /// Some bind mounts should not be automatically created.
81    /// (Some are auto-created for backwards-compatibility)
82    /// This is checked on the API but setting this here prevents race conditions.
83    /// where a bind dir existed during validation was removed before reaching the setup code.
84    #[serde(rename = "SkipMountpointCreation")]
85    #[serde(skip_serializing_if = "Option::is_none")]
86    pub skip_mountpoint_creation: Option<bool>,
87    /// Track usage of this mountpoint
88    /// Specifically needed for containers which are running and calls to `docker cp`
89    /// because both these actions require mounting the volumes.
90    #[serde(skip_serializing_if = "Option::is_none")]
91    pub active: Option<i32>,
92}
93
94#[derive(Clone, Debug, Deserialize, Serialize)]
95pub enum MountType {
96    /// TypeBind is the type for mounting host dir.
97    #[serde(rename = "bind")]
98    TypeBind,
99    /// TypeVolume is the type for remote storage volumes.
100    #[serde(rename = "volume")]
101    TypeVolume,
102    /// TypeTmpfs is the type for mounting tmpfs.
103    #[serde(rename = "tmpfs")]
104    TypeTmpfs,
105    /// TypeNamedPipe is the type for mounting Windows named pipes.
106    #[serde(rename = "npipe")]
107    TypeNamedPipe,
108}
109
110/// Propagation represents the propagation of a mount.
111#[derive(Clone, Debug, Deserialize, Serialize)]
112pub enum MountPropagation {
113    /// PropagationRPrivate RPRIVATE.
114    #[serde(rename = "rprivate")]
115    PropagationRPrivate,
116    /// PropagationPrivate PRIVATE.
117    #[serde(rename = "private")]
118    PropagationPrivate,
119    /// PropagationRShared RSHARED.
120    #[serde(rename = "rshared")]
121    PropagationRShared,
122    /// PropagationShared SHARED.
123    #[serde(rename = "shared")]
124    PropagationShared,
125    /// PropagationRSlave RSLAVE.
126    #[serde(rename = "rslave")]
127    PropagationRSlave,
128    /// PropagationSlave SLAVE.
129    #[serde(rename = "slave")]
130    PropagationSlave,
131}
132
133/// Mount represents a mount (volume).
134#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
135#[builder(default, setter(into))]
136pub struct Mount {
137    #[serde(rename = "Type")]
138    #[serde(skip_serializing_if = "Option::is_none")]
139    pub mount_type: Option<MountType>,
140    /// source specifies the name of the mount. Depending on mount type, this
141    /// may be a volume name or a host path, or even ignored.
142    /// Source is not supported for tmpfs (must be an empty value).
143    #[serde(rename = "Source")]
144    #[serde(skip_serializing_if = "Option::is_none")]
145    pub source: Option<String>,
146    #[serde(rename = "Target")]
147    #[serde(skip_serializing_if = "Option::is_none")]
148    pub target: Option<String>,
149    #[serde(rename = "ReadOnly")]
150    #[serde(skip_serializing_if = "Option::is_none")]
151    pub read_only: Option<bool>,
152    #[serde(rename = "Consistency")]
153    #[serde(skip_serializing_if = "Option::is_none")]
154    pub consistency: Option<MountConsistency>,
155    #[serde(rename = "BindOptions")]
156    #[serde(skip_serializing_if = "Option::is_none")]
157    pub bind_options: Option<MountBindOptions>,
158    #[serde(rename = "VolumeOptions")]
159    #[serde(skip_serializing_if = "Option::is_none")]
160    pub volume_options: Option<MountVolumeOptions>,
161    #[serde(rename = "TmpfsOptions")]
162    #[serde(skip_serializing_if = "Option::is_none")]
163    pub tmpfs_options: Option<MountTmpfsOptions>,
164}
165
166/// MountConsistency represents the consistency requirements of a mount.
167#[derive(Clone, Debug, Deserialize, Serialize)]
168pub enum MountConsistency {
169    /// ConsistencyFull guarantees bind mount-like consistency.
170    #[serde(rename = "consistent")]
171    ConsistencyFull,
172    /// ConsistencyCached mounts can cache read data and FS structure.
173    #[serde(rename = "cached")]
174    ConsistencyCached,
175    /// ConsistencyDelegated mounts can cache read and written data and structure.
176    #[serde(rename = "delegated")]
177    ConsistencyDelegated,
178    /// ConsistencyDefault provides "consistent" behavior unless overridden.
179    #[serde(rename = "default")]
180    ConsistencyDefault,
181}
182
183/// MountBindOptions defines options specific to mounts of type "bind".
184#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
185#[builder(default, setter(into))]
186pub struct MountBindOptions {
187    #[serde(rename = "Propagation")]
188    #[serde(skip_serializing_if = "Option::is_none")]
189    pub propagation: Option<MountPropagation>,
190    #[serde(rename = "NonRecursive")]
191    #[serde(skip_serializing_if = "Option::is_none")]
192    pub non_recursive: Option<bool>,
193}
194
195/// MountVolumeOptions represents the options for a mount of type volume.
196#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
197#[builder(default, setter(into))]
198pub struct MountVolumeOptions {
199    #[serde(rename = "NoCopy")]
200    #[serde(skip_serializing_if = "Option::is_none")]
201    pub no_copy: Option<bool>,
202    #[serde(rename = "Labels")]
203    #[serde(skip_serializing_if = "Option::is_none")]
204    pub labels: Option<HashMap<String, String>>,
205    #[serde(rename = "DriverConfig")]
206    #[serde(skip_serializing_if = "Option::is_none")]
207    pub driver_config: Option<MountDriver>,
208}
209
210/// MountDriver represents a volume driver.
211#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
212#[builder(default, setter(into))]
213pub struct MountDriver {
214    #[serde(rename = "Name")]
215    #[serde(skip_serializing_if = "Option::is_none")]
216    pub name: Option<String>,
217    #[serde(rename = "Options")]
218    #[serde(skip_serializing_if = "Option::is_none")]
219    pub options: Option<HashMap<String, String>>,
220}
221
222/// MountTmpfsOptions defines options specific to mounts of type "tmpfs".
223#[derive(Clone, Debug, Default, Deserialize, Serialize, Builder)]
224#[builder(default, setter(into))]
225pub struct MountTmpfsOptions {
226    /// Size sets the size of the tmpfs, in bytes.
227    ///
228    /// This will be converted to an operating system specific value
229    /// depending on the host. For example, on linux, it will be converted to
230    /// use a 'k', 'm' or 'g' syntax. BSD, though not widely supported with
231    /// docker, uses a straight byte value.
232    ///
233    /// Percentages are not supported.
234    #[serde(rename = "SizeBytes")]
235    #[serde(skip_serializing_if = "Option::is_none")]
236    pub size_bytes: Option<i64>,
237    /// Mode of the tmpfs upon creation.
238    #[serde(rename = "Mode")]
239    #[serde(skip_serializing_if = "Option::is_none")]
240    pub mode: Option<u32>,
241}