Skip to main content

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