1pub mod vmid;
2pub struct LxcClient<T> {
3 client: T,
4 path: String,
5}
6impl<T> LxcClient<T>
7where
8 T: crate::client::Client,
9{
10 pub fn new(client: T, parent_path: &str) -> Self {
11 Self {
12 client,
13 path: format!("{}{}", parent_path, "/lxc"),
14 }
15 }
16}
17impl<T> LxcClient<T>
18where
19 T: crate::client::Client,
20{
21 #[doc = "LXC container index (per node)."]
22 pub fn get(&self) -> Result<Vec<GetOutputItems>, T::Error> {
23 let path = self.path.to_string();
24 self.client.get(&path, &())
25 }
26}
27impl<T> LxcClient<T>
28where
29 T: crate::client::Client,
30{
31 #[doc = "Create or restore a container."]
32 pub fn post(&self, params: PostParams) -> Result<String, T::Error> {
33 let path = self.path.to_string();
34 self.client.post(&path, ¶ms)
35 }
36}
37impl GetOutputItems {
38 pub fn new(status: Status, vmid: crate::types::VmId) -> Self {
39 Self {
40 status,
41 vmid,
42 cpus: Default::default(),
43 lock: Default::default(),
44 maxdisk: Default::default(),
45 maxmem: Default::default(),
46 maxswap: Default::default(),
47 name: Default::default(),
48 tags: Default::default(),
49 uptime: Default::default(),
50 additional_properties: Default::default(),
51 }
52 }
53}
54#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
55pub struct GetOutputItems {
56 #[serde(
57 serialize_with = "crate::types::serialize_number_optional",
58 deserialize_with = "crate::types::deserialize_number_optional"
59 )]
60 #[serde(skip_serializing_if = "Option::is_none", default)]
61 #[doc = "Maximum usable CPUs."]
62 pub cpus: Option<f64>,
63 #[serde(skip_serializing_if = "Option::is_none", default)]
64 #[doc = "The current config lock, if any."]
65 pub lock: Option<String>,
66 #[serde(
67 serialize_with = "crate::types::serialize_int_optional",
68 deserialize_with = "crate::types::deserialize_int_optional"
69 )]
70 #[serde(skip_serializing_if = "Option::is_none", default)]
71 #[doc = "Root disk size in bytes."]
72 pub maxdisk: Option<u64>,
73 #[serde(
74 serialize_with = "crate::types::serialize_int_optional",
75 deserialize_with = "crate::types::deserialize_int_optional"
76 )]
77 #[serde(skip_serializing_if = "Option::is_none", default)]
78 #[doc = "Maximum memory in bytes."]
79 pub maxmem: Option<u64>,
80 #[serde(
81 serialize_with = "crate::types::serialize_int_optional",
82 deserialize_with = "crate::types::deserialize_int_optional"
83 )]
84 #[serde(skip_serializing_if = "Option::is_none", default)]
85 #[doc = "Maximum SWAP memory in bytes."]
86 pub maxswap: Option<u64>,
87 #[serde(skip_serializing_if = "Option::is_none", default)]
88 #[doc = "Container name."]
89 pub name: Option<String>,
90 #[doc = "LXC Container status."]
91 pub status: Status,
92 #[serde(skip_serializing_if = "Option::is_none", default)]
93 #[doc = "The current configured tags, if any."]
94 pub tags: Option<String>,
95 #[serde(
96 serialize_with = "crate::types::serialize_int_optional",
97 deserialize_with = "crate::types::deserialize_int_optional"
98 )]
99 #[serde(skip_serializing_if = "Option::is_none", default)]
100 #[doc = "Uptime."]
101 pub uptime: Option<u64>,
102 #[doc = "The (unique) ID of the VM."]
103 pub vmid: crate::types::VmId,
104 #[serde(
105 flatten,
106 default,
107 skip_serializing_if = "::std::collections::HashMap::is_empty"
108 )]
109 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
110}
111impl PostParams {
112 pub fn new(ostemplate: String, vmid: crate::types::VmId) -> Self {
113 Self {
114 ostemplate,
115 vmid,
116 arch: Default::default(),
117 bwlimit: Default::default(),
118 cmode: Default::default(),
119 console: Default::default(),
120 cores: Default::default(),
121 cpulimit: Default::default(),
122 cpuunits: Default::default(),
123 debug: Default::default(),
124 description: Default::default(),
125 devs: Default::default(),
126 features: Default::default(),
127 force: Default::default(),
128 hookscript: Default::default(),
129 hostname: Default::default(),
130 ignore_unpack_errors: Default::default(),
131 lock: Default::default(),
132 memory: Default::default(),
133 mps: Default::default(),
134 nameserver: Default::default(),
135 nets: Default::default(),
136 onboot: Default::default(),
137 ostype: Default::default(),
138 password: Default::default(),
139 pool: Default::default(),
140 protection: Default::default(),
141 restore: Default::default(),
142 rootfs: Default::default(),
143 searchdomain: Default::default(),
144 ssh_public_keys: Default::default(),
145 start: Default::default(),
146 startup: Default::default(),
147 storage: Default::default(),
148 swap: Default::default(),
149 tags: Default::default(),
150 template: Default::default(),
151 timezone: Default::default(),
152 tty: Default::default(),
153 unique: Default::default(),
154 unprivileged: Default::default(),
155 unuseds: Default::default(),
156 additional_properties: Default::default(),
157 }
158 }
159}
160#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
161pub struct PostParams {
162 #[serde(skip_serializing_if = "Option::is_none", default)]
163 #[doc = "OS architecture type."]
164 pub arch: Option<Arch>,
165 #[serde(skip_serializing_if = "Option::is_none", default)]
166 #[doc = "Override I/O bandwidth limit (in KiB/s)."]
167 pub bwlimit: Option<()>,
168 #[serde(skip_serializing_if = "Option::is_none", default)]
169 #[doc = "Console mode. By default, the console command tries to open a connection to one of the available tty devices. By setting cmode to 'console' it tries to attach to /dev/console instead. If you set cmode to 'shell', it simply invokes a shell inside the container (no login)."]
170 pub cmode: Option<Cmode>,
171 #[serde(
172 serialize_with = "crate::types::serialize_bool_optional",
173 deserialize_with = "crate::types::deserialize_bool_optional"
174 )]
175 #[serde(skip_serializing_if = "Option::is_none", default)]
176 #[doc = "Attach a console device (/dev/console) to the container."]
177 pub console: Option<bool>,
178 #[serde(
179 serialize_with = "crate::types::serialize_int_optional",
180 deserialize_with = "crate::types::deserialize_int_optional"
181 )]
182 #[serde(skip_serializing_if = "Option::is_none", default)]
183 #[doc = "The number of cores assigned to the container. A container can use all available cores by default."]
184 pub cores: Option<u64>,
185 #[serde(
186 serialize_with = "crate::types::serialize_number_optional",
187 deserialize_with = "crate::types::deserialize_number_optional"
188 )]
189 #[serde(skip_serializing_if = "Option::is_none", default)]
190 #[doc = "Limit of CPU usage.\n\nNOTE: If the computer has 2 CPUs, it has a total of '2' CPU time. Value '0' indicates no CPU limit."]
191 pub cpulimit: Option<f64>,
192 #[serde(skip_serializing_if = "Option::is_none", default)]
193 #[doc = "CPU weight for a container, will be clamped to [1, 10000] in cgroup v2."]
194 #[doc = "CPU weight for a container. Argument is used in the kernel fair scheduler. The larger the number is, the more CPU time this container gets. Number is relative to the weights of all the other running guests."]
195 pub cpuunits: Option<()>,
196 #[serde(
197 serialize_with = "crate::types::serialize_bool_optional",
198 deserialize_with = "crate::types::deserialize_bool_optional"
199 )]
200 #[serde(skip_serializing_if = "Option::is_none", default)]
201 #[doc = "Try to be more verbose. For now this only enables debug log-level on start."]
202 pub debug: Option<bool>,
203 #[serde(skip_serializing_if = "Option::is_none", default)]
204 #[doc = "Description for the Container. Shown in the web-interface CT's summary. This is saved as comment inside the configuration file."]
205 pub description: Option<String>,
206 #[serde(rename = "dev[n]")]
207 #[serde(
208 serialize_with = "crate::types::serialize_multi::<NumberedDevs, _>",
209 deserialize_with = "crate::types::deserialize_multi::<NumberedDevs, _>"
210 )]
211 #[serde(skip_serializing_if = "::std::collections::HashMap::is_empty", default)]
212 #[serde(flatten)]
213 #[doc = "Device to pass through to the container"]
214 pub devs: ::std::collections::HashMap<u32, String>,
215 #[serde(skip_serializing_if = "Option::is_none", default)]
216 #[doc = "Allow containers access to advanced features."]
217 pub features: Option<String>,
218 #[serde(
219 serialize_with = "crate::types::serialize_bool_optional",
220 deserialize_with = "crate::types::deserialize_bool_optional"
221 )]
222 #[serde(skip_serializing_if = "Option::is_none", default)]
223 #[doc = "Allow to overwrite existing container."]
224 pub force: Option<bool>,
225 #[serde(skip_serializing_if = "Option::is_none", default)]
226 #[doc = "Script that will be exectued during various steps in the containers lifetime."]
227 pub hookscript: Option<String>,
228 #[serde(skip_serializing_if = "Option::is_none", default)]
229 #[doc = "Set a host name for the container."]
230 pub hostname: Option<String>,
231 #[serde(rename = "ignore-unpack-errors")]
232 #[serde(
233 serialize_with = "crate::types::serialize_bool_optional",
234 deserialize_with = "crate::types::deserialize_bool_optional"
235 )]
236 #[serde(skip_serializing_if = "Option::is_none", default)]
237 #[doc = "Ignore errors when extracting the template."]
238 pub ignore_unpack_errors: Option<bool>,
239 #[serde(skip_serializing_if = "Option::is_none", default)]
240 #[doc = "Lock/unlock the container."]
241 pub lock: Option<Lock>,
242 #[serde(
243 serialize_with = "crate::types::serialize_int_optional",
244 deserialize_with = "crate::types::deserialize_int_optional"
245 )]
246 #[serde(skip_serializing_if = "Option::is_none", default)]
247 #[doc = "Amount of RAM for the container in MB."]
248 pub memory: Option<u64>,
249 #[serde(rename = "mp[n]")]
250 #[serde(
251 serialize_with = "crate::types::serialize_multi::<NumberedMps, _>",
252 deserialize_with = "crate::types::deserialize_multi::<NumberedMps, _>"
253 )]
254 #[serde(skip_serializing_if = "::std::collections::HashMap::is_empty", default)]
255 #[serde(flatten)]
256 #[doc = "Use volume as container mount point. Use the special syntax STORAGE_ID:SIZE_IN_GiB to allocate a new volume."]
257 pub mps: ::std::collections::HashMap<u32, String>,
258 #[serde(skip_serializing_if = "Option::is_none", default)]
259 #[doc = "Sets DNS server IP address for a container. Create will automatically use the setting from the host if you neither set searchdomain nor nameserver."]
260 pub nameserver: Option<String>,
261 #[serde(rename = "net[n]")]
262 #[serde(
263 serialize_with = "crate::types::serialize_multi::<NumberedNets, _>",
264 deserialize_with = "crate::types::deserialize_multi::<NumberedNets, _>"
265 )]
266 #[serde(skip_serializing_if = "::std::collections::HashMap::is_empty", default)]
267 #[serde(flatten)]
268 #[doc = "Specifies network interfaces for the container."]
269 pub nets: ::std::collections::HashMap<u32, String>,
270 #[serde(
271 serialize_with = "crate::types::serialize_bool_optional",
272 deserialize_with = "crate::types::deserialize_bool_optional"
273 )]
274 #[serde(skip_serializing_if = "Option::is_none", default)]
275 #[doc = "Specifies whether a container will be started during system bootup."]
276 pub onboot: Option<bool>,
277 #[doc = "The OS template or backup file."]
278 pub ostemplate: String,
279 #[serde(skip_serializing_if = "Option::is_none", default)]
280 #[doc = "OS type. This is used to setup configuration inside the container, and corresponds to lxc setup scripts in /usr/share/lxc/config/\\<ostype\\>.common.conf. Value 'unmanaged' can be used to skip and OS specific setup."]
281 pub ostype: Option<Ostype>,
282 #[serde(skip_serializing_if = "Option::is_none", default)]
283 #[doc = "Sets root password inside container."]
284 pub password: Option<String>,
285 #[serde(skip_serializing_if = "Option::is_none", default)]
286 #[doc = "Add the VM to the specified pool."]
287 pub pool: Option<String>,
288 #[serde(
289 serialize_with = "crate::types::serialize_bool_optional",
290 deserialize_with = "crate::types::deserialize_bool_optional"
291 )]
292 #[serde(skip_serializing_if = "Option::is_none", default)]
293 #[doc = "Sets the protection flag of the container. This will prevent the CT or CT's disk remove/update operation."]
294 pub protection: Option<bool>,
295 #[serde(
296 serialize_with = "crate::types::serialize_bool_optional",
297 deserialize_with = "crate::types::deserialize_bool_optional"
298 )]
299 #[serde(skip_serializing_if = "Option::is_none", default)]
300 #[doc = "Mark this as restore task."]
301 pub restore: Option<bool>,
302 #[serde(skip_serializing_if = "Option::is_none", default)]
303 #[doc = "Use volume as container root."]
304 pub rootfs: Option<String>,
305 #[serde(skip_serializing_if = "Option::is_none", default)]
306 #[doc = "Sets DNS search domains for a container. Create will automatically use the setting from the host if you neither set searchdomain nor nameserver."]
307 pub searchdomain: Option<String>,
308 #[serde(rename = "ssh-public-keys")]
309 #[serde(skip_serializing_if = "Option::is_none", default)]
310 #[doc = "Setup public SSH keys (one key per line, OpenSSH format)."]
311 pub ssh_public_keys: Option<String>,
312 #[serde(
313 serialize_with = "crate::types::serialize_bool_optional",
314 deserialize_with = "crate::types::deserialize_bool_optional"
315 )]
316 #[serde(skip_serializing_if = "Option::is_none", default)]
317 #[doc = "Start the CT after its creation finished successfully."]
318 pub start: Option<bool>,
319 #[serde(skip_serializing_if = "Option::is_none", default)]
320 #[doc = "Startup and shutdown behavior. Order is a non-negative number defining the general startup order. Shutdown in done with reverse ordering. Additionally you can set the 'up' or 'down' delay in seconds, which specifies a delay to wait before the next VM is started or stopped."]
321 pub startup: Option<String>,
322 #[serde(skip_serializing_if = "Option::is_none", default)]
323 #[doc = "Default Storage."]
324 pub storage: Option<String>,
325 #[serde(
326 serialize_with = "crate::types::serialize_int_optional",
327 deserialize_with = "crate::types::deserialize_int_optional"
328 )]
329 #[serde(skip_serializing_if = "Option::is_none", default)]
330 #[doc = "Amount of SWAP for the container in MB."]
331 pub swap: Option<u64>,
332 #[serde(skip_serializing_if = "Option::is_none", default)]
333 #[doc = "Tags of the Container. This is only meta information."]
334 pub tags: Option<String>,
335 #[serde(
336 serialize_with = "crate::types::serialize_bool_optional",
337 deserialize_with = "crate::types::deserialize_bool_optional"
338 )]
339 #[serde(skip_serializing_if = "Option::is_none", default)]
340 #[doc = "Enable/disable Template."]
341 pub template: Option<bool>,
342 #[serde(skip_serializing_if = "Option::is_none", default)]
343 #[doc = "Time zone to use in the container. If option isn't set, then nothing will be done. Can be set to 'host' to match the host time zone, or an arbitrary time zone option from /usr/share/zoneinfo/zone.tab"]
344 pub timezone: Option<String>,
345 #[serde(
346 serialize_with = "crate::types::serialize_int_optional",
347 deserialize_with = "crate::types::deserialize_int_optional"
348 )]
349 #[serde(skip_serializing_if = "Option::is_none", default)]
350 #[doc = "Specify the number of tty available to the container"]
351 pub tty: Option<u64>,
352 #[serde(
353 serialize_with = "crate::types::serialize_bool_optional",
354 deserialize_with = "crate::types::deserialize_bool_optional"
355 )]
356 #[serde(skip_serializing_if = "Option::is_none", default)]
357 #[doc = "Assign a unique random ethernet address."]
358 pub unique: Option<bool>,
359 #[serde(
360 serialize_with = "crate::types::serialize_bool_optional",
361 deserialize_with = "crate::types::deserialize_bool_optional"
362 )]
363 #[serde(skip_serializing_if = "Option::is_none", default)]
364 #[doc = "Makes the container run as unprivileged user. (Should not be modified manually.)"]
365 pub unprivileged: Option<bool>,
366 #[serde(rename = "unused[n]")]
367 #[serde(
368 serialize_with = "crate::types::serialize_multi::<NumberedUnuseds, _>",
369 deserialize_with = "crate::types::deserialize_multi::<NumberedUnuseds, _>"
370 )]
371 #[serde(skip_serializing_if = "::std::collections::HashMap::is_empty", default)]
372 #[serde(flatten)]
373 #[doc = "Reference to unused volumes. This is used internally, and should not be modified manually."]
374 pub unuseds: ::std::collections::HashMap<u32, String>,
375 #[doc = "The (unique) ID of the VM."]
376 pub vmid: crate::types::VmId,
377 #[serde(
378 flatten,
379 deserialize_with = "crate::types::multi::deserialize_additional_data::<'_, PostParams, _, _>"
380 )]
381 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
382}
383impl crate::types::multi::Test for PostParams {
384 fn test_fn() -> fn(&str) -> bool {
385 fn the_test(input: &str) -> bool {
386 let array = [
387 <NumberedDevs as crate::types::multi::NumberedItems>::key_matches
388 as fn(&str) -> bool,
389 <NumberedMps as crate::types::multi::NumberedItems>::key_matches
390 as fn(&str) -> bool,
391 <NumberedNets as crate::types::multi::NumberedItems>::key_matches
392 as fn(&str) -> bool,
393 <NumberedUnuseds as crate::types::multi::NumberedItems>::key_matches
394 as fn(&str) -> bool,
395 ];
396 array.iter().any(|f| f(input))
397 }
398 the_test as _
399 }
400}
401#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
402pub enum Arch {
403 #[serde(rename = "amd64")]
404 Amd64,
405 #[serde(rename = "arm64")]
406 Arm64,
407 #[serde(rename = "armhf")]
408 Armhf,
409 #[serde(rename = "i386")]
410 I386,
411 #[serde(rename = "riscv32")]
412 Riscv32,
413 #[serde(rename = "riscv64")]
414 Riscv64,
415}
416impl Default for Arch {
417 fn default() -> Self {
418 Self::Amd64
419 }
420}
421#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
422pub enum Cmode {
423 #[serde(rename = "console")]
424 Console,
425 #[serde(rename = "shell")]
426 Shell,
427 #[serde(rename = "tty")]
428 Tty,
429}
430impl Default for Cmode {
431 fn default() -> Self {
432 Self::Tty
433 }
434}
435#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
436pub enum Lock {
437 #[serde(rename = "backup")]
438 Backup,
439 #[serde(rename = "create")]
440 Create,
441 #[serde(rename = "destroyed")]
442 Destroyed,
443 #[serde(rename = "disk")]
444 Disk,
445 #[serde(rename = "fstrim")]
446 Fstrim,
447 #[serde(rename = "migrate")]
448 Migrate,
449 #[serde(rename = "mounted")]
450 Mounted,
451 #[serde(rename = "rollback")]
452 Rollback,
453 #[serde(rename = "snapshot")]
454 Snapshot,
455 #[serde(rename = "snapshot-delete")]
456 SnapshotDelete,
457}
458#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
459pub enum Ostype {
460 #[serde(rename = "alpine")]
461 Alpine,
462 #[serde(rename = "archlinux")]
463 Archlinux,
464 #[serde(rename = "centos")]
465 Centos,
466 #[serde(rename = "debian")]
467 Debian,
468 #[serde(rename = "devuan")]
469 Devuan,
470 #[serde(rename = "fedora")]
471 Fedora,
472 #[serde(rename = "gentoo")]
473 Gentoo,
474 #[serde(rename = "nixos")]
475 Nixos,
476 #[serde(rename = "opensuse")]
477 Opensuse,
478 #[serde(rename = "ubuntu")]
479 Ubuntu,
480 #[serde(rename = "unmanaged")]
481 Unmanaged,
482}
483#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
484pub enum Status {
485 #[serde(rename = "running")]
486 Running,
487 #[serde(rename = "stopped")]
488 Stopped,
489}
490#[derive(Default)]
491struct NumberedDevs;
492impl crate::types::multi::NumberedItems for NumberedDevs {
493 type Item = String;
494 const PREFIX: &'static str = "dev";
495}
496#[derive(Default)]
497struct NumberedMps;
498impl crate::types::multi::NumberedItems for NumberedMps {
499 type Item = String;
500 const PREFIX: &'static str = "mp";
501}
502#[derive(Default)]
503struct NumberedNets;
504impl crate::types::multi::NumberedItems for NumberedNets {
505 type Item = String;
506 const PREFIX: &'static str = "net";
507}
508#[derive(Default)]
509struct NumberedUnuseds;
510impl crate::types::multi::NumberedItems for NumberedUnuseds {
511 type Item = String;
512 const PREFIX: &'static str = "unused";
513}
514impl<T> LxcClient<T>
515where
516 T: crate::client::Client,
517{
518 pub fn vmid(&self, vmid: crate::types::VmId) -> vmid::VmidClient<T> {
519 vmid::VmidClient::<T>::new(self.client.clone(), &self.path, vmid)
520 }
521}