Skip to main content

openstack_cli_block_storage/v3/os_volume_transfer/
create.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 OsVolumeTransfer command
19//!
20//! Wraps invoking of the `v3/os-volume-transfer` 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::os_volume_transfer::create;
33use openstack_types::block_storage::v3::os_volume_transfer::response;
34
35/// Create a new volume transfer.
36#[derive(Args)]
37pub struct OsVolumeTransferCommand {
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    /// The UUID of the volume.
70    #[arg(help_heading = "Body parameters", long)]
71    volume_id: String,
72}
73
74impl OsVolumeTransferCommand {
75    /// Perform command action
76    pub async fn take_action<C: CliArgs>(
77        &self,
78        parsed_args: &C,
79        client: &mut AsyncOpenStack,
80    ) -> Result<(), OpenStackCliError> {
81        info!("Create OsVolumeTransfer");
82
83        let op = OutputProcessor::from_args(
84            parsed_args,
85            Some("block-storage.os_volume_transfer"),
86            Some("create"),
87        );
88        op.validate_args(parsed_args)?;
89
90        let mut ep_builder = create::Request::builder();
91
92        // Set body parameters
93        // Set Request.transfer data
94        let args = &self.transfer;
95        let mut transfer_builder = create::TransferBuilder::default();
96        if let Some(val) = &args.name {
97            transfer_builder.name(Some(val.into()));
98        } else if args.no_name {
99            transfer_builder.name(None);
100        }
101
102        transfer_builder.volume_id(&args.volume_id);
103
104        ep_builder.transfer(
105            transfer_builder
106                .build()
107                .wrap_err("error preparing the request data")?,
108        );
109
110        let ep = ep_builder
111            .build()
112            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
113
114        let data: serde_json::Value = ep.query_async(client).await?;
115
116        op.output_single::<response::create::OsVolumeTransferResponse>(data.clone())?;
117        // Show command specific hints
118        op.show_command_hint()?;
119        Ok(())
120    }
121}