proxmox_api/generated/cluster/ha/rules/
rule.rs1#[derive(Debug, Clone)]
2pub struct RuleClient<T> {
3 client: T,
4 path: String,
5}
6impl<T> RuleClient<T>
7where
8 T: crate::client::Client,
9{
10 pub fn new(client: T, parent_path: &str, rule: &str) -> Self {
11 Self {
12 client,
13 path: format!("{}/{}", parent_path, rule),
14 }
15 }
16}
17impl<T> RuleClient<T>
18where
19 T: crate::client::Client,
20{
21 #[doc = "Delete HA rule."]
22 #[doc = ""]
23 #[doc = "Permission check: perm(\"/\", [\"Sys.Console\"])"]
24 pub async fn delete(&self) -> Result<(), T::Error> {
25 let path = self.path.to_string();
26 self.client.delete(&path, &()).await
27 }
28}
29impl<T> RuleClient<T>
30where
31 T: crate::client::Client,
32{
33 #[doc = "Read HA rule."]
34 #[doc = ""]
35 #[doc = "Permission check: perm(\"/\", [\"Sys.Audit\"])"]
36 pub async fn get(&self) -> Result<GetOutput, T::Error> {
37 let path = self.path.to_string();
38 self.client.get(&path, &()).await
39 }
40}
41impl<T> RuleClient<T>
42where
43 T: crate::client::Client,
44{
45 #[doc = "Update HA rule."]
46 #[doc = ""]
47 #[doc = "Permission check: perm(\"/\", [\"Sys.Console\"])"]
48 pub async fn put(&self, params: PutParams) -> Result<(), T::Error> {
49 let path = self.path.to_string();
50 self.client.put(&path, ¶ms).await
51 }
52}
53impl GetOutput {
54 pub fn new(rule: String, ty: Type) -> Self {
55 Self {
56 rule,
57 ty,
58 additional_properties: ::std::default::Default::default(),
59 }
60 }
61}
62#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
63pub struct GetOutput {
64 #[doc = "HA rule identifier."]
65 #[doc = ""]
66 pub rule: String,
67 #[serde(rename = "type")]
68 #[doc = "HA rule type."]
69 #[doc = ""]
70 pub ty: Type,
71 #[serde(
72 flatten,
73 default,
74 skip_serializing_if = "::std::collections::HashMap::is_empty"
75 )]
76 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
77}
78impl PutParams {
79 pub fn new(ty: Type) -> Self {
80 Self {
81 ty,
82 affinity: ::std::default::Default::default(),
83 comment: ::std::default::Default::default(),
84 delete: ::std::default::Default::default(),
85 digest: ::std::default::Default::default(),
86 disable: ::std::default::Default::default(),
87 nodes: ::std::default::Default::default(),
88 resources: ::std::default::Default::default(),
89 strict: ::std::default::Default::default(),
90 additional_properties: ::std::default::Default::default(),
91 }
92 }
93}
94#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
95pub struct PutParams {
96 #[serde(skip_serializing_if = "Option::is_none", default)]
97 #[doc = "Describes whether the HA resources are supposed to be kept on the same node ('positive'), or are supposed to be kept on separate nodes ('negative')."]
98 #[doc = ""]
99 pub affinity: Option<Affinity>,
100 #[serde(skip_serializing_if = "Option::is_none", default)]
101 #[doc = "HA rule description."]
102 #[doc = ""]
103 pub comment: Option<CommentStr>,
104 #[serde(skip_serializing_if = "Option::is_none", default)]
105 #[doc = "A list of settings you want to delete."]
106 #[doc = ""]
107 pub delete: Option<DeleteStr>,
108 #[serde(skip_serializing_if = "Option::is_none", default)]
109 #[doc = "Prevent changes if current configuration file has a different digest. This can be used to prevent concurrent modifications."]
110 #[doc = ""]
111 pub digest: Option<DigestStr>,
112 #[serde(
113 serialize_with = "crate::types::serialize_bool_optional",
114 deserialize_with = "crate::types::deserialize_bool_optional"
115 )]
116 #[serde(skip_serializing_if = "Option::is_none", default)]
117 #[doc = "Whether the HA rule is disabled."]
118 #[doc = ""]
119 pub disable: Option<bool>,
120 #[serde(skip_serializing_if = "Option::is_none", default)]
121 #[doc = "List of cluster node names with optional priority."]
122 #[doc = ""]
123 #[doc = "List of cluster node members, where a priority can be given to each node. A resource will run on the available nodes with the highest priority. If there are more nodes in the highest priority class, the resources will get distributed to those nodes. The priorities have a relative meaning only. The higher the number, the higher the priority."]
124 #[doc = ""]
125 pub nodes: Option<String>,
126 #[serde(skip_serializing_if = "Option::is_none", default)]
127 #[doc = "List of HA resource IDs. This consists of a list of resource types followed by a resource specific name separated with a colon (example: vm:100,ct:101)."]
128 #[doc = ""]
129 pub resources: Option<String>,
130 #[serde(
131 serialize_with = "crate::types::serialize_bool_optional",
132 deserialize_with = "crate::types::deserialize_bool_optional"
133 )]
134 #[serde(skip_serializing_if = "Option::is_none", default)]
135 #[doc = "Describes whether the node affinity rule is strict or non-strict."]
136 #[doc = ""]
137 #[doc = "Describes whether the node affinity rule is strict or non-strict."]
138 #[doc = ""]
139 #[doc = "A non-strict node affinity rule makes resources prefer to be on the defined nodes."]
140 #[doc = ""]
141 #[doc = "If none of the defined nodes are available, the resource may run on any other node."]
142 #[doc = ""]
143 #[doc = "A strict node affinity rule makes resources be restricted to the defined nodes. If"]
144 #[doc = ""]
145 #[doc = "none of the defined nodes are available, the resource will be stopped."]
146 #[doc = ""]
147 pub strict: Option<bool>,
148 #[serde(rename = "type")]
149 #[doc = "HA rule type."]
150 #[doc = ""]
151 pub ty: Type,
152 #[serde(
153 flatten,
154 default,
155 skip_serializing_if = "::std::collections::HashMap::is_empty"
156 )]
157 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
158}
159#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
160#[doc = "Describes whether the HA resources are supposed to be kept on the same node ('positive'), or are supposed to be kept on separate nodes ('negative')."]
161#[doc = ""]
162pub enum Affinity {
163 #[serde(rename = "negative")]
164 Negative,
165 #[serde(rename = "positive")]
166 Positive,
167}
168impl TryFrom<&str> for Affinity {
169 type Error = String;
170 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
171 match value {
172 "negative" => Ok(Self::Negative),
173 "positive" => Ok(Self::Positive),
174 v => Err(format!("Unknown variant {v}")),
175 }
176 }
177}
178#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
179#[doc = "HA rule type."]
180#[doc = ""]
181pub enum Type {
182 #[serde(rename = "node-affinity")]
183 NodeAffinity,
184 #[serde(rename = "resource-affinity")]
185 ResourceAffinity,
186}
187impl TryFrom<&str> for Type {
188 type Error = String;
189 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
190 match value {
191 "node-affinity" => Ok(Self::NodeAffinity),
192 "resource-affinity" => Ok(Self::ResourceAffinity),
193 v => Err(format!("Unknown variant {v}")),
194 }
195 }
196}
197#[derive(Debug, Clone, PartialEq, PartialOrd)]
198pub struct CommentStr {
199 value: String,
200}
201impl crate::types::bounded_string::BoundedString for CommentStr {
202 const MIN_LENGTH: Option<usize> = None::<usize>;
203 const MAX_LENGTH: Option<usize> = Some(4096usize);
204 const DEFAULT: Option<&'static str> = None::<&'static str>;
205 const PATTERN: Option<&'static str> = None::<&'static str>;
206 const TYPE_DESCRIPTION: &'static str = "a string with length at most 4096";
207 fn get_value(&self) -> &str {
208 &self.value
209 }
210 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
211 Self::validate(&value)?;
212 Ok(Self { value })
213 }
214}
215impl std::convert::TryFrom<String> for CommentStr {
216 type Error = crate::types::bounded_string::BoundedStringError;
217 fn try_from(value: String) -> Result<Self, Self::Error> {
218 crate::types::bounded_string::BoundedString::new(value)
219 }
220}
221impl ::serde::Serialize for CommentStr {
222 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
223 where
224 S: ::serde::Serializer,
225 {
226 crate::types::bounded_string::serialize_bounded_string(self, serializer)
227 }
228}
229impl<'de> ::serde::Deserialize<'de> for CommentStr {
230 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
231 where
232 D: ::serde::Deserializer<'de>,
233 {
234 crate::types::bounded_string::deserialize_bounded_string(deserializer)
235 }
236}
237#[derive(Debug, Clone, PartialEq, PartialOrd)]
238pub struct DeleteStr {
239 value: String,
240}
241impl crate::types::bounded_string::BoundedString for DeleteStr {
242 const MIN_LENGTH: Option<usize> = None::<usize>;
243 const MAX_LENGTH: Option<usize> = Some(4096usize);
244 const DEFAULT: Option<&'static str> = None::<&'static str>;
245 const PATTERN: Option<&'static str> = None::<&'static str>;
246 const TYPE_DESCRIPTION: &'static str = "a string with length at most 4096";
247 fn get_value(&self) -> &str {
248 &self.value
249 }
250 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
251 Self::validate(&value)?;
252 Ok(Self { value })
253 }
254}
255impl std::convert::TryFrom<String> for DeleteStr {
256 type Error = crate::types::bounded_string::BoundedStringError;
257 fn try_from(value: String) -> Result<Self, Self::Error> {
258 crate::types::bounded_string::BoundedString::new(value)
259 }
260}
261impl ::serde::Serialize for DeleteStr {
262 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
263 where
264 S: ::serde::Serializer,
265 {
266 crate::types::bounded_string::serialize_bounded_string(self, serializer)
267 }
268}
269impl<'de> ::serde::Deserialize<'de> for DeleteStr {
270 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
271 where
272 D: ::serde::Deserializer<'de>,
273 {
274 crate::types::bounded_string::deserialize_bounded_string(deserializer)
275 }
276}
277#[derive(Debug, Clone, PartialEq, PartialOrd)]
278pub struct DigestStr {
279 value: String,
280}
281impl crate::types::bounded_string::BoundedString for DigestStr {
282 const MIN_LENGTH: Option<usize> = None::<usize>;
283 const MAX_LENGTH: Option<usize> = Some(64usize);
284 const DEFAULT: Option<&'static str> = None::<&'static str>;
285 const PATTERN: Option<&'static str> = None::<&'static str>;
286 const TYPE_DESCRIPTION: &'static str = "a string with length at most 64";
287 fn get_value(&self) -> &str {
288 &self.value
289 }
290 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
291 Self::validate(&value)?;
292 Ok(Self { value })
293 }
294}
295impl std::convert::TryFrom<String> for DigestStr {
296 type Error = crate::types::bounded_string::BoundedStringError;
297 fn try_from(value: String) -> Result<Self, Self::Error> {
298 crate::types::bounded_string::BoundedString::new(value)
299 }
300}
301impl ::serde::Serialize for DigestStr {
302 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
303 where
304 S: ::serde::Serializer,
305 {
306 crate::types::bounded_string::serialize_bounded_string(self, serializer)
307 }
308}
309impl<'de> ::serde::Deserialize<'de> for DigestStr {
310 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
311 where
312 D: ::serde::Deserializer<'de>,
313 {
314 crate::types::bounded_string::deserialize_bounded_string(deserializer)
315 }
316}