openstack_cli_placement/v1/resource_provider/inventory/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 Inventory command
19//!
20//! Wraps invoking of the `resource_providers/{uuid}/inventories/{resource_class}` 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_provider::inventory::set;
32use openstack_types::placement::v1::resource_provider::inventory::response;
33
34/// Replace the inventory record of the {resource_class} for the resource
35/// provider identified by {uuid}.
36///
37/// Normal Response Codes: 200
38///
39/// Error response codes: badRequest(400), itemNotFound(404), conflict(409)
40#[derive(Args)]
41#[command(about = "Update resource provider inventory")]
42pub struct InventoryCommand {
43 /// Request Query parameters
44 #[command(flatten)]
45 query: QueryParameters,
46
47 /// Path parameters
48 #[command(flatten)]
49 path: PathParameters,
50
51 /// It is used in determining whether consumption of the resource of the
52 /// provider can exceed physical constraints.
53 ///
54 /// For example, for a vCPU resource with:
55 ///
56 /// ```text
57 /// allocation_ratio = 16.0
58 /// total = 8
59 /// ```
60 ///
61 /// Overall capacity is equal to 128 vCPUs.
62 #[arg(help_heading = "Body parameters", long)]
63 allocation_ratio: Option<f32>,
64
65 /// A maximum amount any single allocation against an inventory can have.
66 #[arg(help_heading = "Body parameters", long)]
67 max_unit: Option<i32>,
68
69 /// A minimum amount any single allocation against an inventory can have.
70 #[arg(help_heading = "Body parameters", long)]
71 min_unit: Option<i32>,
72
73 /// The amount of the resource a provider has reserved for its own use.
74 #[arg(help_heading = "Body parameters", long)]
75 reserved: Option<u32>,
76
77 /// A consistent view marker that assists with the management of concurrent
78 /// resource provider updates.
79 #[arg(help_heading = "Body parameters", long)]
80 resource_provider_generation: i32,
81
82 /// A representation of the divisible amount of the resource that may be
83 /// requested. For example, step_size = 5 means that only values divisible
84 /// by 5 (5, 10, 15, etc.) can be requested.
85 #[arg(help_heading = "Body parameters", long)]
86 step_size: Option<i32>,
87
88 /// The actual amount of the resource that the provider can accommodate.
89 #[arg(help_heading = "Body parameters", long)]
90 total: i32,
91}
92
93/// Query parameters
94#[derive(Args)]
95struct QueryParameters {}
96
97/// Path parameters
98#[derive(Args)]
99struct PathParameters {
100 /// resource_class parameter for
101 /// /resource_providers/{uuid}/inventories/{resource_class} API
102 #[arg(
103 help_heading = "Path parameters",
104 id = "path_param_resource_class",
105 value_name = "RESOURCE_CLASS"
106 )]
107 resource_class: String,
108
109 /// uuid parameter for
110 /// /resource_providers/{uuid}/inventories/{resource_class} API
111 #[arg(
112 help_heading = "Path parameters",
113 id = "path_param_uuid",
114 value_name = "UUID"
115 )]
116 uuid: String,
117}
118
119impl InventoryCommand {
120 /// Perform command action
121 pub async fn take_action<C: CliArgs>(
122 &self,
123 parsed_args: &C,
124 client: &mut AsyncOpenStack,
125 ) -> Result<(), OpenStackCliError> {
126 info!("Set Inventory");
127
128 let op = OutputProcessor::from_args(
129 parsed_args,
130 Some("placement.resource_provider/inventory"),
131 Some("set"),
132 );
133 op.validate_args(parsed_args)?;
134
135 let mut ep_builder = set::Request::builder();
136
137 ep_builder.resource_class(&self.path.resource_class);
138 ep_builder.uuid(&self.path.uuid);
139
140 // Set body parameters
141 // Set Request.allocation_ratio data
142 if let Some(arg) = &self.allocation_ratio {
143 ep_builder.allocation_ratio(*arg);
144 }
145
146 // Set Request.max_unit data
147 if let Some(arg) = &self.max_unit {
148 ep_builder.max_unit(*arg);
149 }
150
151 // Set Request.min_unit data
152 if let Some(arg) = &self.min_unit {
153 ep_builder.min_unit(*arg);
154 }
155
156 // Set Request.reserved data
157 if let Some(arg) = &self.reserved {
158 ep_builder.reserved(*arg);
159 }
160
161 // Set Request.resource_provider_generation data
162 ep_builder.resource_provider_generation(self.resource_provider_generation);
163
164 // Set Request.step_size data
165 if let Some(arg) = &self.step_size {
166 ep_builder.step_size(*arg);
167 }
168
169 // Set Request.total data
170 ep_builder.total(self.total);
171
172 let ep = ep_builder
173 .build()
174 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
175
176 let data: serde_json::Value = ep.query_async(client).await?;
177
178 op.output_single::<response::set::InventoryResponse>(data.clone())?;
179 // Show command specific hints
180 op.show_command_hint()?;
181 Ok(())
182 }
183}