Skip to main content

openstack_cli_block_storage/v3/volume_transfer/
create_355.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//! Create VolumeTransfer command [microversion = 3.55]
19//!
20//! Wraps invoking of the `v3/volume-transfers` with `POST` 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::volume_transfer::create_355;
33use openstack_types::block_storage::v3::volume_transfer::response;
34
35/// Create a new volume transfer.
36#[derive(Args)]
37pub struct VolumeTransferCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// The volume transfer object.
47    #[command(flatten)]
48    transfer: Transfer,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Path parameters
56#[derive(Args)]
57struct PathParameters {}
58/// Transfer Body data
59#[derive(Args, Clone)]
60struct Transfer {
61    /// The name of the object.
62    #[arg(help_heading = "Body parameters", long)]
63    name: Option<String>,
64
65    /// Set explicit NULL for the name
66    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "name")]
67    no_name: bool,
68
69    /// Transfer volume without snapshots. Defaults to False if not specified.
70    ///
71    /// **New in version 3.55**
72    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
73    no_snapshots: Option<bool>,
74
75    /// The UUID of the volume.
76    #[arg(help_heading = "Body parameters", long)]
77    volume_id: String,
78}
79
80impl VolumeTransferCommand {
81    /// Perform command action
82    pub async fn take_action<C: CliArgs>(
83        &self,
84        parsed_args: &C,
85        client: &mut AsyncOpenStack,
86    ) -> Result<(), OpenStackCliError> {
87        info!("Create VolumeTransfer");
88
89        let op = OutputProcessor::from_args(
90            parsed_args,
91            Some("block-storage.volume_transfer"),
92            Some("create"),
93        );
94        op.validate_args(parsed_args)?;
95
96        let mut ep_builder = create_355::Request::builder();
97        ep_builder.header(
98            http::header::HeaderName::from_static("openstack-api-version"),
99            http::header::HeaderValue::from_static("volume 3.55"),
100        );
101
102        // Set body parameters
103        // Set Request.transfer data
104        let args = &self.transfer;
105        let mut transfer_builder = create_355::TransferBuilder::default();
106        if let Some(val) = &args.name {
107            transfer_builder.name(Some(val.into()));
108        } else if args.no_name {
109            transfer_builder.name(None);
110        }
111
112        if let Some(val) = &args.no_snapshots {
113            transfer_builder.no_snapshots(*val);
114        }
115
116        transfer_builder.volume_id(&args.volume_id);
117
118        ep_builder.transfer(
119            transfer_builder
120                .build()
121                .wrap_err("error preparing the request data")?,
122        );
123
124        let ep = ep_builder
125            .build()
126            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
127
128        let data: serde_json::Value = ep.query_async(client).await?;
129
130        op.output_single::<response::create::VolumeTransferResponse>(data.clone())?;
131        // Show command specific hints
132        op.show_command_hint()?;
133        Ok(())
134    }
135}