Skip to main content

openstack_cli_block_storage/v3/backup/
set_39.rs

1// Licensed under the Apache License, Version 2.0 (the "License");
2// you may not use this file except in compliance with the License.
3// You may obtain a copy of the License at
4//
5//     http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS,
9// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10// See the License for the specific language governing permissions and
11// limitations under the License.
12//
13// SPDX-License-Identifier: Apache-2.0
14//
15// WARNING: This file is automatically generated from OpenAPI schema using
16// `openstack-codegenerator`.
17
18//! Set Backup command [microversion = 3.9]
19//!
20//! Wraps invoking of the `v3/backups/{id}` with `PUT` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::block_storage::v3::backup::find;
33use openstack_sdk::api::block_storage::v3::backup::set_39;
34use openstack_sdk::api::find;
35use openstack_types::block_storage::v3::backup::response;
36
37/// Update a backup.
38#[derive(Args)]
39pub struct BackupCommand {
40    /// Request Query parameters
41    #[command(flatten)]
42    query: QueryParameters,
43
44    /// Path parameters
45    #[command(flatten)]
46    path: PathParameters,
47
48    #[command(flatten)]
49    backup: Option<Backup>,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {}
55
56/// Path parameters
57#[derive(Args)]
58struct PathParameters {
59    /// id parameter for /v3/backups/{id} API
60    #[arg(
61        help_heading = "Path parameters",
62        id = "path_param_id",
63        value_name = "ID"
64    )]
65    id: String,
66}
67/// Backup Body data
68#[derive(Args, Clone)]
69struct Backup {
70    #[arg(help_heading = "Body parameters", long)]
71    description: Option<String>,
72
73    /// Set explicit NULL for the description
74    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "description")]
75    no_description: bool,
76
77    #[arg(help_heading = "Body parameters", long)]
78    name: Option<String>,
79
80    /// Set explicit NULL for the name
81    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "name")]
82    no_name: bool,
83}
84
85impl BackupCommand {
86    /// Perform command action
87    pub async fn take_action<C: CliArgs>(
88        &self,
89        parsed_args: &C,
90        client: &mut AsyncOpenStack,
91    ) -> Result<(), OpenStackCliError> {
92        info!("Set Backup");
93
94        let op = OutputProcessor::from_args(parsed_args, Some("block-storage.backup"), Some("set"));
95        op.validate_args(parsed_args)?;
96
97        let mut find_builder = find::Request::builder();
98
99        find_builder.id(&self.path.id);
100        find_builder.header(
101            http::header::HeaderName::from_static("openstack-api-version"),
102            http::header::HeaderValue::from_static("volume 3.9"),
103        );
104
105        let find_ep = find_builder
106            .build()
107            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
108        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
109
110        let mut ep_builder = set_39::Request::builder();
111        ep_builder.header(
112            http::header::HeaderName::from_static("openstack-api-version"),
113            http::header::HeaderValue::from_static("volume 3.9"),
114        );
115
116        let resource_id = find_data["id"]
117            .as_str()
118            .ok_or_else(|| eyre::eyre!("resource ID must be a string"))?
119            .to_string();
120        ep_builder.id(resource_id.clone());
121
122        // Set body parameters
123        // Set Request.backup data
124        if let Some(lbackup) = &self.backup {
125            let mut backup_builder = set_39::BackupBuilder::default();
126            if let Some(val) = &lbackup.description {
127                backup_builder.description(Some(val.into()));
128            }
129            if let Some(val) = &lbackup.name {
130                backup_builder.name(Some(val.into()));
131            }
132            ep_builder.backup(
133                backup_builder
134                    .build()
135                    .wrap_err("error preparing the request data")?,
136            );
137        }
138
139        let ep = ep_builder
140            .build()
141            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
142
143        let data: serde_json::Value = ep.query_async(client).await?;
144
145        op.output_single::<response::set::BackupResponse>(data.clone())?;
146        // Show command specific hints
147        op.show_command_hint()?;
148        Ok(())
149    }
150}