Skip to main content

podtender/pods/
parameter_types.rs

1use crate::containers::parameter_types::{
2    ImageVolume, LinuxResources, LinuxThrottleDevice, Mount, NamedVolume, Namespace, OverlayVolume,
3    PerNetworkOptions, PortMapping,
4};
5use crate::error::PodtenderError;
6#[cfg(any(test, feature = "examples"))]
7use crate::example_values_trait::ExampleValues;
8use crate::utils;
9#[cfg(feature = "builder")]
10use derive_builder::Builder;
11use serde::{Deserialize, Serialize};
12use serde_with::skip_serializing_none;
13use std::collections::HashMap;
14use std::convert::TryFrom;
15
16#[skip_serializing_none]
17#[cfg_attr(feature = "builder", derive(Builder))]
18#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
19#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
20pub struct CreatePodParameter {
21    pub cgroup_parent: Option<String>,
22    pub cpu_period: Option<i64>,
23    pub cpu_quota: Option<i64>,
24    pub dns_option: Option<Vec<String>>,
25    pub dns_search: Option<Vec<String>>,
26    pub dns_server: Option<String>,
27    pub hostadd: Option<Vec<String>>,
28    pub hostname: Option<String>,
29    pub image_volumes: Option<ImageVolume>,
30    pub infra_command: Option<Vec<String>>,
31    pub infra_conmon_pid_file: Option<String>,
32    pub infra_image: Option<String>,
33    pub labels: Option<HashMap<String, String>>,
34    pub mounts: Option<Vec<Mount>>,
35    pub name: Option<String>,
36    pub netns: Option<Namespace>,
37    pub network_options: Option<HashMap<String, String>>,
38    #[serde(rename = "Networks")]
39    pub networks: Option<HashMap<String, PerNetworkOptions>>,
40    pub no_infra: Option<bool>,
41    pub no_manage_hosts: Option<bool>,
42    pub no_manage_resolv_conf: Option<bool>,
43    pub overlay_volumes: Option<Vec<OverlayVolume>>,
44    pub pidns: Option<Namespace>,
45    pub pod_create_command: Option<String>,
46    pub pod_devices: Option<Vec<String>>,
47    pub portmappings: Option<Vec<PortMapping>>,
48    pub resource_limits: Option<LinuxResources>,
49    pub security_opt: Option<Vec<String>>,
50    pub shared_namespaces: Option<Vec<String>>,
51    pub sysctl: Option<HashMap<String, String>>,
52    #[serde(rename = "ThrottleReadBpsDevice")]
53    pub throttle_read_bps_device: Option<HashMap<String, LinuxThrottleDevice>>,
54    pub userns: Option<Namespace>,
55    pub volumes: Option<Vec<NamedVolume>>,
56    pub volumes_from: Option<Vec<String>>,
57}
58
59#[cfg(any(test, feature = "examples"))]
60impl ExampleValues for CreatePodParameter {
61    fn example() -> Self {
62        Self {
63            name: Some(String::from("CreatePodParameter")),
64            ..Default::default()
65        }
66    }
67}
68
69#[skip_serializing_none]
70#[cfg_attr(feature = "builder", derive(Builder))]
71#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
72#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
73pub struct RemovePodParameter {
74    #[serde(skip_serializing)]
75    pub pod_name: String,
76    pub force: Option<bool>,
77}
78
79#[cfg(any(test, feature = "examples"))]
80impl ExampleValues for RemovePodParameter {
81    fn example() -> Self {
82        Self {
83            pod_name: String::from("RemovePodParameter"),
84            force: Some(true),
85        }
86    }
87}
88
89#[skip_serializing_none]
90#[cfg_attr(feature = "builder", derive(Builder))]
91#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
92#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
93pub struct PodExistsParameter {
94    pub pod_name: String,
95}
96
97#[cfg(any(test, feature = "examples"))]
98impl ExampleValues for PodExistsParameter {
99    fn example() -> Self {
100        Self {
101            pod_name: String::from("ExistsPodParameter"),
102        }
103    }
104}
105
106#[skip_serializing_none]
107#[cfg_attr(feature = "builder", derive(Builder))]
108#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
109#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
110pub struct InspectPodParameter {
111    pub pod_name: String,
112}
113
114#[cfg(any(test, feature = "examples"))]
115impl ExampleValues for InspectPodParameter {
116    fn example() -> Self {
117        Self {
118            pod_name: String::from("InspectPodParameter"),
119        }
120    }
121}
122
123#[skip_serializing_none]
124#[cfg_attr(feature = "builder", derive(Builder))]
125#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
126#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
127pub struct KillPodParameter {
128    #[serde(skip_serializing)]
129    pub pod_name: String,
130    pub signal: Option<String>,
131}
132
133#[cfg(any(test, feature = "examples"))]
134impl ExampleValues for KillPodParameter {
135    fn example() -> Self {
136        Self {
137            pod_name: String::from("KillPodParameter"),
138            signal: Some(String::from("SIGKILL")),
139        }
140    }
141}
142
143#[skip_serializing_none]
144#[cfg_attr(feature = "builder", derive(Builder))]
145#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
146#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
147pub struct PausePodParameter {
148    #[serde(skip_serializing)]
149    pub pod_name: String,
150}
151
152#[cfg(any(test, feature = "examples"))]
153impl ExampleValues for PausePodParameter {
154    fn example() -> Self {
155        Self {
156            pod_name: String::from("PausePodParameter"),
157        }
158    }
159}
160
161#[skip_serializing_none]
162#[cfg_attr(feature = "builder", derive(Builder))]
163#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
164#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
165pub struct RestartPodParameter {
166    #[serde(skip_serializing)]
167    pub pod_name: String,
168}
169
170#[cfg(any(test, feature = "examples"))]
171impl ExampleValues for RestartPodParameter {
172    fn example() -> Self {
173        Self {
174            pod_name: String::from("RestartPodParameter"),
175        }
176    }
177}
178
179#[skip_serializing_none]
180#[cfg_attr(feature = "builder", derive(Builder))]
181#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
182#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
183pub struct StartPodParameter {
184    #[serde(skip_serializing)]
185    pub pod_name: String,
186}
187
188#[cfg(any(test, feature = "examples"))]
189impl ExampleValues for StartPodParameter {
190    fn example() -> Self {
191        Self {
192            pod_name: String::from("StartPodParameter"),
193        }
194    }
195}
196
197#[skip_serializing_none]
198#[cfg_attr(feature = "builder", derive(Builder))]
199#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
200#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
201pub struct StopPodParameter {
202    #[serde(skip_serializing)]
203    pub pod_name: String,
204    #[serde(rename = "t")]
205    pub timeout: Option<i32>,
206}
207
208#[cfg(any(test, feature = "examples"))]
209impl ExampleValues for StopPodParameter {
210    fn example() -> Self {
211        Self {
212            pod_name: String::from("StopPodParameter"),
213            timeout: Some(0),
214        }
215    }
216}
217
218#[skip_serializing_none]
219#[cfg_attr(feature = "builder", derive(Builder))]
220#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
221#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
222pub struct ListPodProcessesParameter {
223    #[serde(skip_serializing)]
224    pub pod_name: String,
225    pub delay: Option<u32>,
226    pub ps_args: Option<String>,
227    pub stream: Option<bool>,
228}
229
230#[cfg(any(test, feature = "examples"))]
231impl ExampleValues for ListPodProcessesParameter {
232    fn example() -> Self {
233        Self {
234            pod_name: String::from("PodListProcessesParameter"),
235            delay: Some(1),
236            ps_args: None,
237            stream: Some(true),
238        }
239    }
240}
241
242#[skip_serializing_none]
243#[cfg_attr(feature = "builder", derive(Builder))]
244#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
245#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
246pub struct UnpausePodParameter {
247    #[serde(skip_serializing)]
248    pub pod_name: String,
249}
250
251#[cfg(any(test, feature = "examples"))]
252impl ExampleValues for UnpausePodParameter {
253    fn example() -> Self {
254        Self {
255            pod_name: String::from("UnpausePodParameter"),
256        }
257    }
258}
259
260//query
261#[skip_serializing_none]
262#[cfg_attr(feature = "builder", derive(Builder))]
263#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
264#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
265pub struct ListPodsParameter {
266    pub filters: Option<HashMap<String, Vec<String>>>,
267}
268
269#[cfg(any(test, feature = "examples"))]
270impl ExampleValues for ListPodsParameter {
271    fn example() -> Self {
272        let mut filter_map: HashMap<String, Vec<String>> = HashMap::new();
273        filter_map.insert(
274            String::from("label"),
275            vec![String::from("ListPodsParameter")],
276        );
277        Self {
278            filters: Some(filter_map),
279        }
280    }
281}
282
283/// Internal representation of `ListPodsParameter` since filters can't be serialized in a single step.
284/// It needs to be serialized to json, then to query. `TryInto` tries to perform the serialisation into json.
285#[skip_serializing_none]
286#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
287pub(crate) struct ListPodsParameterQuery {
288    pub filters: Option<String>,
289}
290
291impl TryFrom<ListPodsParameter> for ListPodsParameterQuery {
292    type Error = PodtenderError;
293    fn try_from(param: ListPodsParameter) -> Result<Self, Self::Error> {
294        let filters = utils::convert_from_map_to_json_string(param.filters)?;
295        Ok(ListPodsParameterQuery { filters })
296    }
297}
298
299#[skip_serializing_none]
300#[cfg_attr(feature = "builder", derive(Builder))]
301#[derive(Serialize, Deserialize, Debug, Default, Clone, Eq, PartialEq)]
302#[cfg_attr(feature = "builder", builder(default, setter(strip_option)))]
303pub struct PodStatsParameter {
304    pub all: Option<bool>,
305    #[serde(rename = "namesOrIDs")]
306    pub names_or_ids: Option<Vec<String>>,
307}
308
309#[cfg(any(test, feature = "examples"))]
310impl ExampleValues for PodStatsParameter {
311    fn example() -> Self {
312        Self {
313            all: Some(true),
314            names_or_ids: None,
315        }
316    }
317}