proxmox_api/generated/nodes/node/qemu/vmid/
clone.rs1#[derive(Debug, Clone)]
2pub struct CloneClient<T> {
3 client: T,
4 path: String,
5}
6impl<T> CloneClient<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, "/clone"),
14 }
15 }
16}
17impl<T> CloneClient<T>
18where
19 T: crate::client::Client,
20{
21 #[doc = "Create a copy of virtual machine/template."]
22 #[doc = ""]
23 #[doc = "Permission check: and(perm(\"/vms/{vmid}\", [\"VM.Clone\"]), or(perm(\"/vms/{newid}\", [\"VM.Allocate\"]), perm(\"/pool/{pool}\", [\"VM.Allocate\"], require_param=\"pool\")))"]
24 #[doc = "You need 'VM.Clone' permissions on /vms/{vmid}, and 'VM.Allocate' permissions on /vms/{newid} (or on the VM pool /pool/{pool}). You also need 'Datastore.AllocateSpace' on any used storage and 'SDN.Use' on any used bridge/vnet"]
25 pub async fn post(&self, params: PostParams) -> Result<String, T::Error> {
26 let path = self.path.to_string();
27 self.client.post(&path, ¶ms).await
28 }
29}
30impl PostParams {
31 pub fn new(newid: NewidInt) -> Self {
32 Self {
33 newid,
34 bwlimit: ::std::default::Default::default(),
35 description: ::std::default::Default::default(),
36 format: ::std::default::Default::default(),
37 full: ::std::default::Default::default(),
38 name: ::std::default::Default::default(),
39 pool: ::std::default::Default::default(),
40 snapname: ::std::default::Default::default(),
41 storage: ::std::default::Default::default(),
42 target: ::std::default::Default::default(),
43 additional_properties: ::std::default::Default::default(),
44 }
45 }
46}
47#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
48pub struct PostParams {
49 #[serde(
50 serialize_with = "crate::types::serialize_unsigned_int_optional",
51 deserialize_with = "crate::types::deserialize_unsigned_int_optional"
52 )]
53 #[serde(skip_serializing_if = "Option::is_none", default)]
54 #[doc = "Override I/O bandwidth limit (in KiB/s)."]
55 #[doc = ""]
56 pub bwlimit: Option<u64>,
57 #[serde(skip_serializing_if = "Option::is_none", default)]
58 #[doc = "Description for the new VM."]
59 #[doc = ""]
60 pub description: Option<String>,
61 #[serde(skip_serializing_if = "Option::is_none", default)]
62 #[doc = "Target format for file storage. Only valid for full clone."]
63 #[doc = ""]
64 pub format: Option<Format>,
65 #[serde(
66 serialize_with = "crate::types::serialize_bool_optional",
67 deserialize_with = "crate::types::deserialize_bool_optional"
68 )]
69 #[serde(skip_serializing_if = "Option::is_none", default)]
70 #[doc = "Create a full copy of all disks. This is always done when you clone a normal VM. For VM templates, we try to create a linked clone by default."]
71 #[doc = ""]
72 pub full: Option<bool>,
73 #[serde(skip_serializing_if = "Option::is_none", default)]
74 #[doc = "Set a name for the new VM."]
75 #[doc = ""]
76 pub name: Option<String>,
77 #[doc = "VMID for the clone."]
78 #[doc = ""]
79 pub newid: NewidInt,
80 #[serde(skip_serializing_if = "Option::is_none", default)]
81 #[doc = "Add the new VM to the specified pool."]
82 #[doc = ""]
83 pub pool: Option<String>,
84 #[serde(skip_serializing_if = "Option::is_none", default)]
85 #[doc = "The name of the snapshot."]
86 #[doc = ""]
87 pub snapname: Option<SnapnameStr>,
88 #[serde(skip_serializing_if = "Option::is_none", default)]
89 #[doc = "Target storage for full clone."]
90 #[doc = ""]
91 pub storage: Option<String>,
92 #[serde(skip_serializing_if = "Option::is_none", default)]
93 #[doc = "Target node. Only allowed if the original VM is on shared storage."]
94 #[doc = ""]
95 pub target: Option<String>,
96 #[serde(
97 flatten,
98 default,
99 skip_serializing_if = "::std::collections::HashMap::is_empty"
100 )]
101 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
102}
103#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
104#[doc = "Target format for file storage. Only valid for full clone."]
105#[doc = ""]
106pub enum Format {
107 #[serde(rename = "qcow2")]
108 Qcow2,
109 #[serde(rename = "raw")]
110 Raw,
111 #[serde(rename = "vmdk")]
112 Vmdk,
113}
114impl TryFrom<&str> for Format {
115 type Error = String;
116 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
117 match value {
118 "qcow2" => Ok(Self::Qcow2),
119 "raw" => Ok(Self::Raw),
120 "vmdk" => Ok(Self::Vmdk),
121 v => Err(format!("Unknown variant {v}")),
122 }
123 }
124}
125#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
126pub struct NewidInt(i128);
127impl crate::types::bounded_integer::BoundedInteger for NewidInt {
128 const MIN: Option<i128> = Some(100i128);
129 const MAX: Option<i128> = Some(999999999i128);
130 const DEFAULT: Option<i128> = None::<i128>;
131 const TYPE_DESCRIPTION: &'static str = "an integer between 100 and 999999999";
132 fn get(&self) -> i128 {
133 self.0
134 }
135 fn new(value: i128) -> Result<Self, crate::types::bounded_integer::BoundedIntegerError> {
136 Self::validate(value)?;
137 Ok(Self(value))
138 }
139}
140impl std::convert::TryFrom<i128> for NewidInt {
141 type Error = crate::types::bounded_integer::BoundedIntegerError;
142 fn try_from(value: i128) -> Result<Self, Self::Error> {
143 crate::types::bounded_integer::BoundedInteger::new(value)
144 }
145}
146impl ::serde::Serialize for NewidInt {
147 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
148 where
149 S: ::serde::Serializer,
150 {
151 crate::types::bounded_integer::serialize_bounded_integer(self, serializer)
152 }
153}
154impl<'de> ::serde::Deserialize<'de> for NewidInt {
155 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
156 where
157 D: ::serde::Deserializer<'de>,
158 {
159 crate::types::bounded_integer::deserialize_bounded_integer(deserializer)
160 }
161}
162#[derive(Debug, Clone, PartialEq, PartialOrd)]
163pub struct SnapnameStr {
164 value: String,
165}
166impl crate::types::bounded_string::BoundedString for SnapnameStr {
167 const MIN_LENGTH: Option<usize> = None::<usize>;
168 const MAX_LENGTH: Option<usize> = Some(40usize);
169 const DEFAULT: Option<&'static str> = None::<&'static str>;
170 const PATTERN: Option<&'static str> = None::<&'static str>;
171 const TYPE_DESCRIPTION: &'static str = "a string with length at most 40";
172 fn get_value(&self) -> &str {
173 &self.value
174 }
175 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
176 Self::validate(&value)?;
177 Ok(Self { value })
178 }
179}
180impl std::convert::TryFrom<String> for SnapnameStr {
181 type Error = crate::types::bounded_string::BoundedStringError;
182 fn try_from(value: String) -> Result<Self, Self::Error> {
183 crate::types::bounded_string::BoundedString::new(value)
184 }
185}
186impl ::serde::Serialize for SnapnameStr {
187 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
188 where
189 S: ::serde::Serializer,
190 {
191 crate::types::bounded_string::serialize_bounded_string(self, serializer)
192 }
193}
194impl<'de> ::serde::Deserialize<'de> for SnapnameStr {
195 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
196 where
197 D: ::serde::Deserializer<'de>,
198 {
199 crate::types::bounded_string::deserialize_bounded_string(deserializer)
200 }
201}