openstack_cli/block_storage/v3/volume/metadata/
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 Metadata command
19//!
20//! Wraps invoking of the `v3/volumes/{volume_id}/metadata` with `POST` method
21
22use clap::Args;
23use tracing::info;
24
25use openstack_sdk::AsyncOpenStack;
26
27use crate::Cli;
28use crate::OpenStackCliError;
29use crate::output::OutputProcessor;
30
31use crate::common::parse_key_val;
32use openstack_sdk::api::QueryAsync;
33use openstack_sdk::api::block_storage::v3::volume::metadata::create;
34use openstack_types::block_storage::v3::volume::metadata::response::create::MetadataResponse;
35
36/// Command without description in OpenAPI
37#[derive(Args)]
38pub struct MetadataCommand {
39    /// Request Query parameters
40    #[command(flatten)]
41    query: QueryParameters,
42
43    /// Path parameters
44    #[command(flatten)]
45    path: PathParameters,
46
47    /// One or more metadata key and value pairs that are associated with the
48    /// volume.
49    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
50    metadata: Vec<(String, String)>,
51}
52
53/// Query parameters
54#[derive(Args)]
55struct QueryParameters {}
56
57/// Path parameters
58#[derive(Args)]
59struct PathParameters {
60    /// volume_id parameter for /v3/volumes/{volume_id}/metadata API
61    #[arg(
62        help_heading = "Path parameters",
63        id = "path_param_volume_id",
64        value_name = "VOLUME_ID"
65    )]
66    volume_id: String,
67}
68
69impl MetadataCommand {
70    /// Perform command action
71    pub async fn take_action(
72        &self,
73        parsed_args: &Cli,
74        client: &mut AsyncOpenStack,
75    ) -> Result<(), OpenStackCliError> {
76        info!("Create Metadata");
77
78        let op = OutputProcessor::from_args(
79            parsed_args,
80            Some("block-storage.volume/metadata"),
81            Some("create"),
82        );
83        op.validate_args(parsed_args)?;
84
85        let mut ep_builder = create::Request::builder();
86
87        ep_builder.volume_id(&self.path.volume_id);
88
89        // Set body parameters
90        // Set Request.metadata data
91
92        ep_builder.metadata(self.metadata.iter().cloned());
93
94        let ep = ep_builder
95            .build()
96            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
97
98        let data = ep.query_async(client).await?;
99        op.output_single::<MetadataResponse>(data)?;
100        // Show command specific hints
101        op.show_command_hint()?;
102        Ok(())
103    }
104}