Skip to main content

openstack_cli_compute/v2/quota_class_set/
set_21.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 QuotaClassSet command [microversion = 2.1]
19//!
20//! Wraps invoking of the `v2.1/os-quota-class-sets/{id}` with `PUT` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::quota_class_set::set_21;
33use openstack_types::compute::v2::quota_class_set::response;
34
35/// Update the quotas for the Quota Class.
36///
37/// If the requested Quota Class is not found in the DB, then the API will
38/// create the one. Only ‘default’ quota class is valid and used to set the
39/// default quotas, all other quota class would not be used anywhere.
40///
41/// Normal response codes: 200
42///
43/// Error response codes: badRequest(400), unauthorized(401), forbidden(403)
44#[derive(Args)]
45#[command(about = "Create or Update Quotas for Quota Class (microversion = 2.1)")]
46pub struct QuotaClassSetCommand {
47    /// Request Query parameters
48    #[command(flatten)]
49    query: QueryParameters,
50
51    /// Path parameters
52    #[command(flatten)]
53    path: PathParameters,
54
55    /// A `quota_class_set` object.
56    #[command(flatten)]
57    quota_class_set: QuotaClassSet,
58}
59
60/// Query parameters
61#[derive(Args)]
62struct QueryParameters {}
63
64/// Path parameters
65#[derive(Args)]
66struct PathParameters {
67    /// id parameter for /v2.1/os-quota-class-sets/{id} API
68    #[arg(
69        help_heading = "Path parameters",
70        id = "path_param_id",
71        value_name = "ID"
72    )]
73    id: String,
74}
75/// QuotaClassSet Body data
76#[derive(Args, Clone)]
77struct QuotaClassSet {
78    /// The number of allowed injected files for the quota class.
79    ///
80    /// **Available until version 2.56**
81    #[arg(help_heading = "Body parameters", long)]
82    cores: Option<i32>,
83
84    /// The number of allowed injected files for the quota class.
85    ///
86    /// **Available until version 2.56**
87    #[arg(help_heading = "Body parameters", long)]
88    fixed_ips: Option<i32>,
89
90    /// The number of allowed injected files for the quota class.
91    ///
92    /// **Available until version 2.56**
93    #[arg(help_heading = "Body parameters", long)]
94    floating_ips: Option<i32>,
95
96    /// The number of allowed injected files for the quota class.
97    ///
98    /// **Available until version 2.56**
99    #[arg(help_heading = "Body parameters", long)]
100    injected_file_content_bytes: Option<i32>,
101
102    /// The number of allowed injected files for the quota class.
103    ///
104    /// **Available until version 2.56**
105    #[arg(help_heading = "Body parameters", long)]
106    injected_file_path_bytes: Option<i32>,
107
108    /// The number of allowed injected files for the quota class.
109    ///
110    /// **Available until version 2.56**
111    #[arg(help_heading = "Body parameters", long)]
112    injected_files: Option<i32>,
113
114    /// The number of allowed injected files for the quota class.
115    ///
116    /// **Available until version 2.56**
117    #[arg(help_heading = "Body parameters", long)]
118    instances: Option<i32>,
119
120    /// The number of allowed injected files for the quota class.
121    ///
122    /// **Available until version 2.56**
123    #[arg(help_heading = "Body parameters", long)]
124    key_pairs: Option<i32>,
125
126    /// The number of allowed injected files for the quota class.
127    ///
128    /// **Available until version 2.56**
129    #[arg(help_heading = "Body parameters", long)]
130    metadata_items: Option<i32>,
131
132    /// The number of allowed injected files for the quota class.
133    ///
134    /// **Available until version 2.56**
135    #[arg(help_heading = "Body parameters", long)]
136    ram: Option<i32>,
137
138    /// The number of allowed injected files for the quota class.
139    ///
140    /// **Available until version 2.56**
141    #[arg(help_heading = "Body parameters", long)]
142    security_group_rules: Option<i32>,
143
144    /// The number of allowed injected files for the quota class.
145    ///
146    /// **Available until version 2.56**
147    #[arg(help_heading = "Body parameters", long)]
148    security_groups: Option<i32>,
149
150    /// The number of allowed injected files for the quota class.
151    ///
152    /// **Available until version 2.56**
153    #[arg(help_heading = "Body parameters", long)]
154    server_group_members: Option<i32>,
155
156    /// The number of allowed injected files for the quota class.
157    ///
158    /// **Available until version 2.56**
159    #[arg(help_heading = "Body parameters", long)]
160    server_groups: Option<i32>,
161}
162
163impl QuotaClassSetCommand {
164    /// Perform command action
165    pub async fn take_action<C: CliArgs>(
166        &self,
167        parsed_args: &C,
168        client: &mut AsyncOpenStack,
169    ) -> Result<(), OpenStackCliError> {
170        info!("Set QuotaClassSet");
171
172        let op =
173            OutputProcessor::from_args(parsed_args, Some("compute.quota_class_set"), Some("set"));
174        op.validate_args(parsed_args)?;
175
176        let mut ep_builder = set_21::Request::builder();
177        ep_builder.header(
178            http::header::HeaderName::from_static("openstack-api-version"),
179            http::header::HeaderValue::from_static("compute 2.1"),
180        );
181
182        ep_builder.id(&self.path.id);
183
184        // Set body parameters
185        // Set Request.quota_class_set data
186        let args = &self.quota_class_set;
187        let mut quota_class_set_builder = set_21::QuotaClassSetBuilder::default();
188        if let Some(val) = &args.cores {
189            quota_class_set_builder.cores(*val);
190        }
191
192        if let Some(val) = &args.fixed_ips {
193            quota_class_set_builder.fixed_ips(*val);
194        }
195
196        if let Some(val) = &args.floating_ips {
197            quota_class_set_builder.floating_ips(*val);
198        }
199
200        if let Some(val) = &args.injected_file_content_bytes {
201            quota_class_set_builder.injected_file_content_bytes(*val);
202        }
203
204        if let Some(val) = &args.injected_file_path_bytes {
205            quota_class_set_builder.injected_file_path_bytes(*val);
206        }
207
208        if let Some(val) = &args.injected_files {
209            quota_class_set_builder.injected_files(*val);
210        }
211
212        if let Some(val) = &args.instances {
213            quota_class_set_builder.instances(*val);
214        }
215
216        if let Some(val) = &args.key_pairs {
217            quota_class_set_builder.key_pairs(*val);
218        }
219
220        if let Some(val) = &args.metadata_items {
221            quota_class_set_builder.metadata_items(*val);
222        }
223
224        if let Some(val) = &args.ram {
225            quota_class_set_builder.ram(*val);
226        }
227
228        if let Some(val) = &args.security_group_rules {
229            quota_class_set_builder.security_group_rules(*val);
230        }
231
232        if let Some(val) = &args.security_groups {
233            quota_class_set_builder.security_groups(*val);
234        }
235
236        if let Some(val) = &args.server_group_members {
237            quota_class_set_builder.server_group_members(*val);
238        }
239
240        if let Some(val) = &args.server_groups {
241            quota_class_set_builder.server_groups(*val);
242        }
243
244        ep_builder.quota_class_set(
245            quota_class_set_builder
246                .build()
247                .wrap_err("error preparing the request data")?,
248        );
249
250        let ep = ep_builder
251            .build()
252            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
253
254        let data: serde_json::Value = ep.query_async(client).await?;
255
256        op.output_single::<response::set_21::QuotaClassSetResponse>(data.clone())?;
257        // Show command specific hints
258        op.show_command_hint()?;
259        Ok(())
260    }
261}