hcloud/apis/
volumes_api.rs

1/*
2 * Hetzner Cloud API
3 *
4 * Copied from the official API documentation for the Public Hetzner Cloud.
5 *
6 * The version of the OpenAPI document: 0.26.0
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use super::{configuration, Error};
12use crate::{apis::ResponseContent, models};
13use reqwest;
14use serde::{Deserialize, Serialize};
15
16/// struct for passing parameters to the method [`attach_volume_to_server`]
17#[derive(Clone, Debug, Default)]
18pub struct AttachVolumeToServerParams {
19    /// ID of the Volume.
20    pub id: i64,
21    pub attach_volume_to_server_request: Option<models::AttachVolumeToServerRequest>,
22}
23
24/// struct for passing parameters to the method [`change_volume_protection`]
25#[derive(Clone, Debug, Default)]
26pub struct ChangeVolumeProtectionParams {
27    /// ID of the Volume.
28    pub id: i64,
29    pub change_volume_protection_request: Option<models::ChangeVolumeProtectionRequest>,
30}
31
32/// struct for passing parameters to the method [`create_volume`]
33#[derive(Clone, Debug, Default)]
34pub struct CreateVolumeParams {
35    pub create_volume_request: Option<models::CreateVolumeRequest>,
36}
37
38/// struct for passing parameters to the method [`delete_volume`]
39#[derive(Clone, Debug, Default)]
40pub struct DeleteVolumeParams {
41    /// ID of the Volume.
42    pub id: i64,
43}
44
45/// struct for passing parameters to the method [`detach_volume`]
46#[derive(Clone, Debug, Default)]
47pub struct DetachVolumeParams {
48    /// ID of the Volume.
49    pub id: i64,
50}
51
52/// struct for passing parameters to the method [`get_action_for_volume`]
53#[derive(Clone, Debug, Default)]
54pub struct GetActionForVolumeParams {
55    /// ID of the Volume.
56    pub id: i64,
57    /// ID of the Action.
58    pub action_id: i64,
59}
60
61/// struct for passing parameters to the method [`get_volume`]
62#[derive(Clone, Debug, Default)]
63pub struct GetVolumeParams {
64    /// ID of the Volume.
65    pub id: i64,
66}
67
68/// struct for passing parameters to the method [`get_volume_action`]
69#[derive(Clone, Debug, Default)]
70pub struct GetVolumeActionParams {
71    /// ID of the Action.
72    pub id: i64,
73}
74
75/// struct for passing parameters to the method [`list_actions_for_volume`]
76#[derive(Clone, Debug, Default)]
77pub struct ListActionsForVolumeParams {
78    /// ID of the Volume.
79    pub id: i64,
80    /// Sort actions by field and direction. Can be used multiple times. For more information, see \"[Sorting](#sorting)\".
81    pub sort: Option<Vec<String>>,
82    /// Filter the actions by status. Can be used multiple times. The response will only contain actions matching the specified statuses.
83    pub status: Option<Vec<String>>,
84    /// Page number to return. For more information, see \"[Pagination](#pagination)\".
85    pub page: Option<i64>,
86    /// Maximum number of entries returned per page. For more information, see \"[Pagination](#pagination)\".
87    pub per_page: Option<i64>,
88}
89
90/// struct for passing parameters to the method [`list_volume_actions`]
91#[derive(Clone, Debug, Default)]
92pub struct ListVolumeActionsParams {
93    /// Filter the actions by ID. Can be used multiple times. The response will only contain actions matching the specified IDs.
94    pub id: Option<Vec<i64>>,
95    /// Sort actions by field and direction. Can be used multiple times. For more information, see \"[Sorting](#sorting)\".
96    pub sort: Option<Vec<String>>,
97    /// Filter the actions by status. Can be used multiple times. The response will only contain actions matching the specified statuses.
98    pub status: Option<Vec<String>>,
99    /// Page number to return. For more information, see \"[Pagination](#pagination)\".
100    pub page: Option<i64>,
101    /// Maximum number of entries returned per page. For more information, see \"[Pagination](#pagination)\".
102    pub per_page: Option<i64>,
103}
104
105/// struct for passing parameters to the method [`list_volumes`]
106#[derive(Clone, Debug, Default)]
107pub struct ListVolumesParams {
108    /// Filter resources by status. Can be used multiple times. The response will only contain the resources with the specified status.
109    pub status: Option<Vec<String>>,
110    /// Sort resources by field and direction. Can be used multiple times. For more information, see \"[Sorting](#sorting)\".
111    pub sort: Option<Vec<String>>,
112    /// Filter resources by their name. The response will only contain the resources matching exactly the specified name.
113    pub name: Option<String>,
114    /// Filter resources by labels. The response will only contain resources matching the label selector. For more information, see \"[Label Selector](#label-selector)\".
115    pub label_selector: Option<String>,
116    /// Page number to return. For more information, see \"[Pagination](#pagination)\".
117    pub page: Option<i64>,
118    /// Maximum number of entries returned per page. For more information, see \"[Pagination](#pagination)\".
119    pub per_page: Option<i64>,
120}
121
122/// struct for passing parameters to the method [`replace_volume`]
123#[derive(Clone, Debug, Default)]
124pub struct ReplaceVolumeParams {
125    /// ID of the Volume.
126    pub id: i64,
127    pub replace_volume_request: Option<models::ReplaceVolumeRequest>,
128}
129
130/// struct for passing parameters to the method [`resize_volume`]
131#[derive(Clone, Debug, Default)]
132pub struct ResizeVolumeParams {
133    /// ID of the Volume.
134    pub id: i64,
135    pub resize_volume_request: Option<models::ResizeVolumeRequest>,
136}
137
138/// struct for typed errors of method [`attach_volume_to_server`]
139#[derive(Debug, Clone, Serialize, Deserialize)]
140#[serde(untagged)]
141pub enum AttachVolumeToServerError {
142    UnknownValue(serde_json::Value),
143}
144
145/// struct for typed errors of method [`change_volume_protection`]
146#[derive(Debug, Clone, Serialize, Deserialize)]
147#[serde(untagged)]
148pub enum ChangeVolumeProtectionError {
149    UnknownValue(serde_json::Value),
150}
151
152/// struct for typed errors of method [`create_volume`]
153#[derive(Debug, Clone, Serialize, Deserialize)]
154#[serde(untagged)]
155pub enum CreateVolumeError {
156    UnknownValue(serde_json::Value),
157}
158
159/// struct for typed errors of method [`delete_volume`]
160#[derive(Debug, Clone, Serialize, Deserialize)]
161#[serde(untagged)]
162pub enum DeleteVolumeError {
163    UnknownValue(serde_json::Value),
164}
165
166/// struct for typed errors of method [`detach_volume`]
167#[derive(Debug, Clone, Serialize, Deserialize)]
168#[serde(untagged)]
169pub enum DetachVolumeError {
170    UnknownValue(serde_json::Value),
171}
172
173/// struct for typed errors of method [`get_action_for_volume`]
174#[derive(Debug, Clone, Serialize, Deserialize)]
175#[serde(untagged)]
176pub enum GetActionForVolumeError {
177    UnknownValue(serde_json::Value),
178}
179
180/// struct for typed errors of method [`get_volume`]
181#[derive(Debug, Clone, Serialize, Deserialize)]
182#[serde(untagged)]
183pub enum GetVolumeError {
184    UnknownValue(serde_json::Value),
185}
186
187/// struct for typed errors of method [`get_volume_action`]
188#[derive(Debug, Clone, Serialize, Deserialize)]
189#[serde(untagged)]
190pub enum GetVolumeActionError {
191    UnknownValue(serde_json::Value),
192}
193
194/// struct for typed errors of method [`list_actions_for_volume`]
195#[derive(Debug, Clone, Serialize, Deserialize)]
196#[serde(untagged)]
197pub enum ListActionsForVolumeError {
198    UnknownValue(serde_json::Value),
199}
200
201/// struct for typed errors of method [`list_volume_actions`]
202#[derive(Debug, Clone, Serialize, Deserialize)]
203#[serde(untagged)]
204pub enum ListVolumeActionsError {
205    UnknownValue(serde_json::Value),
206}
207
208/// struct for typed errors of method [`list_volumes`]
209#[derive(Debug, Clone, Serialize, Deserialize)]
210#[serde(untagged)]
211pub enum ListVolumesError {
212    UnknownValue(serde_json::Value),
213}
214
215/// struct for typed errors of method [`replace_volume`]
216#[derive(Debug, Clone, Serialize, Deserialize)]
217#[serde(untagged)]
218pub enum ReplaceVolumeError {
219    UnknownValue(serde_json::Value),
220}
221
222/// struct for typed errors of method [`resize_volume`]
223#[derive(Debug, Clone, Serialize, Deserialize)]
224#[serde(untagged)]
225pub enum ResizeVolumeError {
226    UnknownValue(serde_json::Value),
227}
228
229/// Attaches a Volume to a Server. Works only if the Server is in the same Location as the Volume.
230pub async fn attach_volume_to_server(
231    configuration: &configuration::Configuration,
232    params: AttachVolumeToServerParams,
233) -> Result<models::AttachVolumeToServerResponse, Error<AttachVolumeToServerError>> {
234    let local_var_configuration = configuration;
235
236    // unbox the parameters
237    let id = params.id;
238    let attach_volume_to_server_request = params.attach_volume_to_server_request;
239
240    let local_var_client = &local_var_configuration.client;
241
242    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
243    let local_var_uri_str = format!("{}/volumes/{id}/actions/attach", local_base_path, id = id);
244    let mut local_var_req_builder =
245        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
246
247    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
248        local_var_req_builder =
249            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
250    }
251    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
252        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
253    };
254    local_var_req_builder = local_var_req_builder.json(&attach_volume_to_server_request);
255
256    let local_var_req = local_var_req_builder.build()?;
257    let local_var_resp = local_var_client.execute(local_var_req).await?;
258
259    let local_var_status = local_var_resp.status();
260    let local_var_content = local_var_resp.text().await?;
261
262    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
263        serde_json::from_str(&local_var_content).map_err(Error::from)
264    } else {
265        let local_var_entity: Option<AttachVolumeToServerError> =
266            serde_json::from_str(&local_var_content).ok();
267        let local_var_error = ResponseContent {
268            status: local_var_status,
269            content: local_var_content,
270            entity: local_var_entity,
271        };
272        Err(Error::ResponseError(local_var_error))
273    }
274}
275
276/// Changes the protection configuration of a Volume.
277pub async fn change_volume_protection(
278    configuration: &configuration::Configuration,
279    params: ChangeVolumeProtectionParams,
280) -> Result<models::ChangeVolumeProtectionResponse, Error<ChangeVolumeProtectionError>> {
281    let local_var_configuration = configuration;
282
283    // unbox the parameters
284    let id = params.id;
285    let change_volume_protection_request = params.change_volume_protection_request;
286
287    let local_var_client = &local_var_configuration.client;
288
289    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
290    let local_var_uri_str = format!(
291        "{}/volumes/{id}/actions/change_protection",
292        local_base_path,
293        id = id
294    );
295    let mut local_var_req_builder =
296        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
297
298    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
299        local_var_req_builder =
300            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
301    }
302    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
303        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
304    };
305    local_var_req_builder = local_var_req_builder.json(&change_volume_protection_request);
306
307    let local_var_req = local_var_req_builder.build()?;
308    let local_var_resp = local_var_client.execute(local_var_req).await?;
309
310    let local_var_status = local_var_resp.status();
311    let local_var_content = local_var_resp.text().await?;
312
313    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
314        serde_json::from_str(&local_var_content).map_err(Error::from)
315    } else {
316        let local_var_entity: Option<ChangeVolumeProtectionError> =
317            serde_json::from_str(&local_var_content).ok();
318        let local_var_error = ResponseContent {
319            status: local_var_status,
320            content: local_var_content,
321            entity: local_var_entity,
322        };
323        Err(Error::ResponseError(local_var_error))
324    }
325}
326
327/// Creates a new Volume attached to a Server. If you want to create a Volume that is not attached to a Server, you need to provide the `location` key instead of `server`. This can be either the ID or the name of the Location this Volume will be created in. Note that a Volume can be attached to a Server only in the same Location as the Volume itself.  Specifying the Server during Volume creation will automatically attach the Volume to that Server after it has been initialized. In that case, the `next_actions` key in the response is an array which contains a single `attach_volume` action.  The minimum Volume size is 10GB and the maximum size is 10TB (10240GB).  A volume’s name can consist of alphanumeric characters, dashes, underscores, and dots, but has to start and end with an alphanumeric character. The total length is limited to 64 characters. Volume names must be unique per Project.  #### Call specific error codes  | Code                                | Description                                         | |-------------------------------------|-----------------------------------------------------| | `no_space_left_in_location`         | There is no volume space left in the given location |
328pub async fn create_volume(
329    configuration: &configuration::Configuration,
330    params: CreateVolumeParams,
331) -> Result<models::CreateVolumeResponse, Error<CreateVolumeError>> {
332    let local_var_configuration = configuration;
333
334    // unbox the parameters
335    let create_volume_request = params.create_volume_request;
336
337    let local_var_client = &local_var_configuration.client;
338
339    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
340    let local_var_uri_str = format!("{}/volumes", local_base_path);
341    let mut local_var_req_builder =
342        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
343
344    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
345        local_var_req_builder =
346            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
347    }
348    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
349        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
350    };
351    local_var_req_builder = local_var_req_builder.json(&create_volume_request);
352
353    let local_var_req = local_var_req_builder.build()?;
354    let local_var_resp = local_var_client.execute(local_var_req).await?;
355
356    let local_var_status = local_var_resp.status();
357    let local_var_content = local_var_resp.text().await?;
358
359    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
360        serde_json::from_str(&local_var_content).map_err(Error::from)
361    } else {
362        let local_var_entity: Option<CreateVolumeError> =
363            serde_json::from_str(&local_var_content).ok();
364        let local_var_error = ResponseContent {
365            status: local_var_status,
366            content: local_var_content,
367            entity: local_var_entity,
368        };
369        Err(Error::ResponseError(local_var_error))
370    }
371}
372
373/// Deletes a volume. All Volume data is irreversibly destroyed. The Volume must not be attached to a Server and it must not have delete protection enabled.
374pub async fn delete_volume(
375    configuration: &configuration::Configuration,
376    params: DeleteVolumeParams,
377) -> Result<(), Error<DeleteVolumeError>> {
378    let local_var_configuration = configuration;
379
380    // unbox the parameters
381    let id = params.id;
382
383    let local_var_client = &local_var_configuration.client;
384
385    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
386    let local_var_uri_str = format!("{}/volumes/{id}", local_base_path, id = id);
387    let mut local_var_req_builder =
388        local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
389
390    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
391        local_var_req_builder =
392            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
393    }
394    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
395        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
396    };
397
398    let local_var_req = local_var_req_builder.build()?;
399    let local_var_resp = local_var_client.execute(local_var_req).await?;
400
401    let local_var_status = local_var_resp.status();
402    let local_var_content = local_var_resp.text().await?;
403
404    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
405        Ok(())
406    } else {
407        let local_var_entity: Option<DeleteVolumeError> =
408            serde_json::from_str(&local_var_content).ok();
409        let local_var_error = ResponseContent {
410            status: local_var_status,
411            content: local_var_content,
412            entity: local_var_entity,
413        };
414        Err(Error::ResponseError(local_var_error))
415    }
416}
417
418/// Detaches a Volume from the Server it’s attached to. You may attach it to a Server again at a later time.
419pub async fn detach_volume(
420    configuration: &configuration::Configuration,
421    params: DetachVolumeParams,
422) -> Result<models::DetachVolumeResponse, Error<DetachVolumeError>> {
423    let local_var_configuration = configuration;
424
425    // unbox the parameters
426    let id = params.id;
427
428    let local_var_client = &local_var_configuration.client;
429
430    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
431    let local_var_uri_str = format!("{}/volumes/{id}/actions/detach", local_base_path, id = id);
432    let mut local_var_req_builder =
433        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
434
435    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
436        local_var_req_builder =
437            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
438    }
439    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
440        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
441    };
442
443    let local_var_req = local_var_req_builder.build()?;
444    let local_var_resp = local_var_client.execute(local_var_req).await?;
445
446    let local_var_status = local_var_resp.status();
447    let local_var_content = local_var_resp.text().await?;
448
449    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
450        serde_json::from_str(&local_var_content).map_err(Error::from)
451    } else {
452        let local_var_entity: Option<DetachVolumeError> =
453            serde_json::from_str(&local_var_content).ok();
454        let local_var_error = ResponseContent {
455            status: local_var_status,
456            content: local_var_content,
457            entity: local_var_entity,
458        };
459        Err(Error::ResponseError(local_var_error))
460    }
461}
462
463/// Returns a specific Action for a Volume.
464pub async fn get_action_for_volume(
465    configuration: &configuration::Configuration,
466    params: GetActionForVolumeParams,
467) -> Result<models::GetActionResponse, Error<GetActionForVolumeError>> {
468    let local_var_configuration = configuration;
469
470    // unbox the parameters
471    let id = params.id;
472    let action_id = params.action_id;
473
474    let local_var_client = &local_var_configuration.client;
475
476    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
477    let local_var_uri_str = format!(
478        "{}/volumes/{id}/actions/{action_id}",
479        local_base_path,
480        id = id,
481        action_id = action_id
482    );
483    let mut local_var_req_builder =
484        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
485
486    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
487        local_var_req_builder =
488            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
489    }
490    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
491        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
492    };
493
494    let local_var_req = local_var_req_builder.build()?;
495    let local_var_resp = local_var_client.execute(local_var_req).await?;
496
497    let local_var_status = local_var_resp.status();
498    let local_var_content = local_var_resp.text().await?;
499
500    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
501        serde_json::from_str(&local_var_content).map_err(Error::from)
502    } else {
503        let local_var_entity: Option<GetActionForVolumeError> =
504            serde_json::from_str(&local_var_content).ok();
505        let local_var_error = ResponseContent {
506            status: local_var_status,
507            content: local_var_content,
508            entity: local_var_entity,
509        };
510        Err(Error::ResponseError(local_var_error))
511    }
512}
513
514/// Gets a specific Volume object.
515pub async fn get_volume(
516    configuration: &configuration::Configuration,
517    params: GetVolumeParams,
518) -> Result<models::GetVolumeResponse, Error<GetVolumeError>> {
519    let local_var_configuration = configuration;
520
521    // unbox the parameters
522    let id = params.id;
523
524    let local_var_client = &local_var_configuration.client;
525
526    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
527    let local_var_uri_str = format!("{}/volumes/{id}", local_base_path, id = id);
528    let mut local_var_req_builder =
529        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
530
531    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
532        local_var_req_builder =
533            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
534    }
535    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
536        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
537    };
538
539    let local_var_req = local_var_req_builder.build()?;
540    let local_var_resp = local_var_client.execute(local_var_req).await?;
541
542    let local_var_status = local_var_resp.status();
543    let local_var_content = local_var_resp.text().await?;
544
545    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
546        serde_json::from_str(&local_var_content).map_err(Error::from)
547    } else {
548        let local_var_entity: Option<GetVolumeError> =
549            serde_json::from_str(&local_var_content).ok();
550        let local_var_error = ResponseContent {
551            status: local_var_status,
552            content: local_var_content,
553            entity: local_var_entity,
554        };
555        Err(Error::ResponseError(local_var_error))
556    }
557}
558
559/// Returns a specific Action object.
560pub async fn get_volume_action(
561    configuration: &configuration::Configuration,
562    params: GetVolumeActionParams,
563) -> Result<models::GetActionResponse, Error<GetVolumeActionError>> {
564    let local_var_configuration = configuration;
565
566    // unbox the parameters
567    let id = params.id;
568
569    let local_var_client = &local_var_configuration.client;
570
571    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
572    let local_var_uri_str = format!("{}/volumes/actions/{id}", local_base_path, id = id);
573    let mut local_var_req_builder =
574        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
575
576    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
577        local_var_req_builder =
578            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
579    }
580    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
581        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
582    };
583
584    let local_var_req = local_var_req_builder.build()?;
585    let local_var_resp = local_var_client.execute(local_var_req).await?;
586
587    let local_var_status = local_var_resp.status();
588    let local_var_content = local_var_resp.text().await?;
589
590    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
591        serde_json::from_str(&local_var_content).map_err(Error::from)
592    } else {
593        let local_var_entity: Option<GetVolumeActionError> =
594            serde_json::from_str(&local_var_content).ok();
595        let local_var_error = ResponseContent {
596            status: local_var_status,
597            content: local_var_content,
598            entity: local_var_entity,
599        };
600        Err(Error::ResponseError(local_var_error))
601    }
602}
603
604/// Returns all Action objects for a Volume. You can `sort` the results by using the sort URI parameter, and filter them with the `status` parameter.
605pub async fn list_actions_for_volume(
606    configuration: &configuration::Configuration,
607    params: ListActionsForVolumeParams,
608) -> Result<models::ListActionsResponse, Error<ListActionsForVolumeError>> {
609    let local_var_configuration = configuration;
610
611    // unbox the parameters
612    let id = params.id;
613    let sort = params.sort;
614    let status = params.status;
615    let page = params.page;
616    let per_page = params.per_page;
617
618    let local_var_client = &local_var_configuration.client;
619
620    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
621    let local_var_uri_str = format!("{}/volumes/{id}/actions", local_base_path, id = id);
622    let mut local_var_req_builder =
623        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
624
625    if let Some(ref local_var_str) = sort {
626        local_var_req_builder = match "multi" {
627            "multi" => local_var_req_builder.query(
628                &local_var_str
629                    .iter()
630                    .map(|p| ("sort".to_owned(), p.to_string()))
631                    .collect::<Vec<(std::string::String, std::string::String)>>(),
632            ),
633            _ => local_var_req_builder.query(&[(
634                "sort",
635                &local_var_str
636                    .iter()
637                    .map(|p| p.to_string())
638                    .collect::<Vec<String>>()
639                    .join(",")
640                    .to_string(),
641            )]),
642        };
643    }
644    if let Some(ref local_var_str) = status {
645        local_var_req_builder = match "multi" {
646            "multi" => local_var_req_builder.query(
647                &local_var_str
648                    .iter()
649                    .map(|p| ("status".to_owned(), p.to_string()))
650                    .collect::<Vec<(std::string::String, std::string::String)>>(),
651            ),
652            _ => local_var_req_builder.query(&[(
653                "status",
654                &local_var_str
655                    .iter()
656                    .map(|p| p.to_string())
657                    .collect::<Vec<String>>()
658                    .join(",")
659                    .to_string(),
660            )]),
661        };
662    }
663    if let Some(ref local_var_str) = page {
664        local_var_req_builder =
665            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
666    }
667    if let Some(ref local_var_str) = per_page {
668        local_var_req_builder =
669            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
670    }
671    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
672        local_var_req_builder =
673            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
674    }
675    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
676        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
677    };
678
679    let local_var_req = local_var_req_builder.build()?;
680    let local_var_resp = local_var_client.execute(local_var_req).await?;
681
682    let local_var_status = local_var_resp.status();
683    let local_var_content = local_var_resp.text().await?;
684
685    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
686        serde_json::from_str(&local_var_content).map_err(Error::from)
687    } else {
688        let local_var_entity: Option<ListActionsForVolumeError> =
689            serde_json::from_str(&local_var_content).ok();
690        let local_var_error = ResponseContent {
691            status: local_var_status,
692            content: local_var_content,
693            entity: local_var_entity,
694        };
695        Err(Error::ResponseError(local_var_error))
696    }
697}
698
699/// Returns all Action objects. You can `sort` the results by using the sort URI parameter, and filter them with the `status` and `id` parameter.
700pub async fn list_volume_actions(
701    configuration: &configuration::Configuration,
702    params: ListVolumeActionsParams,
703) -> Result<models::ListActionsResponse, Error<ListVolumeActionsError>> {
704    let local_var_configuration = configuration;
705
706    // unbox the parameters
707    let id = params.id;
708    let sort = params.sort;
709    let status = params.status;
710    let page = params.page;
711    let per_page = params.per_page;
712
713    let local_var_client = &local_var_configuration.client;
714
715    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
716    let local_var_uri_str = format!("{}/volumes/actions", local_base_path);
717    let mut local_var_req_builder =
718        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
719
720    if let Some(ref local_var_str) = id {
721        local_var_req_builder = match "multi" {
722            "multi" => local_var_req_builder.query(
723                &local_var_str
724                    .iter()
725                    .map(|p| ("id".to_owned(), p.to_string()))
726                    .collect::<Vec<(std::string::String, std::string::String)>>(),
727            ),
728            _ => local_var_req_builder.query(&[(
729                "id",
730                &local_var_str
731                    .iter()
732                    .map(|p| p.to_string())
733                    .collect::<Vec<String>>()
734                    .join(",")
735                    .to_string(),
736            )]),
737        };
738    }
739    if let Some(ref local_var_str) = sort {
740        local_var_req_builder = match "multi" {
741            "multi" => local_var_req_builder.query(
742                &local_var_str
743                    .iter()
744                    .map(|p| ("sort".to_owned(), p.to_string()))
745                    .collect::<Vec<(std::string::String, std::string::String)>>(),
746            ),
747            _ => local_var_req_builder.query(&[(
748                "sort",
749                &local_var_str
750                    .iter()
751                    .map(|p| p.to_string())
752                    .collect::<Vec<String>>()
753                    .join(",")
754                    .to_string(),
755            )]),
756        };
757    }
758    if let Some(ref local_var_str) = status {
759        local_var_req_builder = match "multi" {
760            "multi" => local_var_req_builder.query(
761                &local_var_str
762                    .iter()
763                    .map(|p| ("status".to_owned(), p.to_string()))
764                    .collect::<Vec<(std::string::String, std::string::String)>>(),
765            ),
766            _ => local_var_req_builder.query(&[(
767                "status",
768                &local_var_str
769                    .iter()
770                    .map(|p| p.to_string())
771                    .collect::<Vec<String>>()
772                    .join(",")
773                    .to_string(),
774            )]),
775        };
776    }
777    if let Some(ref local_var_str) = page {
778        local_var_req_builder =
779            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
780    }
781    if let Some(ref local_var_str) = per_page {
782        local_var_req_builder =
783            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
784    }
785    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
786        local_var_req_builder =
787            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
788    }
789    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
790        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
791    };
792
793    let local_var_req = local_var_req_builder.build()?;
794    let local_var_resp = local_var_client.execute(local_var_req).await?;
795
796    let local_var_status = local_var_resp.status();
797    let local_var_content = local_var_resp.text().await?;
798
799    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
800        serde_json::from_str(&local_var_content).map_err(Error::from)
801    } else {
802        let local_var_entity: Option<ListVolumeActionsError> =
803            serde_json::from_str(&local_var_content).ok();
804        let local_var_error = ResponseContent {
805            status: local_var_status,
806            content: local_var_content,
807            entity: local_var_entity,
808        };
809        Err(Error::ResponseError(local_var_error))
810    }
811}
812
813/// Gets all existing Volumes that you have available.
814pub async fn list_volumes(
815    configuration: &configuration::Configuration,
816    params: ListVolumesParams,
817) -> Result<models::ListVolumesResponse, Error<ListVolumesError>> {
818    let local_var_configuration = configuration;
819
820    // unbox the parameters
821    let status = params.status;
822    let sort = params.sort;
823    let name = params.name;
824    let label_selector = params.label_selector;
825    let page = params.page;
826    let per_page = params.per_page;
827
828    let local_var_client = &local_var_configuration.client;
829
830    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
831    let local_var_uri_str = format!("{}/volumes", local_base_path);
832    let mut local_var_req_builder =
833        local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
834
835    if let Some(ref local_var_str) = status {
836        local_var_req_builder = match "multi" {
837            "multi" => local_var_req_builder.query(
838                &local_var_str
839                    .iter()
840                    .map(|p| ("status".to_owned(), p.to_string()))
841                    .collect::<Vec<(std::string::String, std::string::String)>>(),
842            ),
843            _ => local_var_req_builder.query(&[(
844                "status",
845                &local_var_str
846                    .iter()
847                    .map(|p| p.to_string())
848                    .collect::<Vec<String>>()
849                    .join(",")
850                    .to_string(),
851            )]),
852        };
853    }
854    if let Some(ref local_var_str) = sort {
855        local_var_req_builder = match "multi" {
856            "multi" => local_var_req_builder.query(
857                &local_var_str
858                    .iter()
859                    .map(|p| ("sort".to_owned(), p.to_string()))
860                    .collect::<Vec<(std::string::String, std::string::String)>>(),
861            ),
862            _ => local_var_req_builder.query(&[(
863                "sort",
864                &local_var_str
865                    .iter()
866                    .map(|p| p.to_string())
867                    .collect::<Vec<String>>()
868                    .join(",")
869                    .to_string(),
870            )]),
871        };
872    }
873    if let Some(ref local_var_str) = name {
874        local_var_req_builder =
875            local_var_req_builder.query(&[("name", &local_var_str.to_string())]);
876    }
877    if let Some(ref local_var_str) = label_selector {
878        local_var_req_builder =
879            local_var_req_builder.query(&[("label_selector", &local_var_str.to_string())]);
880    }
881    if let Some(ref local_var_str) = page {
882        local_var_req_builder =
883            local_var_req_builder.query(&[("page", &local_var_str.to_string())]);
884    }
885    if let Some(ref local_var_str) = per_page {
886        local_var_req_builder =
887            local_var_req_builder.query(&[("per_page", &local_var_str.to_string())]);
888    }
889    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
890        local_var_req_builder =
891            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
892    }
893    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
894        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
895    };
896
897    let local_var_req = local_var_req_builder.build()?;
898    let local_var_resp = local_var_client.execute(local_var_req).await?;
899
900    let local_var_status = local_var_resp.status();
901    let local_var_content = local_var_resp.text().await?;
902
903    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
904        serde_json::from_str(&local_var_content).map_err(Error::from)
905    } else {
906        let local_var_entity: Option<ListVolumesError> =
907            serde_json::from_str(&local_var_content).ok();
908        let local_var_error = ResponseContent {
909            status: local_var_status,
910            content: local_var_content,
911            entity: local_var_entity,
912        };
913        Err(Error::ResponseError(local_var_error))
914    }
915}
916
917/// Updates the Volume properties.
918pub async fn replace_volume(
919    configuration: &configuration::Configuration,
920    params: ReplaceVolumeParams,
921) -> Result<models::ReplaceVolumeResponse, Error<ReplaceVolumeError>> {
922    let local_var_configuration = configuration;
923
924    // unbox the parameters
925    let id = params.id;
926    let replace_volume_request = params.replace_volume_request;
927
928    let local_var_client = &local_var_configuration.client;
929
930    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
931    let local_var_uri_str = format!("{}/volumes/{id}", local_base_path, id = id);
932    let mut local_var_req_builder =
933        local_var_client.request(reqwest::Method::PUT, local_var_uri_str.as_str());
934
935    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
936        local_var_req_builder =
937            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
938    }
939    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
940        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
941    };
942    local_var_req_builder = local_var_req_builder.json(&replace_volume_request);
943
944    let local_var_req = local_var_req_builder.build()?;
945    let local_var_resp = local_var_client.execute(local_var_req).await?;
946
947    let local_var_status = local_var_resp.status();
948    let local_var_content = local_var_resp.text().await?;
949
950    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
951        serde_json::from_str(&local_var_content).map_err(Error::from)
952    } else {
953        let local_var_entity: Option<ReplaceVolumeError> =
954            serde_json::from_str(&local_var_content).ok();
955        let local_var_error = ResponseContent {
956            status: local_var_status,
957            content: local_var_content,
958            entity: local_var_entity,
959        };
960        Err(Error::ResponseError(local_var_error))
961    }
962}
963
964/// Changes the size of a Volume. Note that downsizing a Volume is not possible.
965pub async fn resize_volume(
966    configuration: &configuration::Configuration,
967    params: ResizeVolumeParams,
968) -> Result<models::ResizeVolumeResponse, Error<ResizeVolumeError>> {
969    let local_var_configuration = configuration;
970
971    // unbox the parameters
972    let id = params.id;
973    let resize_volume_request = params.resize_volume_request;
974
975    let local_var_client = &local_var_configuration.client;
976
977    let local_base_path = local_var_configuration.get_base_path("https://api.hetzner.cloud/v1");
978    let local_var_uri_str = format!("{}/volumes/{id}/actions/resize", local_base_path, id = id);
979    let mut local_var_req_builder =
980        local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
981
982    if let Some(ref local_var_user_agent) = local_var_configuration.user_agent {
983        local_var_req_builder =
984            local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
985    }
986    if let Some(ref local_var_token) = local_var_configuration.bearer_access_token {
987        local_var_req_builder = local_var_req_builder.bearer_auth(local_var_token.to_owned());
988    };
989    local_var_req_builder = local_var_req_builder.json(&resize_volume_request);
990
991    let local_var_req = local_var_req_builder.build()?;
992    let local_var_resp = local_var_client.execute(local_var_req).await?;
993
994    let local_var_status = local_var_resp.status();
995    let local_var_content = local_var_resp.text().await?;
996
997    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
998        serde_json::from_str(&local_var_content).map_err(Error::from)
999    } else {
1000        let local_var_entity: Option<ResizeVolumeError> =
1001            serde_json::from_str(&local_var_content).ok();
1002        let local_var_error = ResponseContent {
1003            status: local_var_status,
1004            content: local_var_content,
1005            entity: local_var_entity,
1006        };
1007        Err(Error::ResponseError(local_var_error))
1008    }
1009}