openstack_cli/block_storage/v3/qos_spec/
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 QosSpec command
19//!
20//! Wraps invoking of the `v3/qos-specs` with `POST` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_sdk::AsyncOpenStack;
27
28use crate::Cli;
29use crate::OpenStackCliError;
30use crate::output::OutputProcessor;
31
32use openstack_sdk::api::QueryAsync;
33use openstack_sdk::api::block_storage::v3::qos_spec::create;
34use openstack_types::block_storage::v3::qos_spec::response::create::QosSpecResponse;
35
36/// Command without description in OpenAPI
37#[derive(Args)]
38pub struct QosSpecCommand {
39    /// Request Query parameters
40    #[command(flatten)]
41    query: QueryParameters,
42
43    /// Path parameters
44    #[command(flatten)]
45    path: PathParameters,
46
47    /// A `qos_specs` object.
48    #[command(flatten)]
49    qos_specs: QosSpecs,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {}
55
56/// Path parameters
57#[derive(Args)]
58struct PathParameters {}
59/// QosSpecs Body data
60#[derive(Args, Clone)]
61struct QosSpecs {
62    /// The name of the QoS specification.
63    #[arg(help_heading = "Body parameters", long)]
64    name: String,
65}
66
67impl QosSpecCommand {
68    /// Perform command action
69    pub async fn take_action(
70        &self,
71        parsed_args: &Cli,
72        client: &mut AsyncOpenStack,
73    ) -> Result<(), OpenStackCliError> {
74        info!("Create QosSpec");
75
76        let op =
77            OutputProcessor::from_args(parsed_args, Some("block-storage.qos_spec"), Some("create"));
78        op.validate_args(parsed_args)?;
79
80        let mut ep_builder = create::Request::builder();
81
82        // Set body parameters
83        // Set Request.qos_specs data
84        let args = &self.qos_specs;
85        let mut qos_specs_builder = create::QosSpecsBuilder::default();
86
87        qos_specs_builder.name(&args.name);
88
89        ep_builder.qos_specs(
90            qos_specs_builder
91                .build()
92                .wrap_err("error preparing the request data")?,
93        );
94
95        let ep = ep_builder
96            .build()
97            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
98
99        let data = ep.query_async(client).await?;
100        op.output_single::<QosSpecResponse>(data)?;
101        // Show command specific hints
102        op.show_command_hint()?;
103        Ok(())
104    }
105}