proxmox_api/generated/cluster/ha/
rules.rs1pub mod rule;
2#[derive(Debug, Clone)]
3pub struct RulesClient<T> {
4 client: T,
5 path: String,
6}
7impl<T> RulesClient<T>
8where
9 T: crate::client::Client,
10{
11 pub fn new(client: T, parent_path: &str) -> Self {
12 Self {
13 client,
14 path: format!("{}{}", parent_path, "/rules"),
15 }
16 }
17}
18impl<T> RulesClient<T>
19where
20 T: crate::client::Client,
21{
22 #[doc = "Get HA rules."]
23 #[doc = ""]
24 #[doc = "Permission check: perm(\"/\", [\"Sys.Audit\"])"]
25 pub async fn get(&self, params: GetParams) -> Result<Vec<GetOutputItems>, T::Error> {
26 let path = self.path.to_string();
27 let optional_vec: Option<Vec<GetOutputItems>> = self.client.get(&path, ¶ms).await?;
28 Ok(optional_vec.unwrap_or_default())
29 }
30}
31impl<T> RulesClient<T>
32where
33 T: crate::client::Client,
34{
35 #[doc = "Create HA rule."]
36 #[doc = ""]
37 #[doc = "Permission check: perm(\"/\", [\"Sys.Console\"])"]
38 pub async fn post(&self, params: PostParams) -> Result<(), T::Error> {
39 let path = self.path.to_string();
40 self.client.post(&path, ¶ms).await
41 }
42}
43impl GetOutputItems {
44 pub fn new(rule: String) -> Self {
45 Self {
46 rule,
47 additional_properties: ::std::default::Default::default(),
48 }
49 }
50}
51#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize)]
52pub struct GetOutputItems {
53 pub rule: String,
54 #[serde(
55 flatten,
56 default,
57 skip_serializing_if = "::std::collections::HashMap::is_empty"
58 )]
59 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
60}
61#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, Default)]
62pub struct GetParams {
63 #[serde(skip_serializing_if = "Option::is_none", default)]
64 #[doc = "Limit the returned list to rules affecting the specified resource."]
65 #[doc = ""]
66 pub resource: Option<String>,
67 #[serde(rename = "type")]
68 #[serde(skip_serializing_if = "Option::is_none", default)]
69 #[doc = "Limit the returned list to the specified rule type."]
70 #[doc = ""]
71 pub ty: Option<Type>,
72 #[serde(
73 flatten,
74 default,
75 skip_serializing_if = "::std::collections::HashMap::is_empty"
76 )]
77 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
78}
79impl PostParams {
80 pub fn new(resources: String, rule: String, ty: Type) -> Self {
81 Self {
82 resources,
83 rule,
84 ty,
85 affinity: ::std::default::Default::default(),
86 comment: ::std::default::Default::default(),
87 disable: ::std::default::Default::default(),
88 nodes: ::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 PostParams {
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(
105 serialize_with = "crate::types::serialize_bool_optional",
106 deserialize_with = "crate::types::deserialize_bool_optional"
107 )]
108 #[serde(skip_serializing_if = "Option::is_none", default)]
109 #[doc = "Whether the HA rule is disabled."]
110 #[doc = ""]
111 pub disable: Option<bool>,
112 #[serde(skip_serializing_if = "Option::is_none", default)]
113 #[doc = "List of cluster node names with optional priority."]
114 #[doc = ""]
115 #[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."]
116 #[doc = ""]
117 pub nodes: Option<String>,
118 #[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)."]
119 #[doc = ""]
120 pub resources: String,
121 #[doc = "HA rule identifier."]
122 #[doc = ""]
123 pub rule: String,
124 #[serde(
125 serialize_with = "crate::types::serialize_bool_optional",
126 deserialize_with = "crate::types::deserialize_bool_optional"
127 )]
128 #[serde(skip_serializing_if = "Option::is_none", default)]
129 #[doc = "Describes whether the node affinity rule is strict or non-strict."]
130 #[doc = ""]
131 #[doc = "Describes whether the node affinity rule is strict or non-strict."]
132 #[doc = ""]
133 #[doc = "A non-strict node affinity rule makes resources prefer to be on the defined nodes."]
134 #[doc = ""]
135 #[doc = "If none of the defined nodes are available, the resource may run on any other node."]
136 #[doc = ""]
137 #[doc = "A strict node affinity rule makes resources be restricted to the defined nodes. If"]
138 #[doc = ""]
139 #[doc = "none of the defined nodes are available, the resource will be stopped."]
140 #[doc = ""]
141 pub strict: Option<bool>,
142 #[serde(rename = "type")]
143 #[doc = "HA rule type."]
144 #[doc = ""]
145 pub ty: Type,
146 #[serde(
147 flatten,
148 default,
149 skip_serializing_if = "::std::collections::HashMap::is_empty"
150 )]
151 pub additional_properties: ::std::collections::HashMap<String, ::serde_json::Value>,
152}
153#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
154#[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')."]
155#[doc = ""]
156pub enum Affinity {
157 #[serde(rename = "negative")]
158 Negative,
159 #[serde(rename = "positive")]
160 Positive,
161}
162impl TryFrom<&str> for Affinity {
163 type Error = String;
164 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
165 match value {
166 "negative" => Ok(Self::Negative),
167 "positive" => Ok(Self::Positive),
168 v => Err(format!("Unknown variant {v}")),
169 }
170 }
171}
172#[derive(Clone, Debug, :: serde :: Serialize, :: serde :: Deserialize, PartialEq)]
173#[doc = "Limit the returned list to the specified rule type."]
174#[doc = ""]
175pub enum Type {
176 #[serde(rename = "node-affinity")]
177 NodeAffinity,
178 #[serde(rename = "resource-affinity")]
179 ResourceAffinity,
180}
181impl TryFrom<&str> for Type {
182 type Error = String;
183 fn try_from(value: &str) -> Result<Self, <Self as TryFrom<&str>>::Error> {
184 match value {
185 "node-affinity" => Ok(Self::NodeAffinity),
186 "resource-affinity" => Ok(Self::ResourceAffinity),
187 v => Err(format!("Unknown variant {v}")),
188 }
189 }
190}
191#[derive(Debug, Clone, PartialEq, PartialOrd)]
192pub struct CommentStr {
193 value: String,
194}
195impl crate::types::bounded_string::BoundedString for CommentStr {
196 const MIN_LENGTH: Option<usize> = None::<usize>;
197 const MAX_LENGTH: Option<usize> = Some(4096usize);
198 const DEFAULT: Option<&'static str> = None::<&'static str>;
199 const PATTERN: Option<&'static str> = None::<&'static str>;
200 const TYPE_DESCRIPTION: &'static str = "a string with length at most 4096";
201 fn get_value(&self) -> &str {
202 &self.value
203 }
204 fn new(value: String) -> Result<Self, crate::types::bounded_string::BoundedStringError> {
205 Self::validate(&value)?;
206 Ok(Self { value })
207 }
208}
209impl std::convert::TryFrom<String> for CommentStr {
210 type Error = crate::types::bounded_string::BoundedStringError;
211 fn try_from(value: String) -> Result<Self, Self::Error> {
212 crate::types::bounded_string::BoundedString::new(value)
213 }
214}
215impl ::serde::Serialize for CommentStr {
216 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
217 where
218 S: ::serde::Serializer,
219 {
220 crate::types::bounded_string::serialize_bounded_string(self, serializer)
221 }
222}
223impl<'de> ::serde::Deserialize<'de> for CommentStr {
224 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
225 where
226 D: ::serde::Deserializer<'de>,
227 {
228 crate::types::bounded_string::deserialize_bounded_string(deserializer)
229 }
230}
231impl<T> RulesClient<T>
232where
233 T: crate::client::Client,
234{
235 pub fn rule(&self, rule: &str) -> rule::RuleClient<T> {
236 rule::RuleClient::<T>::new(self.client.clone(), &self.path, rule)
237 }
238}