Skip to main content

clientapi_pve/apis/
cluster_api.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
11
12use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18/// struct for typed errors of method [`cluster_get_cluster`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ClusterGetClusterError {
22    Status400(models::PveError),
23    Status401(models::PveError),
24    Status403(models::PveError),
25    Status404(models::PveError),
26    Status500(models::PveError),
27    Status501(models::PveError),
28    Status503(models::PveError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`cluster_get_status`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ClusterGetStatusError {
36    Status400(models::PveError),
37    Status401(models::PveError),
38    Status403(models::PveError),
39    Status404(models::PveError),
40    Status500(models::PveError),
41    Status501(models::PveError),
42    Status503(models::PveError),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`cluster_log`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ClusterLogError {
50    Status400(models::PveError),
51    Status401(models::PveError),
52    Status403(models::PveError),
53    Status404(models::PveError),
54    Status500(models::PveError),
55    Status501(models::PveError),
56    Status503(models::PveError),
57    UnknownValue(serde_json::Value),
58}
59
60/// struct for typed errors of method [`cluster_nextid`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ClusterNextidError {
64    Status400(models::PveError),
65    Status401(models::PveError),
66    Status403(models::PveError),
67    Status404(models::PveError),
68    Status500(models::PveError),
69    Status501(models::PveError),
70    Status503(models::PveError),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`cluster_resources`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ClusterResourcesError {
78    Status400(models::PveError),
79    Status401(models::PveError),
80    Status403(models::PveError),
81    Status404(models::PveError),
82    Status500(models::PveError),
83    Status501(models::PveError),
84    Status503(models::PveError),
85    UnknownValue(serde_json::Value),
86}
87
88/// struct for typed errors of method [`cluster_tasks`]
89#[derive(Debug, Clone, Serialize, Deserialize)]
90#[serde(untagged)]
91pub enum ClusterTasksError {
92    Status400(models::PveError),
93    Status401(models::PveError),
94    Status403(models::PveError),
95    Status404(models::PveError),
96    Status500(models::PveError),
97    Status501(models::PveError),
98    Status503(models::PveError),
99    UnknownValue(serde_json::Value),
100}
101
102
103/// Cluster index.
104pub async fn cluster_get_cluster(configuration: &configuration::Configuration, ) -> Result<models::ClusterGetClusterResponse, Error<ClusterGetClusterError>> {
105
106    let uri_str = format!("{}/cluster", configuration.base_path);
107    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
108
109    if let Some(ref user_agent) = configuration.user_agent {
110        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
111    }
112    if let Some(ref apikey) = configuration.api_key {
113        let key = apikey.key.clone();
114        let value = match apikey.prefix {
115            Some(ref prefix) => format!("{} {}", prefix, key),
116            None => key,
117        };
118        req_builder = req_builder.header("Authorization", value);
119    };
120    if let Some(ref apikey) = configuration.api_key {
121        let key = apikey.key.clone();
122        let value = match apikey.prefix {
123            Some(ref prefix) => format!("{} {}", prefix, key),
124            None => key,
125        };
126        req_builder = req_builder.header("CSRFPreventionToken", value);
127    };
128
129    let req = req_builder.build()?;
130    let resp = configuration.client.execute(req).await?;
131
132    let status = resp.status();
133    let content_type = resp
134        .headers()
135        .get("content-type")
136        .and_then(|v| v.to_str().ok())
137        .unwrap_or("application/octet-stream");
138    let content_type = super::ContentType::from(content_type);
139
140    if !status.is_client_error() && !status.is_server_error() {
141        let content = resp.text().await?;
142        match content_type {
143            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
144            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterGetClusterResponse`"))),
145            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterGetClusterResponse`")))),
146        }
147    } else {
148        let content = resp.text().await?;
149        let entity: Option<ClusterGetClusterError> = serde_json::from_str(&content).ok();
150        Err(Error::ResponseError(ResponseContent { status, content, entity }))
151    }
152}
153
154/// Get cluster status information.
155pub async fn cluster_get_status(configuration: &configuration::Configuration, ) -> Result<models::ClusterGetStatusResponse, Error<ClusterGetStatusError>> {
156
157    let uri_str = format!("{}/cluster/status", configuration.base_path);
158    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
159
160    if let Some(ref user_agent) = configuration.user_agent {
161        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
162    }
163    if let Some(ref apikey) = configuration.api_key {
164        let key = apikey.key.clone();
165        let value = match apikey.prefix {
166            Some(ref prefix) => format!("{} {}", prefix, key),
167            None => key,
168        };
169        req_builder = req_builder.header("Authorization", value);
170    };
171    if let Some(ref apikey) = configuration.api_key {
172        let key = apikey.key.clone();
173        let value = match apikey.prefix {
174            Some(ref prefix) => format!("{} {}", prefix, key),
175            None => key,
176        };
177        req_builder = req_builder.header("CSRFPreventionToken", value);
178    };
179
180    let req = req_builder.build()?;
181    let resp = configuration.client.execute(req).await?;
182
183    let status = resp.status();
184    let content_type = resp
185        .headers()
186        .get("content-type")
187        .and_then(|v| v.to_str().ok())
188        .unwrap_or("application/octet-stream");
189    let content_type = super::ContentType::from(content_type);
190
191    if !status.is_client_error() && !status.is_server_error() {
192        let content = resp.text().await?;
193        match content_type {
194            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
195            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterGetStatusResponse`"))),
196            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterGetStatusResponse`")))),
197        }
198    } else {
199        let content = resp.text().await?;
200        let entity: Option<ClusterGetStatusError> = serde_json::from_str(&content).ok();
201        Err(Error::ResponseError(ResponseContent { status, content, entity }))
202    }
203}
204
205/// Read cluster log  Permissions: The user needs 'Sys.Syslog' on '/' in order to get all logs.
206pub async fn cluster_log(configuration: &configuration::Configuration, max: Option<i64>) -> Result<models::ClusterLogResponse, Error<ClusterLogError>> {
207    // add a prefix to parameters to efficiently prevent name collisions
208    let p_query_max = max;
209
210    let uri_str = format!("{}/cluster/log", configuration.base_path);
211    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
212
213    if let Some(ref param_value) = p_query_max {
214        req_builder = req_builder.query(&[("max", &param_value.to_string())]);
215    }
216    if let Some(ref user_agent) = configuration.user_agent {
217        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
218    }
219    if let Some(ref apikey) = configuration.api_key {
220        let key = apikey.key.clone();
221        let value = match apikey.prefix {
222            Some(ref prefix) => format!("{} {}", prefix, key),
223            None => key,
224        };
225        req_builder = req_builder.header("Authorization", value);
226    };
227    if let Some(ref apikey) = configuration.api_key {
228        let key = apikey.key.clone();
229        let value = match apikey.prefix {
230            Some(ref prefix) => format!("{} {}", prefix, key),
231            None => key,
232        };
233        req_builder = req_builder.header("CSRFPreventionToken", value);
234    };
235
236    let req = req_builder.build()?;
237    let resp = configuration.client.execute(req).await?;
238
239    let status = resp.status();
240    let content_type = resp
241        .headers()
242        .get("content-type")
243        .and_then(|v| v.to_str().ok())
244        .unwrap_or("application/octet-stream");
245    let content_type = super::ContentType::from(content_type);
246
247    if !status.is_client_error() && !status.is_server_error() {
248        let content = resp.text().await?;
249        match content_type {
250            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
251            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterLogResponse`"))),
252            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterLogResponse`")))),
253        }
254    } else {
255        let content = resp.text().await?;
256        let entity: Option<ClusterLogError> = serde_json::from_str(&content).ok();
257        Err(Error::ResponseError(ResponseContent { status, content, entity }))
258    }
259}
260
261/// Get next free VMID. Pass a VMID to assert that its free (at time of check).
262pub async fn cluster_nextid(configuration: &configuration::Configuration, vmid: Option<i32>) -> Result<models::ClusterNextidResponse, Error<ClusterNextidError>> {
263    // add a prefix to parameters to efficiently prevent name collisions
264    let p_query_vmid = vmid;
265
266    let uri_str = format!("{}/cluster/nextid", configuration.base_path);
267    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
268
269    if let Some(ref param_value) = p_query_vmid {
270        req_builder = req_builder.query(&[("vmid", &param_value.to_string())]);
271    }
272    if let Some(ref user_agent) = configuration.user_agent {
273        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
274    }
275    if let Some(ref apikey) = configuration.api_key {
276        let key = apikey.key.clone();
277        let value = match apikey.prefix {
278            Some(ref prefix) => format!("{} {}", prefix, key),
279            None => key,
280        };
281        req_builder = req_builder.header("Authorization", value);
282    };
283    if let Some(ref apikey) = configuration.api_key {
284        let key = apikey.key.clone();
285        let value = match apikey.prefix {
286            Some(ref prefix) => format!("{} {}", prefix, key),
287            None => key,
288        };
289        req_builder = req_builder.header("CSRFPreventionToken", value);
290    };
291
292    let req = req_builder.build()?;
293    let resp = configuration.client.execute(req).await?;
294
295    let status = resp.status();
296    let content_type = resp
297        .headers()
298        .get("content-type")
299        .and_then(|v| v.to_str().ok())
300        .unwrap_or("application/octet-stream");
301    let content_type = super::ContentType::from(content_type);
302
303    if !status.is_client_error() && !status.is_server_error() {
304        let content = resp.text().await?;
305        match content_type {
306            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
307            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterNextidResponse`"))),
308            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterNextidResponse`")))),
309        }
310    } else {
311        let content = resp.text().await?;
312        let entity: Option<ClusterNextidError> = serde_json::from_str(&content).ok();
313        Err(Error::ResponseError(ResponseContent { status, content, entity }))
314    }
315}
316
317/// Resources index (cluster wide).
318pub async fn cluster_resources(configuration: &configuration::Configuration, r#type: Option<models::PveClusterTypeEnum>) -> Result<models::ClusterResourcesResponse, Error<ClusterResourcesError>> {
319    // add a prefix to parameters to efficiently prevent name collisions
320    let p_query_type = r#type;
321
322    let uri_str = format!("{}/cluster/resources", configuration.base_path);
323    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
324
325    if let Some(ref param_value) = p_query_type {
326        req_builder = req_builder.query(&[("type", &param_value.to_string())]);
327    }
328    if let Some(ref user_agent) = configuration.user_agent {
329        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
330    }
331    if let Some(ref apikey) = configuration.api_key {
332        let key = apikey.key.clone();
333        let value = match apikey.prefix {
334            Some(ref prefix) => format!("{} {}", prefix, key),
335            None => key,
336        };
337        req_builder = req_builder.header("Authorization", value);
338    };
339    if let Some(ref apikey) = configuration.api_key {
340        let key = apikey.key.clone();
341        let value = match apikey.prefix {
342            Some(ref prefix) => format!("{} {}", prefix, key),
343            None => key,
344        };
345        req_builder = req_builder.header("CSRFPreventionToken", value);
346    };
347
348    let req = req_builder.build()?;
349    let resp = configuration.client.execute(req).await?;
350
351    let status = resp.status();
352    let content_type = resp
353        .headers()
354        .get("content-type")
355        .and_then(|v| v.to_str().ok())
356        .unwrap_or("application/octet-stream");
357    let content_type = super::ContentType::from(content_type);
358
359    if !status.is_client_error() && !status.is_server_error() {
360        let content = resp.text().await?;
361        match content_type {
362            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
363            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterResourcesResponse`"))),
364            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterResourcesResponse`")))),
365        }
366    } else {
367        let content = resp.text().await?;
368        let entity: Option<ClusterResourcesError> = serde_json::from_str(&content).ok();
369        Err(Error::ResponseError(ResponseContent { status, content, entity }))
370    }
371}
372
373/// List recent tasks (cluster wide).
374pub async fn cluster_tasks(configuration: &configuration::Configuration, ) -> Result<models::ClusterTasksResponse, Error<ClusterTasksError>> {
375
376    let uri_str = format!("{}/cluster/tasks", configuration.base_path);
377    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
378
379    if let Some(ref user_agent) = configuration.user_agent {
380        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
381    }
382    if let Some(ref apikey) = configuration.api_key {
383        let key = apikey.key.clone();
384        let value = match apikey.prefix {
385            Some(ref prefix) => format!("{} {}", prefix, key),
386            None => key,
387        };
388        req_builder = req_builder.header("Authorization", value);
389    };
390    if let Some(ref apikey) = configuration.api_key {
391        let key = apikey.key.clone();
392        let value = match apikey.prefix {
393            Some(ref prefix) => format!("{} {}", prefix, key),
394            None => key,
395        };
396        req_builder = req_builder.header("CSRFPreventionToken", value);
397    };
398
399    let req = req_builder.build()?;
400    let resp = configuration.client.execute(req).await?;
401
402    let status = resp.status();
403    let content_type = resp
404        .headers()
405        .get("content-type")
406        .and_then(|v| v.to_str().ok())
407        .unwrap_or("application/octet-stream");
408    let content_type = super::ContentType::from(content_type);
409
410    if !status.is_client_error() && !status.is_server_error() {
411        let content = resp.text().await?;
412        match content_type {
413            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
414            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ClusterTasksResponse`"))),
415            ContentType::Unsupported(unknown_type) => return Err(Error::from(serde_json::Error::custom(format!("Received `{unknown_type}` content type response that cannot be converted to `models::ClusterTasksResponse`")))),
416        }
417    } else {
418        let content = resp.text().await?;
419        let entity: Option<ClusterTasksError> = serde_json::from_str(&content).ok();
420        Err(Error::ResponseError(ResponseContent { status, content, entity }))
421    }
422}
423