1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*
* Proxmox Virtual Environment API
*
* Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
*
* The version of the OpenAPI document: 9.x
*
* Generated by: https://openapi-generator.tech
*/
use crate::models;
use serde::{Deserialize, Serialize};
#[derive(Clone, Default, Debug, PartialEq, Serialize, Deserialize)]
pub struct PveCrsConfig {
/// Configures how the HA Manager should select nodes to start or recover services: - with 'basic', only the number of services is used, - with 'static', static CPU and memory configuration of services are considered, - with 'dynamic', static and dynamic CPU and memory usage of services are considered.
#[serde(rename = "ha", skip_serializing_if = "Option::is_none")]
pub ha: Option<models::PveClusterOptionsHaEnum>,
/// Whether to use CRS for balancing HA resources automatically depending on the current node imbalance.
#[serde(rename = "ha-auto-rebalance", skip_serializing_if = "Option::is_none")]
pub ha_auto_rebalance: Option<models::PveBoolean>,
/// The number of HA rounds for which the cluster node imbalance threshold must be exceeded before triggering an automatic resource balancing migration.
#[serde(rename = "ha-auto-rebalance-hold-duration", skip_serializing_if = "Option::is_none")]
pub ha_auto_rebalance_hold_duration: Option<f64>,
/// The minimum relative improvement in cluster node imbalance, in percent, to commit to a resource balancing migration.
#[serde(rename = "ha-auto-rebalance-margin", skip_serializing_if = "Option::is_none")]
pub ha_auto_rebalance_margin: Option<f64>,
/// The method to use for the scoring of balancing migrations.
#[serde(rename = "ha-auto-rebalance-method", skip_serializing_if = "Option::is_none")]
pub ha_auto_rebalance_method: Option<models::PveClusterOptionsHaAutoRebalanceMethodEnum>,
/// The cluster node imbalance, in percent, which will trigger the automatic resource balancing system if exceeded.
#[serde(rename = "ha-auto-rebalance-threshold", skip_serializing_if = "Option::is_none")]
pub ha_auto_rebalance_threshold: Option<f64>,
/// Set to use CRS for selecting a suited node when a HA services request-state changes from stop to start.
#[serde(rename = "ha-rebalance-on-start", skip_serializing_if = "Option::is_none")]
pub ha_rebalance_on_start: Option<models::PveBoolean>,
}
impl PveCrsConfig {
pub fn new() -> PveCrsConfig {
PveCrsConfig {
ha: None,
ha_auto_rebalance: None,
ha_auto_rebalance_hold_duration: None,
ha_auto_rebalance_margin: None,
ha_auto_rebalance_method: None,
ha_auto_rebalance_threshold: None,
ha_rebalance_on_start: None,
}
}
}
impl PveCrsConfig {
/// Serialise this PveCrsConfig into Proxmox's CLI-style shorthand
/// string (`key=value,…`). The property marked `x-pve-default-key`
/// is emitted positionally without a `key=` prefix; aliases collapse
/// multiple property names to the same wire key.
///
/// Example: `PveCrsConfig `
/// → `"virtio,bridge=vmbr0"`
pub fn to_shorthand(&self) -> String {
let mut parts: Vec<String> = Vec::new();
if let Some(ref v) = self.ha {
parts.push(format!("ha={}", v));
}
if let Some(ref v) = self.ha_auto_rebalance {
parts.push(format!("ha-auto-rebalance={}", v));
}
if let Some(ref v) = self.ha_auto_rebalance_hold_duration {
parts.push(format!("ha-auto-rebalance-hold-duration={}", v));
}
if let Some(ref v) = self.ha_auto_rebalance_margin {
parts.push(format!("ha-auto-rebalance-margin={}", v));
}
if let Some(ref v) = self.ha_auto_rebalance_method {
parts.push(format!("ha-auto-rebalance-method={}", v));
}
if let Some(ref v) = self.ha_auto_rebalance_threshold {
parts.push(format!("ha-auto-rebalance-threshold={}", v));
}
if let Some(ref v) = self.ha_rebalance_on_start {
parts.push(format!("ha-rebalance-on-start={}", v));
}
parts.join(",")
}
}