Skip to main content

openstack_cli_placement/v1/resource_provider/
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 ResourceProviders command
19//!
20//! Wraps invoking of the `resource_providers` 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::resource_provider::list;
32use openstack_types::placement::v1::resource_provider::response;
33
34/// List an optionally filtered collection of resource providers.
35///
36/// Normal Response Codes: 200
37///
38/// Error response codes: badRequest(400)
39///
40/// A 400 BadRequest response code will be returned if a resource class
41/// specified in `resources` request parameter does not exist.
42#[derive(Args)]
43#[command(about = "List resource providers")]
44pub struct ResourceProvidersCommand {
45    /// Request Query parameters
46    #[command(flatten)]
47    query: QueryParameters,
48
49    /// Path parameters
50    #[command(flatten)]
51    path: PathParameters,
52}
53
54/// Query parameters
55#[derive(Args)]
56struct QueryParameters {
57    /// A string representing a resource provider uuid. When supplied, it will
58    /// filter the returned allocation candidates to only those resource
59    /// providers that are in the same tree with the given resource provider.
60    #[arg(help_heading = "Query parameters", long)]
61    in_tree: Option<String>,
62
63    /// A string representing an aggregate uuid; or the prefix in: followed by
64    /// a comma-separated list of strings representing aggregate uuids. The
65    /// resource providers in the allocation request in the response must
66    /// directly or via the root provider be associated with the aggregate or
67    /// aggregates identified by uuid:
68    /// `member_of=5e08ea53-c4c6-448e-9334-ac4953de3cfa`,
69    /// `member_of=in:42896e0d-205d-4fe3-bd1e-100924931787,5e08ea53-c4c6-448e-9334-ac4953de3cfa`
70    /// Starting from microversion 1.24 specifying multiple member_of query
71    /// string parameters is possible. Multiple member_of parameters will
72    /// result in filtering providers that are directly or via root provider
73    /// associated with aggregates listed in all of the member_of query string
74    /// values. For example, to get the providers that are associated with
75    /// aggregate A as well as associated with any of aggregates B or C, the
76    /// user could issue the following query:
77    /// `member_of=AGGA_UUID&member_of=in:AGGB_UUID,AGGC_UUID` Starting from
78    /// microversion 1.32 specifying forbidden aggregates is supported in the
79    /// member_of query string parameter. Forbidden aggregates are prefixed
80    /// with a !. This negative expression can also be used in multiple
81    /// member_of parameters: `member_of=AGGA_UUID&member_of=!AGGB_UUID` would
82    /// translate logically to “Candidate resource providers must be in AGGA
83    /// and not in AGGB.” We do NOT support ! on the values within in:, but we
84    /// support !in:. Both of the following two example queries return
85    /// candidate resource providers that are NOT in AGGA, AGGB, or AGGC:
86    /// `member_of=!in:AGGA_UUID,AGGB_UUID,AGGC_UUID`,
87    /// `member_of=!AGGA_UUID&member_of=!AGGB_UUID&member_of=!AGGC_UUID` We do
88    /// not check if the same aggregate uuid is in both positive and negative
89    /// expression to return 400 BadRequest. We still return 200 for such
90    /// cases. For example: `member_of=AGGA_UUID&member_of=!AGGA_UUID` would
91    /// return empty allocation_requests and provider_summaries, while:
92    /// `member_of=in:AGGA_UUID,AGGB_UUID&member_of=!AGGA_UUID` would return
93    /// resource providers that are NOT in AGGA but in AGGB.
94    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
95    member_of: Option<Vec<String>>,
96
97    /// The name of a resource provider to filter the list.
98    #[arg(help_heading = "Query parameters", long)]
99    name: Option<String>,
100
101    /// A comma-separated list of traits that a provider must have:
102    /// `required=HW_CPU_X86_AVX,HW_CPU_X86_SSE` Allocation requests in the
103    /// response will be for resource providers that have capacity for all
104    /// requested resources and the set of those resource providers will
105    /// collectively contain all of the required traits. These traits may be
106    /// satisfied by any provider in the same non-sharing tree or associated
107    /// via aggregate as far as that provider also contributes resource to the
108    /// request. Starting from microversion 1.22 traits which are forbidden
109    /// from any resource provider contributing resources to the request may be
110    /// expressed by prefixing a trait with a `!`. Starting from microversion
111    /// 1.39 the required query parameter can be repeated. The trait lists from
112    /// the repeated parameters are AND-ed together. So:
113    /// `required=T1,!T2&required=T3` means T1 and not T2 and T3. Also starting
114    /// from microversion 1.39 the required parameter supports the syntax:
115    /// `required=in:T1,T2,T3` which means T1 or T2 or T3. Mixing forbidden
116    /// traits into an in: prefixed value is not supported and rejected. But
117    /// mixing a normal trait list and an in: prefixed trait list in two query
118    /// params within the same request is supported. So:
119    /// `required=in:T3,T4&required=T1,!T2` is supported and it means T1 and
120    /// not T2 and (T3 or T4).
121    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
122    required: Option<Vec<String>>,
123
124    /// A comma-separated list of strings indicating an amount of resource of a
125    /// specified class that providers in each allocation request must
126    /// collectively have the capacity and availability to serve:
127    /// `resources=VCPU:4,DISK_GB:64,MEMORY_MB:2048` These resources may be
128    /// satisfied by any provider in the same non-sharing tree or associated
129    /// via aggregate.
130    #[arg(help_heading = "Query parameters", long)]
131    resources: Option<String>,
132
133    /// The uuid of a resource provider.
134    #[arg(help_heading = "Query parameters", long)]
135    uuid: Option<String>,
136}
137
138/// Path parameters
139#[derive(Args)]
140struct PathParameters {}
141
142impl ResourceProvidersCommand {
143    /// Perform command action
144    pub async fn take_action<C: CliArgs>(
145        &self,
146        parsed_args: &C,
147        client: &mut AsyncOpenStack,
148    ) -> Result<(), OpenStackCliError> {
149        info!("List ResourceProviders");
150
151        let op = OutputProcessor::from_args(
152            parsed_args,
153            Some("placement.resource_provider"),
154            Some("list"),
155        );
156        op.validate_args(parsed_args)?;
157
158        let mut ep_builder = list::Request::builder();
159
160        // Set query parameters
161        if let Some(val) = &self.query.in_tree {
162            ep_builder.in_tree(val);
163        }
164        if let Some(val) = &self.query.member_of {
165            ep_builder.member_of(val.iter());
166        }
167        if let Some(val) = &self.query.name {
168            ep_builder.name(val);
169        }
170        if let Some(val) = &self.query.required {
171            ep_builder.required(val.iter());
172        }
173        if let Some(val) = &self.query.resources {
174            ep_builder.resources(val);
175        }
176        if let Some(val) = &self.query.uuid {
177            ep_builder.uuid(val);
178        }
179
180        let ep = ep_builder
181            .build()
182            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
183
184        let data: Vec<serde_json::Value> = ep.query_async(client).await?;
185
186        op.output_list::<response::list::ResourceProviderResponse>(data.clone())?;
187        // Show command specific hints
188        op.show_command_hint()?;
189        Ok(())
190    }
191}