Skip to main content

clientapi_pbs/apis/
status_api.rs

1/*
2 * Proxmox Backup Server API
3 *
4 * Generated from apidoc.js. NOT an official Proxmox specification. See https://pbs.proxmox.com/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 [`status_get_datastore_usage`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum StatusGetDatastoreUsageError {
22    Status400(models::PbsError),
23    Status401(models::PbsError),
24    Status403(models::PbsError),
25    Status404(models::PbsError),
26    Status500(models::PbsError),
27    Status501(models::PbsError),
28    Status503(models::PbsError),
29    UnknownValue(serde_json::Value),
30}
31
32/// struct for typed errors of method [`status_get_metrics`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum StatusGetMetricsError {
36    Status400(models::PbsError),
37    Status401(models::PbsError),
38    Status403(models::PbsError),
39    Status404(models::PbsError),
40    Status500(models::PbsError),
41    Status501(models::PbsError),
42    Status503(models::PbsError),
43    UnknownValue(serde_json::Value),
44}
45
46/// struct for typed errors of method [`status_get_status`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum StatusGetStatusError {
50    Status400(models::PbsError),
51    Status401(models::PbsError),
52    Status403(models::PbsError),
53    Status404(models::PbsError),
54    Status500(models::PbsError),
55    Status501(models::PbsError),
56    Status503(models::PbsError),
57    UnknownValue(serde_json::Value),
58}
59
60
61/// List Datastore usages and estimates
62pub async fn status_get_datastore_usage(configuration: &configuration::Configuration, ) -> Result<models::StatusGetDatastoreUsageResponse, Error<StatusGetDatastoreUsageError>> {
63
64    let uri_str = format!("{}/status/datastore-usage", configuration.base_path);
65    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
66
67    if let Some(ref user_agent) = configuration.user_agent {
68        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
69    }
70    if let Some(ref apikey) = configuration.api_key {
71        let key = apikey.key.clone();
72        let value = match apikey.prefix {
73            Some(ref prefix) => format!("{} {}", prefix, key),
74            None => key,
75        };
76        req_builder = req_builder.header("Authorization", value);
77    };
78    if let Some(ref apikey) = configuration.api_key {
79        let key = apikey.key.clone();
80        let value = match apikey.prefix {
81            Some(ref prefix) => format!("{} {}", prefix, key),
82            None => key,
83        };
84        req_builder = req_builder.header("CSRFPreventionToken", value);
85    };
86
87    let req = req_builder.build()?;
88    let resp = configuration.client.execute(req).await?;
89
90    let status = resp.status();
91    let content_type = resp
92        .headers()
93        .get("content-type")
94        .and_then(|v| v.to_str().ok())
95        .unwrap_or("application/octet-stream");
96    let content_type = super::ContentType::from(content_type);
97
98    if !status.is_client_error() && !status.is_server_error() {
99        let content = resp.text().await?;
100        match content_type {
101            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
102            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StatusGetDatastoreUsageResponse`"))),
103            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::StatusGetDatastoreUsageResponse`")))),
104        }
105    } else {
106        let content = resp.text().await?;
107        let entity: Option<StatusGetDatastoreUsageError> = serde_json::from_str(&content).ok();
108        Err(Error::ResponseError(ResponseContent { status, content, entity }))
109    }
110}
111
112/// Return backup server metrics.  Permissions: Users need Sys.Audit on /system/status for host metrics and Datastore.Audit on /datastore/{store} for datastore metrics
113pub async fn status_get_metrics(configuration: &configuration::Configuration, history: Option<bool>, start_time: Option<i64>) -> Result<models::StatusGetMetricsResponse, Error<StatusGetMetricsError>> {
114    // add a prefix to parameters to efficiently prevent name collisions
115    let p_query_history = history;
116    let p_query_start_time = start_time;
117
118    let uri_str = format!("{}/status/metrics", configuration.base_path);
119    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
120
121    if let Some(ref param_value) = p_query_history {
122        req_builder = req_builder.query(&[("history", &param_value.to_string())]);
123    }
124    if let Some(ref param_value) = p_query_start_time {
125        req_builder = req_builder.query(&[("start-time", &param_value.to_string())]);
126    }
127    if let Some(ref user_agent) = configuration.user_agent {
128        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
129    }
130    if let Some(ref apikey) = configuration.api_key {
131        let key = apikey.key.clone();
132        let value = match apikey.prefix {
133            Some(ref prefix) => format!("{} {}", prefix, key),
134            None => key,
135        };
136        req_builder = req_builder.header("Authorization", value);
137    };
138    if let Some(ref apikey) = configuration.api_key {
139        let key = apikey.key.clone();
140        let value = match apikey.prefix {
141            Some(ref prefix) => format!("{} {}", prefix, key),
142            None => key,
143        };
144        req_builder = req_builder.header("CSRFPreventionToken", value);
145    };
146
147    let req = req_builder.build()?;
148    let resp = configuration.client.execute(req).await?;
149
150    let status = resp.status();
151    let content_type = resp
152        .headers()
153        .get("content-type")
154        .and_then(|v| v.to_str().ok())
155        .unwrap_or("application/octet-stream");
156    let content_type = super::ContentType::from(content_type);
157
158    if !status.is_client_error() && !status.is_server_error() {
159        let content = resp.text().await?;
160        match content_type {
161            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
162            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StatusGetMetricsResponse`"))),
163            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::StatusGetMetricsResponse`")))),
164        }
165    } else {
166        let content = resp.text().await?;
167        let entity: Option<StatusGetMetricsError> = serde_json::from_str(&content).ok();
168        Err(Error::ResponseError(ResponseContent { status, content, entity }))
169    }
170}
171
172/// Directory index.
173pub async fn status_get_status(configuration: &configuration::Configuration, ) -> Result<models::StatusGetStatusResponse, Error<StatusGetStatusError>> {
174
175    let uri_str = format!("{}/status", configuration.base_path);
176    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
177
178    if let Some(ref user_agent) = configuration.user_agent {
179        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
180    }
181    if let Some(ref apikey) = configuration.api_key {
182        let key = apikey.key.clone();
183        let value = match apikey.prefix {
184            Some(ref prefix) => format!("{} {}", prefix, key),
185            None => key,
186        };
187        req_builder = req_builder.header("Authorization", value);
188    };
189    if let Some(ref apikey) = configuration.api_key {
190        let key = apikey.key.clone();
191        let value = match apikey.prefix {
192            Some(ref prefix) => format!("{} {}", prefix, key),
193            None => key,
194        };
195        req_builder = req_builder.header("CSRFPreventionToken", value);
196    };
197
198    let req = req_builder.build()?;
199    let resp = configuration.client.execute(req).await?;
200
201    let status = resp.status();
202    let content_type = resp
203        .headers()
204        .get("content-type")
205        .and_then(|v| v.to_str().ok())
206        .unwrap_or("application/octet-stream");
207    let content_type = super::ContentType::from(content_type);
208
209    if !status.is_client_error() && !status.is_server_error() {
210        let content = resp.text().await?;
211        match content_type {
212            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
213            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StatusGetStatusResponse`"))),
214            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::StatusGetStatusResponse`")))),
215        }
216    } else {
217        let content = resp.text().await?;
218        let entity: Option<StatusGetStatusError> = serde_json::from_str(&content).ok();
219        Err(Error::ResponseError(ResponseContent { status, content, entity }))
220    }
221}
222