Skip to main content

clientapi_pbs/apis/
config_drive_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 [`config_drive_create_drive`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ConfigDriveCreateDriveError {
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 [`config_drive_delete_drive`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum ConfigDriveDeleteDriveError {
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 [`config_drive_get_config_drive_by_name`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum ConfigDriveGetConfigDriveByNameError {
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/// struct for typed errors of method [`config_drive_get_drive`]
61#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum ConfigDriveGetDriveError {
64    Status400(models::PbsError),
65    Status401(models::PbsError),
66    Status403(models::PbsError),
67    Status404(models::PbsError),
68    Status500(models::PbsError),
69    Status501(models::PbsError),
70    Status503(models::PbsError),
71    UnknownValue(serde_json::Value),
72}
73
74/// struct for typed errors of method [`config_drive_update_drive`]
75#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum ConfigDriveUpdateDriveError {
78    Status400(models::PbsError),
79    Status401(models::PbsError),
80    Status403(models::PbsError),
81    Status404(models::PbsError),
82    Status500(models::PbsError),
83    Status501(models::PbsError),
84    Status503(models::PbsError),
85    UnknownValue(serde_json::Value),
86}
87
88
89/// Create a new drive
90pub async fn config_drive_create_drive(configuration: &configuration::Configuration, config_drive_create_drive_request: models::ConfigDriveCreateDriveRequest) -> Result<models::ConfigDriveCreateDriveResponse, Error<ConfigDriveCreateDriveError>> {
91    // add a prefix to parameters to efficiently prevent name collisions
92    let p_body_config_drive_create_drive_request = config_drive_create_drive_request;
93
94    let uri_str = format!("{}/config/drive", configuration.base_path);
95    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
96
97    if let Some(ref user_agent) = configuration.user_agent {
98        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
99    }
100    if let Some(ref apikey) = configuration.api_key {
101        let key = apikey.key.clone();
102        let value = match apikey.prefix {
103            Some(ref prefix) => format!("{} {}", prefix, key),
104            None => key,
105        };
106        req_builder = req_builder.header("Authorization", value);
107    };
108    if let Some(ref apikey) = configuration.api_key {
109        let key = apikey.key.clone();
110        let value = match apikey.prefix {
111            Some(ref prefix) => format!("{} {}", prefix, key),
112            None => key,
113        };
114        req_builder = req_builder.header("CSRFPreventionToken", value);
115    };
116    req_builder = req_builder.json(&p_body_config_drive_create_drive_request);
117
118    let req = req_builder.build()?;
119    let resp = configuration.client.execute(req).await?;
120
121    let status = resp.status();
122    let content_type = resp
123        .headers()
124        .get("content-type")
125        .and_then(|v| v.to_str().ok())
126        .unwrap_or("application/octet-stream");
127    let content_type = super::ContentType::from(content_type);
128
129    if !status.is_client_error() && !status.is_server_error() {
130        let content = resp.text().await?;
131        match content_type {
132            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
133            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigDriveCreateDriveResponse`"))),
134            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::ConfigDriveCreateDriveResponse`")))),
135        }
136    } else {
137        let content = resp.text().await?;
138        let entity: Option<ConfigDriveCreateDriveError> = serde_json::from_str(&content).ok();
139        Err(Error::ResponseError(ResponseContent { status, content, entity }))
140    }
141}
142
143/// Delete a drive configuration
144pub async fn config_drive_delete_drive(configuration: &configuration::Configuration, name: &str) -> Result<models::ConfigDriveDeleteDriveResponse, Error<ConfigDriveDeleteDriveError>> {
145    // add a prefix to parameters to efficiently prevent name collisions
146    let p_path_name = name;
147
148    let uri_str = format!("{}/config/drive/{name}", configuration.base_path, name=crate::apis::urlencode(p_path_name));
149    let mut req_builder = configuration.client.request(reqwest::Method::DELETE, &uri_str);
150
151    if let Some(ref user_agent) = configuration.user_agent {
152        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
153    }
154    if let Some(ref apikey) = configuration.api_key {
155        let key = apikey.key.clone();
156        let value = match apikey.prefix {
157            Some(ref prefix) => format!("{} {}", prefix, key),
158            None => key,
159        };
160        req_builder = req_builder.header("Authorization", value);
161    };
162    if let Some(ref apikey) = configuration.api_key {
163        let key = apikey.key.clone();
164        let value = match apikey.prefix {
165            Some(ref prefix) => format!("{} {}", prefix, key),
166            None => key,
167        };
168        req_builder = req_builder.header("CSRFPreventionToken", value);
169    };
170
171    let req = req_builder.build()?;
172    let resp = configuration.client.execute(req).await?;
173
174    let status = resp.status();
175    let content_type = resp
176        .headers()
177        .get("content-type")
178        .and_then(|v| v.to_str().ok())
179        .unwrap_or("application/octet-stream");
180    let content_type = super::ContentType::from(content_type);
181
182    if !status.is_client_error() && !status.is_server_error() {
183        let content = resp.text().await?;
184        match content_type {
185            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
186            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigDriveDeleteDriveResponse`"))),
187            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::ConfigDriveDeleteDriveResponse`")))),
188        }
189    } else {
190        let content = resp.text().await?;
191        let entity: Option<ConfigDriveDeleteDriveError> = serde_json::from_str(&content).ok();
192        Err(Error::ResponseError(ResponseContent { status, content, entity }))
193    }
194}
195
196/// Get drive configuration
197pub async fn config_drive_get_config_drive_by_name(configuration: &configuration::Configuration, name: &str) -> Result<models::ConfigDriveGetConfigDriveByNameResponse, Error<ConfigDriveGetConfigDriveByNameError>> {
198    // add a prefix to parameters to efficiently prevent name collisions
199    let p_path_name = name;
200
201    let uri_str = format!("{}/config/drive/{name}", configuration.base_path, name=crate::apis::urlencode(p_path_name));
202    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
203
204    if let Some(ref user_agent) = configuration.user_agent {
205        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
206    }
207    if let Some(ref apikey) = configuration.api_key {
208        let key = apikey.key.clone();
209        let value = match apikey.prefix {
210            Some(ref prefix) => format!("{} {}", prefix, key),
211            None => key,
212        };
213        req_builder = req_builder.header("Authorization", value);
214    };
215    if let Some(ref apikey) = configuration.api_key {
216        let key = apikey.key.clone();
217        let value = match apikey.prefix {
218            Some(ref prefix) => format!("{} {}", prefix, key),
219            None => key,
220        };
221        req_builder = req_builder.header("CSRFPreventionToken", value);
222    };
223
224    let req = req_builder.build()?;
225    let resp = configuration.client.execute(req).await?;
226
227    let status = resp.status();
228    let content_type = resp
229        .headers()
230        .get("content-type")
231        .and_then(|v| v.to_str().ok())
232        .unwrap_or("application/octet-stream");
233    let content_type = super::ContentType::from(content_type);
234
235    if !status.is_client_error() && !status.is_server_error() {
236        let content = resp.text().await?;
237        match content_type {
238            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
239            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigDriveGetConfigDriveByNameResponse`"))),
240            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::ConfigDriveGetConfigDriveByNameResponse`")))),
241        }
242    } else {
243        let content = resp.text().await?;
244        let entity: Option<ConfigDriveGetConfigDriveByNameError> = serde_json::from_str(&content).ok();
245        Err(Error::ResponseError(ResponseContent { status, content, entity }))
246    }
247}
248
249/// List drives  Permissions: List configured tape drives filtered by Tape.Audit privileges
250pub async fn config_drive_get_drive(configuration: &configuration::Configuration, ) -> Result<models::ConfigDriveGetDriveResponse, Error<ConfigDriveGetDriveError>> {
251
252    let uri_str = format!("{}/config/drive", configuration.base_path);
253    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
254
255    if let Some(ref user_agent) = configuration.user_agent {
256        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
257    }
258    if let Some(ref apikey) = configuration.api_key {
259        let key = apikey.key.clone();
260        let value = match apikey.prefix {
261            Some(ref prefix) => format!("{} {}", prefix, key),
262            None => key,
263        };
264        req_builder = req_builder.header("Authorization", value);
265    };
266    if let Some(ref apikey) = configuration.api_key {
267        let key = apikey.key.clone();
268        let value = match apikey.prefix {
269            Some(ref prefix) => format!("{} {}", prefix, key),
270            None => key,
271        };
272        req_builder = req_builder.header("CSRFPreventionToken", value);
273    };
274
275    let req = req_builder.build()?;
276    let resp = configuration.client.execute(req).await?;
277
278    let status = resp.status();
279    let content_type = resp
280        .headers()
281        .get("content-type")
282        .and_then(|v| v.to_str().ok())
283        .unwrap_or("application/octet-stream");
284    let content_type = super::ContentType::from(content_type);
285
286    if !status.is_client_error() && !status.is_server_error() {
287        let content = resp.text().await?;
288        match content_type {
289            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
290            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigDriveGetDriveResponse`"))),
291            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::ConfigDriveGetDriveResponse`")))),
292        }
293    } else {
294        let content = resp.text().await?;
295        let entity: Option<ConfigDriveGetDriveError> = serde_json::from_str(&content).ok();
296        Err(Error::ResponseError(ResponseContent { status, content, entity }))
297    }
298}
299
300/// Update a drive configuration
301pub async fn config_drive_update_drive(configuration: &configuration::Configuration, name: &str, config_drive_update_drive_request: Option<models::ConfigDriveUpdateDriveRequest>) -> Result<models::ConfigDriveUpdateDriveResponse, Error<ConfigDriveUpdateDriveError>> {
302    // add a prefix to parameters to efficiently prevent name collisions
303    let p_path_name = name;
304    let p_body_config_drive_update_drive_request = config_drive_update_drive_request;
305
306    let uri_str = format!("{}/config/drive/{name}", configuration.base_path, name=crate::apis::urlencode(p_path_name));
307    let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
308
309    if let Some(ref user_agent) = configuration.user_agent {
310        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
311    }
312    if let Some(ref apikey) = configuration.api_key {
313        let key = apikey.key.clone();
314        let value = match apikey.prefix {
315            Some(ref prefix) => format!("{} {}", prefix, key),
316            None => key,
317        };
318        req_builder = req_builder.header("Authorization", value);
319    };
320    if let Some(ref apikey) = configuration.api_key {
321        let key = apikey.key.clone();
322        let value = match apikey.prefix {
323            Some(ref prefix) => format!("{} {}", prefix, key),
324            None => key,
325        };
326        req_builder = req_builder.header("CSRFPreventionToken", value);
327    };
328    req_builder = req_builder.json(&p_body_config_drive_update_drive_request);
329
330    let req = req_builder.build()?;
331    let resp = configuration.client.execute(req).await?;
332
333    let status = resp.status();
334    let content_type = resp
335        .headers()
336        .get("content-type")
337        .and_then(|v| v.to_str().ok())
338        .unwrap_or("application/octet-stream");
339    let content_type = super::ContentType::from(content_type);
340
341    if !status.is_client_error() && !status.is_server_error() {
342        let content = resp.text().await?;
343        match content_type {
344            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
345            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::ConfigDriveUpdateDriveResponse`"))),
346            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::ConfigDriveUpdateDriveResponse`")))),
347        }
348    } else {
349        let content = resp.text().await?;
350        let entity: Option<ConfigDriveUpdateDriveError> = serde_json::from_str(&content).ok();
351        Err(Error::ResponseError(ResponseContent { status, content, entity }))
352    }
353}
354