Skip to main content

openstack_cli_placement/v1/resource_class/
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 ResourceClass command
19//!
20//! Wraps invoking of the `resource_classes` with `POST` method
21
22use clap::Args;
23use tracing::info;
24
25use openstack_cli_core::cli::CliArgs;
26use openstack_cli_core::error::OpenStackCliError;
27use openstack_cli_core::output::OutputProcessor;
28use openstack_sdk::AsyncOpenStack;
29
30use openstack_sdk::api::QueryAsync;
31use openstack_sdk::api::placement::v1::resource_class::create;
32use openstack_types::placement::v1::resource_class::response;
33
34/// Create a new resource class. The new class must be a *custom* resource
35/// class, prefixed with CUSTOM\_ and distinct from the standard resource
36/// classes.
37///
38/// Normal Response Codes: 201
39///
40/// Error response codes: badRequest(400), conflict(409)
41///
42/// A 400 BadRequest response code will be returned if the resource class does
43/// not have prefix CUSTOM\_.
44///
45/// A 409 Conflict response code will be returned if another resource class
46/// exists with the provided name.
47#[derive(Args)]
48#[command(about = "Create resource class")]
49pub struct ResourceClassCommand {
50    /// Request Query parameters
51    #[command(flatten)]
52    query: QueryParameters,
53
54    /// Path parameters
55    #[command(flatten)]
56    path: PathParameters,
57
58    /// The name of one resource class.
59    #[arg(help_heading = "Body parameters", long)]
60    name: String,
61}
62
63/// Query parameters
64#[derive(Args)]
65struct QueryParameters {}
66
67/// Path parameters
68#[derive(Args)]
69struct PathParameters {}
70
71impl ResourceClassCommand {
72    /// Perform command action
73    pub async fn take_action<C: CliArgs>(
74        &self,
75        parsed_args: &C,
76        client: &mut AsyncOpenStack,
77    ) -> Result<(), OpenStackCliError> {
78        info!("Create ResourceClass");
79
80        let op = OutputProcessor::from_args(
81            parsed_args,
82            Some("placement.resource_class"),
83            Some("create"),
84        );
85        op.validate_args(parsed_args)?;
86
87        let mut ep_builder = create::Request::builder();
88
89        // Set body parameters
90        // Set Request.name data
91        ep_builder.name(&self.name);
92
93        let ep = ep_builder
94            .build()
95            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
96
97        let data: serde_json::Value = ep.query_async(client).await?;
98
99        op.output_single::<response::create::ResourceClassResponse>(data.clone())?;
100        // Show command specific hints
101        op.show_command_hint()?;
102        Ok(())
103    }
104}