Skip to main content

clientapi_pve/apis/
nodes_vzdump_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 [`nodes_vzdump_defaults`]
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum NodesVzdumpDefaultsError {
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 [`nodes_vzdump_extractconfig`]
33#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum NodesVzdumpExtractconfigError {
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 [`nodes_vzdump_vzdump`]
47#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum NodesVzdumpVzdumpError {
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
61/// Get the currently configured vzdump defaults.  Permissions: The user needs 'Datastore.Audit' or 'Datastore.AllocateSpace' permissions for the specified storage (or default storage if none specified). Some properties are only returned when the user has 'Sys.Audit' permissions for the node.
62pub async fn nodes_vzdump_defaults(configuration: &configuration::Configuration, node: &str, storage: Option<&str>) -> Result<models::NodesVzdumpDefaultsResponse, Error<NodesVzdumpDefaultsError>> {
63    // add a prefix to parameters to efficiently prevent name collisions
64    let p_path_node = node;
65    let p_query_storage = storage;
66
67    let uri_str = format!("{}/nodes/{node}/vzdump/defaults", configuration.base_path, node=crate::apis::urlencode(p_path_node));
68    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
69
70    if let Some(ref param_value) = p_query_storage {
71        req_builder = req_builder.query(&[("storage", &param_value.to_string())]);
72    }
73    if let Some(ref user_agent) = configuration.user_agent {
74        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
75    }
76    if let Some(ref apikey) = configuration.api_key {
77        let key = apikey.key.clone();
78        let value = match apikey.prefix {
79            Some(ref prefix) => format!("{} {}", prefix, key),
80            None => key,
81        };
82        req_builder = req_builder.header("Authorization", value);
83    };
84    if let Some(ref apikey) = configuration.api_key {
85        let key = apikey.key.clone();
86        let value = match apikey.prefix {
87            Some(ref prefix) => format!("{} {}", prefix, key),
88            None => key,
89        };
90        req_builder = req_builder.header("CSRFPreventionToken", value);
91    };
92
93    let req = req_builder.build()?;
94    let resp = configuration.client.execute(req).await?;
95
96    let status = resp.status();
97    let content_type = resp
98        .headers()
99        .get("content-type")
100        .and_then(|v| v.to_str().ok())
101        .unwrap_or("application/octet-stream");
102    let content_type = super::ContentType::from(content_type);
103
104    if !status.is_client_error() && !status.is_server_error() {
105        let content = resp.text().await?;
106        match content_type {
107            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
108            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesVzdumpDefaultsResponse`"))),
109            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::NodesVzdumpDefaultsResponse`")))),
110        }
111    } else {
112        let content = resp.text().await?;
113        let entity: Option<NodesVzdumpDefaultsError> = serde_json::from_str(&content).ok();
114        Err(Error::ResponseError(ResponseContent { status, content, entity }))
115    }
116}
117
118/// Extract configuration from vzdump backup archive.  Permissions: The user needs 'VM.Backup' permissions on the backed up guest ID, and 'Datastore.AllocateSpace' on the backup storage.
119pub async fn nodes_vzdump_extractconfig(configuration: &configuration::Configuration, node: &str, volume: &str) -> Result<models::NodesVzdumpExtractconfigResponse, Error<NodesVzdumpExtractconfigError>> {
120    // add a prefix to parameters to efficiently prevent name collisions
121    let p_path_node = node;
122    let p_query_volume = volume;
123
124    let uri_str = format!("{}/nodes/{node}/vzdump/extractconfig", configuration.base_path, node=crate::apis::urlencode(p_path_node));
125    let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
126
127    req_builder = req_builder.query(&[("volume", &p_query_volume.to_string())]);
128    if let Some(ref user_agent) = configuration.user_agent {
129        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
130    }
131    if let Some(ref apikey) = configuration.api_key {
132        let key = apikey.key.clone();
133        let value = match apikey.prefix {
134            Some(ref prefix) => format!("{} {}", prefix, key),
135            None => key,
136        };
137        req_builder = req_builder.header("Authorization", value);
138    };
139    if let Some(ref apikey) = configuration.api_key {
140        let key = apikey.key.clone();
141        let value = match apikey.prefix {
142            Some(ref prefix) => format!("{} {}", prefix, key),
143            None => key,
144        };
145        req_builder = req_builder.header("CSRFPreventionToken", value);
146    };
147
148    let req = req_builder.build()?;
149    let resp = configuration.client.execute(req).await?;
150
151    let status = resp.status();
152    let content_type = resp
153        .headers()
154        .get("content-type")
155        .and_then(|v| v.to_str().ok())
156        .unwrap_or("application/octet-stream");
157    let content_type = super::ContentType::from(content_type);
158
159    if !status.is_client_error() && !status.is_server_error() {
160        let content = resp.text().await?;
161        match content_type {
162            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
163            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesVzdumpExtractconfigResponse`"))),
164            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::NodesVzdumpExtractconfigResponse`")))),
165        }
166    } else {
167        let content = resp.text().await?;
168        let entity: Option<NodesVzdumpExtractconfigError> = serde_json::from_str(&content).ok();
169        Err(Error::ResponseError(ResponseContent { status, content, entity }))
170    }
171}
172
173/// Create backup.  Permissions: The user needs 'VM.Backup' permissions on any VM, and 'Datastore.AllocateSpace' on the backup storage (and fleecing storage when fleecing is used). The 'tmpdir', 'dumpdir', 'script' and 'job-id' parameters are restricted to the 'root@pam' user. The 'prune-backups' setting requires 'Datastore.Allocate' on the backup storage. The 'bwlimit', 'performance' and 'ionice' parameters require 'Sys.Modify' on '/'.
174pub async fn nodes_vzdump_vzdump(configuration: &configuration::Configuration, node: &str, nodes_vzdump_vzdump_request: Option<models::NodesVzdumpVzdumpRequest>) -> Result<models::NodesVzdumpVzdumpResponse, Error<NodesVzdumpVzdumpError>> {
175    // add a prefix to parameters to efficiently prevent name collisions
176    let p_path_node = node;
177    let p_body_nodes_vzdump_vzdump_request = nodes_vzdump_vzdump_request;
178
179    let uri_str = format!("{}/nodes/{node}/vzdump", configuration.base_path, node=crate::apis::urlencode(p_path_node));
180    let mut req_builder = configuration.client.request(reqwest::Method::POST, &uri_str);
181
182    if let Some(ref user_agent) = configuration.user_agent {
183        req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
184    }
185    if let Some(ref apikey) = configuration.api_key {
186        let key = apikey.key.clone();
187        let value = match apikey.prefix {
188            Some(ref prefix) => format!("{} {}", prefix, key),
189            None => key,
190        };
191        req_builder = req_builder.header("Authorization", value);
192    };
193    if let Some(ref apikey) = configuration.api_key {
194        let key = apikey.key.clone();
195        let value = match apikey.prefix {
196            Some(ref prefix) => format!("{} {}", prefix, key),
197            None => key,
198        };
199        req_builder = req_builder.header("CSRFPreventionToken", value);
200    };
201    req_builder = req_builder.json(&p_body_nodes_vzdump_vzdump_request);
202
203    let req = req_builder.build()?;
204    let resp = configuration.client.execute(req).await?;
205
206    let status = resp.status();
207    let content_type = resp
208        .headers()
209        .get("content-type")
210        .and_then(|v| v.to_str().ok())
211        .unwrap_or("application/octet-stream");
212    let content_type = super::ContentType::from(content_type);
213
214    if !status.is_client_error() && !status.is_server_error() {
215        let content = resp.text().await?;
216        match content_type {
217            ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
218            ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::NodesVzdumpVzdumpResponse`"))),
219            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::NodesVzdumpVzdumpResponse`")))),
220        }
221    } else {
222        let content = resp.text().await?;
223        let entity: Option<NodesVzdumpVzdumpError> = serde_json::from_str(&content).ok();
224        Err(Error::ResponseError(ResponseContent { status, content, entity }))
225    }
226}
227