Skip to main content

openstack_cli_placement/v1/trait/
list.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//! List Traits command
19//!
20//! Wraps invoking of the `traits` with `GET` 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::list;
32use openstack_types::placement::v1::r#trait::response;
33
34/// Return a list of valid trait strings according to parameters specified.
35///
36/// Normal Response Codes: 200
37#[derive(Args)]
38#[command(about = "List traits")]
39pub struct TraitsCommand {
40    /// Request Query parameters
41    #[command(flatten)]
42    query: QueryParameters,
43
44    /// Path parameters
45    #[command(flatten)]
46    path: PathParameters,
47}
48
49/// Query parameters
50#[derive(Args)]
51struct QueryParameters {
52    /// If this parameter has a true value, the returned traits will be those
53    /// that are associated with at least one resource provider. Available
54    /// values for the parameter are true and false.
55    #[arg(action=clap::ArgAction::SetTrue, help_heading = "Query parameters", long)]
56    associated: Option<bool>,
57
58    /// The name of a resource provider to filter the list.
59    #[arg(help_heading = "Query parameters", long)]
60    name: Option<String>,
61}
62
63/// Path parameters
64#[derive(Args)]
65struct PathParameters {}
66
67impl TraitsCommand {
68    /// Perform command action
69    pub async fn take_action<C: CliArgs>(
70        &self,
71        parsed_args: &C,
72        client: &mut AsyncOpenStack,
73    ) -> Result<(), OpenStackCliError> {
74        info!("List Traits");
75
76        let op = OutputProcessor::from_args(parsed_args, Some("placement.trait"), Some("list"));
77        op.validate_args(parsed_args)?;
78
79        let mut ep_builder = list::Request::builder();
80
81        // Set query parameters
82        if let Some(val) = &self.query.associated {
83            ep_builder.associated(*val);
84        }
85        if let Some(val) = &self.query.name {
86            ep_builder.name(val);
87        }
88
89        let ep = ep_builder
90            .build()
91            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
92
93        let data: Vec<serde_json::Value> = ep.query_async(client).await?;
94
95        op.output_list::<response::list::TraitResponse>(data.clone())?;
96        // Show command specific hints
97        op.show_command_hint()?;
98        Ok(())
99    }
100}