Skip to main content

clientapi_pve/models/
cluster_config_join_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 ClusterConfigJoinRequest {
16
17
18    /// Certificate SHA 256 fingerprint.
19    pub fingerprint: String,
20
21    /// Do not throw error if node already exists.
22    pub force: Option<models::PveBoolean>,
23
24    /// Hostname (or IP) of an existing cluster member.
25    pub hostname: String,
26
27    /// Node id for this node.
28    pub nodeid: Option<i64>,
29
30    /// Superuser (root) password of peer node.
31    pub password: String,
32
33    /// Number of votes for this node
34    pub votes: Option<i64>,
35
36    /// Links family. Wire form: `link0..link7`. Serialised by the manual impls below.
37    pub links: Option<std::collections::HashMap<u32, models::PveLinkField>>,
38}
39
40impl ClusterConfigJoinRequest {
41    pub fn new(fingerprint: String, hostname: String, password: String) -> ClusterConfigJoinRequest {
42        ClusterConfigJoinRequest {
43            
44            fingerprint,
45            
46            force: None,
47            
48            hostname,
49            
50            nodeid: None,
51            
52            password,
53            
54            votes: None,
55            
56            links: None,
57        }
58    }
59}
60
61
62// Flattens indexed-family maps to/from `<base><idx>` wire keys.
63impl serde::Serialize for ClusterConfigJoinRequest {
64    fn serialize<S: serde::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
65        use serde::ser::Error;
66        let mut map = serde_json::Map::new();
67        
68        {
69            let _v = serde_json::to_value(&self.fingerprint).map_err(Error::custom)?;
70            if !_v.is_null() {
71                map.insert("fingerprint".to_string(), _v);
72            }
73        }
74        
75        {
76            let _v = serde_json::to_value(&self.force).map_err(Error::custom)?;
77            if !_v.is_null() {
78                map.insert("force".to_string(), _v);
79            }
80        }
81        
82        {
83            let _v = serde_json::to_value(&self.hostname).map_err(Error::custom)?;
84            if !_v.is_null() {
85                map.insert("hostname".to_string(), _v);
86            }
87        }
88        
89        {
90            let _v = serde_json::to_value(&self.nodeid).map_err(Error::custom)?;
91            if !_v.is_null() {
92                map.insert("nodeid".to_string(), _v);
93            }
94        }
95        
96        {
97            let _v = serde_json::to_value(&self.password).map_err(Error::custom)?;
98            if !_v.is_null() {
99                map.insert("password".to_string(), _v);
100            }
101        }
102        
103        {
104            let _v = serde_json::to_value(&self.votes).map_err(Error::custom)?;
105            if !_v.is_null() {
106                map.insert("votes".to_string(), _v);
107            }
108        }
109        
110        if let Some(ref _m) = self.links {
111            for (_idx, _val) in _m.iter() {
112                map.insert(format!("link{}", _idx), serde_json::to_value(_val).map_err(Error::custom)?);
113            }
114        }
115        serde_json::Value::Object(map).serialize(serializer)
116    }
117}
118
119impl<'de> serde::Deserialize<'de> for ClusterConfigJoinRequest {
120    fn deserialize<D: serde::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
121        use serde::de::Error;
122        let mut raw: serde_json::Map<String, serde_json::Value> =
123            serde::Deserialize::deserialize(deserializer)?;
124        let mut __links: std::collections::HashMap<u32, models::PveLinkField> = std::collections::HashMap::new();
125        {
126            let _prefix = "link";
127            let _keys: Vec<String> = raw.keys()
128                .filter(|k| {
129                    if let Some(_suffix) = k.strip_prefix(_prefix) {
130                        !_suffix.is_empty() && _suffix.chars().all(|c| c.is_ascii_digit())
131                    } else {
132                        false
133                    }
134                })
135                .cloned()
136                .collect();
137            for _key in _keys {
138                let _suffix = _key.strip_prefix(_prefix).unwrap();
139                let _idx: u32 = _suffix.parse().map_err(Error::custom)?;
140                let _value = raw.remove(&_key).unwrap();
141                let _item: models::PveLinkField = serde_json::from_value(_value).map_err(Error::custom)?;
142                __links.insert(_idx, _item);
143            }
144        }
145        Ok(ClusterConfigJoinRequest {
146            
147            fingerprint: serde_json::from_value(raw.remove("fingerprint").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
148            
149            force: serde_json::from_value(raw.remove("force").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
150            
151            hostname: serde_json::from_value(raw.remove("hostname").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
152            
153            nodeid: serde_json::from_value(raw.remove("nodeid").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
154            
155            password: serde_json::from_value(raw.remove("password").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
156            
157            votes: serde_json::from_value(raw.remove("votes").unwrap_or(serde_json::Value::Null)).map_err(Error::custom)?,
158            
159            links: if __links.is_empty() { None } else { Some(__links) },
160        })
161    }
162}
163
164