Skip to main content

openstack_cli_placement/v1/resource_class/
set_17.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//! Set ResourceClass command [microversion = 1.7]
19//!
20//! Wraps invoking of the `resource_classes/{name}` with `PUT` 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::set_17;
32
33/// Create or validate the existence of single resource class identified by
34/// {name}.
35///
36/// Normal Response Codes: 201, 204
37///
38/// A 201 Created response code will be returned if the new resource class is
39/// successfully created. A 204 No Content response code will be returned if
40/// the resource class already exists.
41///
42/// Error response codes: badRequest(400)
43#[derive(Args)]
44#[command(about = "Update resource class (microversion = 1.7)")]
45pub struct ResourceClassCommand {
46    /// Request Query parameters
47    #[command(flatten)]
48    query: QueryParameters,
49
50    /// Path parameters
51    #[command(flatten)]
52    path: PathParameters,
53}
54
55/// Query parameters
56#[derive(Args)]
57struct QueryParameters {}
58
59/// Path parameters
60#[derive(Args)]
61struct PathParameters {
62    /// name parameter for /resource_classes/{name} API
63    #[arg(
64        help_heading = "Path parameters",
65        id = "path_param_name",
66        value_name = "NAME"
67    )]
68    name: String,
69}
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!("Set ResourceClass");
79
80        let op =
81            OutputProcessor::from_args(parsed_args, Some("placement.resource_class"), Some("set"));
82        op.validate_args(parsed_args)?;
83
84        let mut ep_builder = set_17::Request::builder();
85        ep_builder.header(
86            http::header::HeaderName::from_static("openstack-api-version"),
87            http::header::HeaderValue::from_static("placement 1.7"),
88        );
89
90        ep_builder.name(&self.path.name);
91
92        let ep = ep_builder
93            .build()
94            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
95        openstack_sdk::api::ignore(ep).query_async(client).await?;
96        // Show command specific hints
97        op.show_command_hint()?;
98        Ok(())
99    }
100}