1use reqwest;
13use serde::{Deserialize, Serialize, de::Error as _};
14use crate::{apis::ResponseContent, models};
15use super::{Error, configuration, ContentType};
16
17
18#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum StorageCreateStorageError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
34#[serde(untagged)]
35pub enum StorageDeleteStorageError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
48#[serde(untagged)]
49pub enum StorageGetStorageError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
62#[serde(untagged)]
63pub enum StorageReadGetStorageError {
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#[derive(Debug, Clone, Serialize, Deserialize)]
76#[serde(untagged)]
77pub enum StorageUpdateStorageError {
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
89pub async fn storage_create_storage(configuration: &configuration::Configuration, storage_create_storage_request: models::StorageCreateStorageRequest) -> Result<models::StorageCreateStorageResponse, Error<StorageCreateStorageError>> {
91 let p_body_storage_create_storage_request = storage_create_storage_request;
93
94 let uri_str = format!("{}/storage", 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_storage_create_storage_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::StorageCreateStorageResponse`"))),
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::StorageCreateStorageResponse`")))),
135 }
136 } else {
137 let content = resp.text().await?;
138 let entity: Option<StorageCreateStorageError> = serde_json::from_str(&content).ok();
139 Err(Error::ResponseError(ResponseContent { status, content, entity }))
140 }
141}
142
143pub async fn storage_delete_storage(configuration: &configuration::Configuration, storage: &str) -> Result<models::StorageDeleteStorageResponse, Error<StorageDeleteStorageError>> {
145 let p_path_storage = storage;
147
148 let uri_str = format!("{}/storage/{storage}", configuration.base_path, storage=crate::apis::urlencode(p_path_storage));
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::StorageDeleteStorageResponse`"))),
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::StorageDeleteStorageResponse`")))),
188 }
189 } else {
190 let content = resp.text().await?;
191 let entity: Option<StorageDeleteStorageError> = serde_json::from_str(&content).ok();
192 Err(Error::ResponseError(ResponseContent { status, content, entity }))
193 }
194}
195
196pub async fn storage_get_storage(configuration: &configuration::Configuration, r#type: Option<models::PveNodesStorageTypeEnum>) -> Result<models::StorageGetStorageResponse, Error<StorageGetStorageError>> {
198 let p_query_type = r#type;
200
201 let uri_str = format!("{}/storage", configuration.base_path);
202 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
203
204 if let Some(ref param_value) = p_query_type {
205 req_builder = req_builder.query(&[("type", ¶m_value.to_string())]);
206 }
207 if let Some(ref user_agent) = configuration.user_agent {
208 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
209 }
210 if let Some(ref apikey) = configuration.api_key {
211 let key = apikey.key.clone();
212 let value = match apikey.prefix {
213 Some(ref prefix) => format!("{} {}", prefix, key),
214 None => key,
215 };
216 req_builder = req_builder.header("Authorization", value);
217 };
218 if let Some(ref apikey) = configuration.api_key {
219 let key = apikey.key.clone();
220 let value = match apikey.prefix {
221 Some(ref prefix) => format!("{} {}", prefix, key),
222 None => key,
223 };
224 req_builder = req_builder.header("CSRFPreventionToken", value);
225 };
226
227 let req = req_builder.build()?;
228 let resp = configuration.client.execute(req).await?;
229
230 let status = resp.status();
231 let content_type = resp
232 .headers()
233 .get("content-type")
234 .and_then(|v| v.to_str().ok())
235 .unwrap_or("application/octet-stream");
236 let content_type = super::ContentType::from(content_type);
237
238 if !status.is_client_error() && !status.is_server_error() {
239 let content = resp.text().await?;
240 match content_type {
241 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
242 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StorageGetStorageResponse`"))),
243 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::StorageGetStorageResponse`")))),
244 }
245 } else {
246 let content = resp.text().await?;
247 let entity: Option<StorageGetStorageError> = serde_json::from_str(&content).ok();
248 Err(Error::ResponseError(ResponseContent { status, content, entity }))
249 }
250}
251
252pub async fn storage_read_get_storage(configuration: &configuration::Configuration, storage: &str) -> Result<models::StorageReadGetStorageResponse, Error<StorageReadGetStorageError>> {
254 let p_path_storage = storage;
256
257 let uri_str = format!("{}/storage/{storage}", configuration.base_path, storage=crate::apis::urlencode(p_path_storage));
258 let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
259
260 if let Some(ref user_agent) = configuration.user_agent {
261 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
262 }
263 if let Some(ref apikey) = configuration.api_key {
264 let key = apikey.key.clone();
265 let value = match apikey.prefix {
266 Some(ref prefix) => format!("{} {}", prefix, key),
267 None => key,
268 };
269 req_builder = req_builder.header("Authorization", value);
270 };
271 if let Some(ref apikey) = configuration.api_key {
272 let key = apikey.key.clone();
273 let value = match apikey.prefix {
274 Some(ref prefix) => format!("{} {}", prefix, key),
275 None => key,
276 };
277 req_builder = req_builder.header("CSRFPreventionToken", value);
278 };
279
280 let req = req_builder.build()?;
281 let resp = configuration.client.execute(req).await?;
282
283 let status = resp.status();
284 let content_type = resp
285 .headers()
286 .get("content-type")
287 .and_then(|v| v.to_str().ok())
288 .unwrap_or("application/octet-stream");
289 let content_type = super::ContentType::from(content_type);
290
291 if !status.is_client_error() && !status.is_server_error() {
292 let content = resp.text().await?;
293 match content_type {
294 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
295 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StorageReadGetStorageResponse`"))),
296 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::StorageReadGetStorageResponse`")))),
297 }
298 } else {
299 let content = resp.text().await?;
300 let entity: Option<StorageReadGetStorageError> = serde_json::from_str(&content).ok();
301 Err(Error::ResponseError(ResponseContent { status, content, entity }))
302 }
303}
304
305pub async fn storage_update_storage(configuration: &configuration::Configuration, storage: &str, storage_update_storage_request: Option<models::StorageUpdateStorageRequest>) -> Result<models::StorageUpdateStorageResponse, Error<StorageUpdateStorageError>> {
307 let p_path_storage = storage;
309 let p_body_storage_update_storage_request = storage_update_storage_request;
310
311 let uri_str = format!("{}/storage/{storage}", configuration.base_path, storage=crate::apis::urlencode(p_path_storage));
312 let mut req_builder = configuration.client.request(reqwest::Method::PUT, &uri_str);
313
314 if let Some(ref user_agent) = configuration.user_agent {
315 req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
316 }
317 if let Some(ref apikey) = configuration.api_key {
318 let key = apikey.key.clone();
319 let value = match apikey.prefix {
320 Some(ref prefix) => format!("{} {}", prefix, key),
321 None => key,
322 };
323 req_builder = req_builder.header("Authorization", value);
324 };
325 if let Some(ref apikey) = configuration.api_key {
326 let key = apikey.key.clone();
327 let value = match apikey.prefix {
328 Some(ref prefix) => format!("{} {}", prefix, key),
329 None => key,
330 };
331 req_builder = req_builder.header("CSRFPreventionToken", value);
332 };
333 req_builder = req_builder.json(&p_body_storage_update_storage_request);
334
335 let req = req_builder.build()?;
336 let resp = configuration.client.execute(req).await?;
337
338 let status = resp.status();
339 let content_type = resp
340 .headers()
341 .get("content-type")
342 .and_then(|v| v.to_str().ok())
343 .unwrap_or("application/octet-stream");
344 let content_type = super::ContentType::from(content_type);
345
346 if !status.is_client_error() && !status.is_server_error() {
347 let content = resp.text().await?;
348 match content_type {
349 ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
350 ContentType::Text => return Err(Error::from(serde_json::Error::custom("Received `text/plain` content type response that cannot be converted to `models::StorageUpdateStorageResponse`"))),
351 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::StorageUpdateStorageResponse`")))),
352 }
353 } else {
354 let content = resp.text().await?;
355 let entity: Option<StorageUpdateStorageError> = serde_json::from_str(&content).ok();
356 Err(Error::ResponseError(ResponseContent { status, content, entity }))
357 }
358}
359