docker_sync/
container.rs

1use std::collections::HashMap;
2
3#[derive(Serialize, Deserialize, Debug)]
4#[allow(non_snake_case)]
5//Labels, HostConfig
6pub struct Container {
7    pub Id: String,
8    pub Image: String,
9    pub Status: String,
10    pub Command: String,
11    pub Created: u64,
12    pub Names: Vec<String>,
13    pub Ports: Vec<Port>,
14    pub SizeRw: Option<u64>, // I guess it is optional on Mac.
15    pub SizeRootFs: u64,
16    pub Labels: Option<HashMap<String, String>>,
17    pub HostConfig: HostConfig,
18}
19
20#[derive(Serialize, Deserialize, Debug)]
21#[allow(non_snake_case)]
22pub struct Port {
23    pub IP: Option<String>,
24    pub PrivatePort: u64,
25    pub PublicPort: Option<u64>,
26    pub Type: String,
27}
28
29#[derive(Serialize, Deserialize, Debug)]
30#[allow(non_snake_case)]
31pub struct HostConfig {
32    pub NetworkMode: String,
33}
34
35#[derive(Serialize, Deserialize, Debug)]
36#[allow(non_snake_case)]
37pub struct ContainerInfo {
38    pub AppArmorProfile: String,
39    pub Args: Vec<String>,
40    // Config
41    pub Created: String,
42    pub Driver: String,
43    pub ExecDriver: String,
44    // ExecIDs
45    // HostConfig
46    pub HostnamePath: String,
47    pub HostsPath: String,
48    pub LogPath: String,
49    pub Id: String,
50    pub Image: String,
51    pub MountLabel: String,
52    pub Name: String,
53    // NetworkSettings
54    pub Path: String,
55    pub ProcessLabel: String,
56    pub ResolvConfPath: String,
57    pub RestartCount: u64,
58    // State
59    pub Volumes: HashMap<String, String>,
60    pub VolumesRW: HashMap<String, bool>,
61}
62
63impl Clone for Container {
64    fn clone(&self) -> Self {
65        Container {
66            Id: self.Id.clone(),
67            Image: self.Image.clone(),
68            Status: self.Status.clone(),
69            Command: self.Command.clone(),
70            Created: self.Created,
71            Names: self.Names.clone(),
72            Ports: self.Ports.clone(),
73            SizeRw: self.SizeRw,
74            SizeRootFs: self.SizeRootFs,
75            Labels: self.Labels.clone(),
76            HostConfig: self.HostConfig.clone(),
77        }
78    }
79}
80
81impl std::fmt::Display for Container {
82    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
83        write!(f, "{}", self.Id)
84    }
85}
86
87impl std::clone::Clone for Port {
88    fn clone(&self) -> Self {
89        Port {
90            IP: self.IP.clone(),
91            PrivatePort: self.PrivatePort,
92            PublicPort: self.PublicPort,
93            Type: self.Type.clone(),
94        }
95    }
96}
97
98impl Clone for HostConfig {
99    fn clone(&self) -> Self {
100        HostConfig {
101            NetworkMode: self.NetworkMode.clone(),
102        }
103    }
104}
105
106impl Clone for ContainerInfo {
107    fn clone(&self) -> Self {
108        ContainerInfo {
109            AppArmorProfile: self.AppArmorProfile.clone(),
110            Args: self.Args.clone(),
111            // Config
112            Created: self.Created.clone(),
113            Driver: self.Driver.clone(),
114            ExecDriver: self.ExecDriver.clone(),
115            // ExecIDs
116            // HostConfig
117            HostnamePath: self.HostnamePath.clone(),
118            HostsPath: self.HostsPath.clone(),
119            LogPath: self.LogPath.clone(),
120            Id: self.Id.clone(),
121            Image: self.Image.clone(),
122            MountLabel: self.MountLabel.clone(),
123            Name: self.Name.clone(),
124            // NetworkSettings
125            Path: self.Path.clone(),
126            ProcessLabel: self.ProcessLabel.clone(),
127            ResolvConfPath: self.ResolvConfPath.clone(),
128            RestartCount: self.RestartCount,
129            // State
130            Volumes: self.Volumes.clone(),
131            VolumesRW: self.VolumesRW.clone(),
132        }
133    }
134}
135
136impl std::fmt::Display for ContainerInfo {
137    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
138        write!(f, "{}", self.Id)
139    }
140}
141
142#[derive(Serialize, Deserialize, Debug)]
143#[allow(non_snake_case)]
144pub struct PortBinding {
145    pub HostIp: Option<String>,
146    pub HostPort: String,
147}
148
149impl Clone for PortBinding {
150    fn clone(&self) -> Self {
151        PortBinding {
152            HostIp: self.HostIp.clone(),
153            HostPort: self.HostPort.clone(),
154        }
155    }
156}
157
158impl std::fmt::Display for PortBinding {
159    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
160        write!(f, "{}", self.HostPort)
161    }
162}
163
164#[derive(Serialize, Deserialize, Debug)]
165#[allow(non_snake_case)]
166pub struct HostConfigCreate {
167    pub NetworkMode: Option<String>,
168    pub PublishAllPorts: Option<bool>,
169    pub PortBindings: Option<HashMap<String, Vec<PortBinding>>>,
170}
171
172impl Clone for HostConfigCreate {
173    fn clone(&self) -> Self {
174        HostConfigCreate {
175            NetworkMode: self.NetworkMode.clone(),
176            PublishAllPorts: self.PublishAllPorts,
177            PortBindings: self.PortBindings.clone(),
178        }
179    }
180}
181
182impl std::fmt::Display for HostConfigCreate {
183    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
184        write!(f, "{:#?}", self.NetworkMode)
185    }
186}
187
188#[derive(Serialize, Deserialize, Debug)]
189#[allow(non_snake_case)]
190pub struct ContainerCreate {
191    pub Image: String,
192    pub Labels: Option<HashMap<String, String>>,
193    pub ExposedPorts: Option<HashMap<String, HashMap<i32, i32>>>,
194    pub HostConfig: Option<HostConfigCreate>,
195}
196
197impl Clone for ContainerCreate {
198    fn clone(&self) -> Self {
199        ContainerCreate {
200            Image: self.Image.clone(),
201            Labels: self.Labels.clone(),
202            ExposedPorts: self.ExposedPorts.clone(),
203            HostConfig: self.HostConfig.clone(),
204        }
205    }
206}
207
208impl std::fmt::Display for ContainerCreate {
209    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::result::Result<(), std::fmt::Error> {
210        write!(f, "{}", self.Image)
211    }
212}