Skip to main content

clientapi_pve/models/
cluster_config_create_config_request.rs

1/*
2 * Proxmox Virtual Environment API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pve.proxmox.com/pve-docs/api-viewer/ for the upstream documentation.
5 *
6 * The version of the OpenAPI document: 9.x
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11use crate::models;
12use serde::{Deserialize, Serialize};
13
14#[derive(Clone, Default, Debug, PartialEq)]
15pub struct ClusterConfigCreateConfigRequest {
16
17
18    /// The name of the cluster.
19    pub clustername: String,
20
21    /// Node id for this node.
22    pub nodeid: Option<i64>,
23
24    /// Coefficient used to determine Corosync's token timeout. See the corosync.conf(5) manual for more details.
25    pub token_coefficient: Option<i64>,
26
27    /// Number of votes for this node.
28    pub votes: Option<i64>,
29
30    /// Links family. Wire form: `link0..link7`. Serialised by the manual impls below.
31    pub links: Option<std::collections::HashMap<u32, models::PveLinkField>>,
32}
33
34impl ClusterConfigCreateConfigRequest {
35    pub fn new(clustername: String) -> ClusterConfigCreateConfigRequest {
36        ClusterConfigCreateConfigRequest {
37            
38            clustername,
39            
40            nodeid: None,
41            
42            token_coefficient: None,
43            
44            votes: None,
45            
46            links: None,
47        }
48    }
49}
50
51
52// Flattens indexed-family maps to/from `<base><idx>` wire keys.
53impl serde::Serialize for ClusterConfigCreateConfigRequest {
54    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
55        use serde::ser::Error;
56        let mut map = serde_json::Map::new();
57        
58        {
59            let _v = serde_json::to_value(&self.clustername).map_err(Error::custom)?;
60            if !_v.is_null() {
61                map.insert("clustername".to_string(), _v);
62            }
63        }
64        
65        {
66            let _v = serde_json::to_value(&self.nodeid).map_err(Error::custom)?;
67            if !_v.is_null() {
68                map.insert("nodeid".to_string(), _v);
69            }
70        }
71        
72        {
73            let _v = serde_json::to_value(&self.token_coefficient).map_err(Error::custom)?;
74            if !_v.is_null() {
75                map.insert("token-coefficient".to_string(), _v);
76            }
77        }
78        
79        {
80            let _v = serde_json::to_value(&self.votes).map_err(Error::custom)?;
81            if !_v.is_null() {
82                map.insert("votes".to_string(), _v);
83            }
84        }
85        
86        if let Some(ref _m) = self.links {
87            for (_idx, _val) in _m.iter() {
88                map.insert(format!("link{}", _idx), serde_json::to_value(_val).map_err(Error::custom)?);
89            }
90        }
91        serde_json::Value::Object(map).serialize(serializer)
92    }
93}
94
95impl<'de> serde::Deserialize<'de> for ClusterConfigCreateConfigRequest {
96    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
97        use serde::de::Error;
98        let mut raw: serde_json::Map<String, serde_json::Value> =
99            serde::Deserialize::deserialize(deserializer)?;
100        let mut __links: std::collections::HashMap<u32, models::PveLinkField> = std::collections::HashMap::new();
101        {
102            let _prefix = "link";
103            let _keys: Vec<String> = raw.keys()
104                .filter(|k| {
105                    if let Some(_suffix) = k.strip_prefix(_prefix) {
106                        !_suffix.is_empty() && _suffix.chars().all(|c| c.is_ascii_digit())
107                    } else {
108                        false
109                    }
110                })
111                .cloned()
112                .collect();
113            for _key in _keys {
114                let _suffix = _key.strip_prefix(_prefix).unwrap();
115                let _idx: u32 = _suffix.parse().map_err(Error::custom)?;
116                let _value = raw.remove(&_key).unwrap();
117                let _item: models::PveLinkField = serde_json::from_value(_value).map_err(Error::custom)?;
118                __links.insert(_idx, _item);
119            }
120        }
121        Ok(ClusterConfigCreateConfigRequest {
122            
123            clustername: serde_json::from_value(raw.remove("clustername").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
124            
125            nodeid: serde_json::from_value(raw.remove("nodeid").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
126            
127            token_coefficient: serde_json::from_value(raw.remove("token-coefficient").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
128            
129            votes: serde_json::from_value(raw.remove("votes").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
130            
131            links: if __links.is_empty() { None } else { Some(__links) },
132        })
133    }
134}
135
136