openstack_cli_placement/v1/allocation_candidate/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//! Show AllocationCandidate command
19//!
20//! Wraps invoking of the `allocation_candidates` 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::allocation_candidate::list;
32use openstack_types::placement::v1::allocation_candidate::response;
33
34/// Returns a dictionary representing a collection of allocation requests and
35/// resource provider summaries. Each allocation request has information to
36/// form a `PUT /allocations/{consumer_uuid}` request to claim resources
37/// against a related set of resource providers. Additional parameters might be
38/// required, see [Update allocations](#update-allocations). As several
39/// allocation requests are available it’s necessary to select one. To make a
40/// decision, resource provider summaries are provided with the
41/// inventory/capacity information. For example, this information is used by
42/// nova-scheduler’s FilterScheduler to make decisions about on which compute
43/// host to build a server.
44///
45/// You can also find additional case studies of the request parameters in the
46/// [Modeling with Provider Trees](https://docs.openstack.org/placement/latest/usage/provider-tree.html)
47/// document.
48///
49/// Normal Response Codes: 200
50///
51/// Error response codes: badRequest(400)
52#[derive(Args)]
53#[command(about = "List allocation candidates")]
54pub struct AllocationCandidateCommand {
55 /// Request Query parameters
56 #[command(flatten)]
57 query: QueryParameters,
58
59 /// Path parameters
60 #[command(flatten)]
61 path: PathParameters,
62}
63
64/// Query parameters
65#[derive(Args)]
66struct QueryParameters {
67 /// When more than one resourcesN query parameter is supplied, group_policy
68 /// is required to indicate how the groups should interact. With
69 /// group_policy=none, separate groupings - with or without a suffix - may
70 /// or may not be satisfied by the same provider. With
71 /// group_policy=isolate, suffixed groups are guaranteed to be satisfied by
72 /// different providers - though there may still be overlap with the
73 /// suffixless group.
74 #[arg(help_heading = "Query parameters", long)]
75 group_policy: Option<String>,
76
77 /// A string representing a resource provider uuid. When supplied, it will
78 /// filter the returned allocation candidates to only those resource
79 /// providers that are in the same tree with the given resource provider.
80 #[arg(help_heading = "Query parameters", long)]
81 in_tree: Option<String>,
82
83 /// A positive integer used to limit the maximum number of allocation
84 /// candidates returned in the response.
85 #[arg(
86 help_heading = "Query parameters",
87 long("page-size"),
88 visible_alias("limit")
89 )]
90 limit: Option<i32>,
91
92 /// A string representing an aggregate uuid; or the prefix in: followed by
93 /// a comma-separated list of strings representing aggregate uuids. The
94 /// resource providers in the allocation request in the response must
95 /// directly or via the root provider be associated with the aggregate or
96 /// aggregates identified by uuid:
97 /// `member_of=5e08ea53-c4c6-448e-9334-ac4953de3cfa`,
98 /// `member_of=in:42896e0d-205d-4fe3-bd1e-100924931787,5e08ea53-c4c6-448e-9334-ac4953de3cfa`
99 /// Starting from microversion 1.24 specifying multiple member_of query
100 /// string parameters is possible. Multiple member_of parameters will
101 /// result in filtering providers that are directly or via root provider
102 /// associated with aggregates listed in all of the member_of query string
103 /// values. For example, to get the providers that are associated with
104 /// aggregate A as well as associated with any of aggregates B or C, the
105 /// user could issue the following query:
106 /// `member_of=AGGA_UUID&member_of=in:AGGB_UUID,AGGC_UUID` Starting from
107 /// microversion 1.32 specifying forbidden aggregates is supported in the
108 /// member_of query string parameter. Forbidden aggregates are prefixed
109 /// with a !. This negative expression can also be used in multiple
110 /// member_of parameters: `member_of=AGGA_UUID&member_of=!AGGB_UUID` would
111 /// translate logically to “Candidate resource providers must be in AGGA
112 /// and not in AGGB.” We do NOT support ! on the values within in:, but we
113 /// support !in:. Both of the following two example queries return
114 /// candidate resource providers that are NOT in AGGA, AGGB, or AGGC:
115 /// `member_of=!in:AGGA_UUID,AGGB_UUID,AGGC_UUID`,
116 /// `member_of=!AGGA_UUID&member_of=!AGGB_UUID&member_of=!AGGC_UUID` We do
117 /// not check if the same aggregate uuid is in both positive and negative
118 /// expression to return 400 BadRequest. We still return 200 for such
119 /// cases. For example: `member_of=AGGA_UUID&member_of=!AGGA_UUID` would
120 /// return empty allocation_requests and provider_summaries, while:
121 /// `member_of=in:AGGA_UUID,AGGB_UUID&member_of=!AGGA_UUID` would return
122 /// resource providers that are NOT in AGGA but in AGGB.
123 #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
124 member_of: Option<Vec<String>>,
125
126 /// A comma-separated list of traits that a provider must have:
127 /// `required=HW_CPU_X86_AVX,HW_CPU_X86_SSE` Allocation requests in the
128 /// response will be for resource providers that have capacity for all
129 /// requested resources and the set of those resource providers will
130 /// collectively contain all of the required traits. These traits may be
131 /// satisfied by any provider in the same non-sharing tree or associated
132 /// via aggregate as far as that provider also contributes resource to the
133 /// request. Starting from microversion 1.22 traits which are forbidden
134 /// from any resource provider contributing resources to the request may be
135 /// expressed by prefixing a trait with a `!`. Starting from microversion
136 /// 1.39 the required query parameter can be repeated. The trait lists from
137 /// the repeated parameters are AND-ed together. So:
138 /// `required=T1,!T2&required=T3` means T1 and not T2 and T3. Also starting
139 /// from microversion 1.39 the required parameter supports the syntax:
140 /// `required=in:T1,T2,T3` which means T1 or T2 or T3. Mixing forbidden
141 /// traits into an in: prefixed value is not supported and rejected. But
142 /// mixing a normal trait list and an in: prefixed trait list in two query
143 /// params within the same request is supported. So:
144 /// `required=in:T3,T4&required=T1,!T2` is supported and it means T1 and
145 /// not T2 and (T3 or T4).
146 #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
147 required: Option<Vec<String>>,
148
149 /// A comma-separated list of strings indicating an amount of resource of a
150 /// specified class that providers in each allocation request must
151 /// collectively have the capacity and availability to serve:
152 /// `resources=VCPU:4,DISK_GB:64,MEMORY_MB:2048` These resources may be
153 /// satisfied by any provider in the same non-sharing tree or associated
154 /// via aggregate.
155 #[arg(help_heading = "Query parameters", long)]
156 resources: Option<String>,
157
158 /// A comma-separated list of trait requirements that the root provider of
159 /// the (non-sharing) tree must satisfy:
160 /// `root_required=COMPUTE_SUPPORTS_MULTI_ATTACH,!CUSTOM_WINDOWS_LICENSED`
161 /// Allocation requests in the response will be limited to those whose
162 /// (non-sharing) tree’s root provider satisfies the specified trait
163 /// requirements. Traits which are forbidden (must not be present on the
164 /// root provider) are expressed by prefixing the trait with a !.
165 #[arg(help_heading = "Query parameters", long)]
166 root_required: Option<String>,
167
168 /// A comma-separated list of request group suffix strings ($S). Each must
169 /// exactly match a suffix on a granular group somewhere else in the
170 /// request. Importantly, the identified request groups need not have a
171 /// resources[$S]. If this is provided, at least one of the resource
172 /// providers satisfying a specified request group must be an ancestor of
173 /// the rest. The same_subtree query parameter can be repeated and each
174 /// repeat group is treated independently.
175 #[arg(help_heading = "Query parameters", long)]
176 same_subtree: Option<String>,
177}
178
179/// Path parameters
180#[derive(Args)]
181struct PathParameters {}
182
183impl AllocationCandidateCommand {
184 /// Perform command action
185 pub async fn take_action<C: CliArgs>(
186 &self,
187 parsed_args: &C,
188 client: &mut AsyncOpenStack,
189 ) -> Result<(), OpenStackCliError> {
190 info!("Show AllocationCandidate");
191
192 let op = OutputProcessor::from_args(
193 parsed_args,
194 Some("placement.allocation_candidate"),
195 Some("list"),
196 );
197 op.validate_args(parsed_args)?;
198
199 let mut ep_builder = list::Request::builder();
200
201 // Set query parameters
202 if let Some(val) = &self.query.group_policy {
203 ep_builder.group_policy(val);
204 }
205 if let Some(val) = &self.query.in_tree {
206 ep_builder.in_tree(val);
207 }
208 if let Some(val) = &self.query.limit {
209 ep_builder.limit(*val);
210 }
211 if let Some(val) = &self.query.member_of {
212 ep_builder.member_of(val.iter());
213 }
214 if let Some(val) = &self.query.required {
215 ep_builder.required(val.iter());
216 }
217 if let Some(val) = &self.query.resources {
218 ep_builder.resources(val);
219 }
220 if let Some(val) = &self.query.root_required {
221 ep_builder.root_required(val);
222 }
223 if let Some(val) = &self.query.same_subtree {
224 ep_builder.same_subtree(val);
225 }
226
227 let ep = ep_builder
228 .build()
229 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
230
231 let data: serde_json::Value = ep.query_async(client).await?;
232
233 op.output_single::<response::list::AllocationCandidateResponse>(data.clone())?;
234 // Show command specific hints
235 op.show_command_hint()?;
236 Ok(())
237 }
238}