openstack_cli_placement/v1/trait/set.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 Trait command
19//!
20//! Wraps invoking of the `traits/{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::r#trait::set;
32
33/// Insert a new custom trait. If traits already exists 204 will be returned.
34///
35/// There are two kinds of traits: the standard traits and the custom traits.
36/// The standard traits are interoperable across different OpenStack cloud
37/// deployments. The definition of standard traits comes from the os-traits
38/// library. The standard traits are read-only in the placement API which means
39/// that the user can’t modify any standard traits through API. The custom
40/// traits are used by admin users to manage the non-standard qualitative
41/// information of resource providers.
42///
43/// Normal Response Codes: 201, 204
44///
45/// Error response codes: badRequest(400)
46#[derive(Args)]
47#[command(about = "Update traits")]
48pub struct TraitCommand {
49 /// Request Query parameters
50 #[command(flatten)]
51 query: QueryParameters,
52
53 /// Path parameters
54 #[command(flatten)]
55 path: PathParameters,
56}
57
58/// Query parameters
59#[derive(Args)]
60struct QueryParameters {}
61
62/// Path parameters
63#[derive(Args)]
64struct PathParameters {
65 /// name parameter for /traits/{name} API
66 #[arg(
67 help_heading = "Path parameters",
68 id = "path_param_name",
69 value_name = "NAME"
70 )]
71 name: String,
72}
73
74impl TraitCommand {
75 /// Perform command action
76 pub async fn take_action<C: CliArgs>(
77 &self,
78 parsed_args: &C,
79 client: &mut AsyncOpenStack,
80 ) -> Result<(), OpenStackCliError> {
81 info!("Set Trait");
82
83 let op = OutputProcessor::from_args(parsed_args, Some("placement.trait"), Some("set"));
84 op.validate_args(parsed_args)?;
85
86 let mut ep_builder = set::Request::builder();
87
88 ep_builder.name(&self.path.name);
89
90 let ep = ep_builder
91 .build()
92 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
93 openstack_sdk::api::ignore(ep).query_async(client).await?;
94 // Show command specific hints
95 op.show_command_hint()?;
96 Ok(())
97 }
98}