Skip to main content

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