openstack_cli_compute/v2/quota_class_set/
set_21.rs1use 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#[derive(Args)]
45#[command(about = "Create or Update Quotas for Quota Class (microversion = 2.1)")]
46pub struct QuotaClassSetCommand {
47 #[command(flatten)]
49 query: QueryParameters,
50
51 #[command(flatten)]
53 path: PathParameters,
54
55 #[command(flatten)]
57 quota_class_set: QuotaClassSet,
58}
59
60#[derive(Args)]
62struct QueryParameters {}
63
64#[derive(Args)]
66struct PathParameters {
67 #[arg(
69 help_heading = "Path parameters",
70 id = "path_param_id",
71 value_name = "ID"
72 )]
73 id: String,
74}
75#[derive(Args, Clone)]
77struct QuotaClassSet {
78 #[arg(help_heading = "Body parameters", long)]
82 cores: Option<i32>,
83
84 #[arg(help_heading = "Body parameters", long)]
88 fixed_ips: Option<i32>,
89
90 #[arg(help_heading = "Body parameters", long)]
94 floating_ips: Option<i32>,
95
96 #[arg(help_heading = "Body parameters", long)]
100 injected_file_content_bytes: Option<i32>,
101
102 #[arg(help_heading = "Body parameters", long)]
106 injected_file_path_bytes: Option<i32>,
107
108 #[arg(help_heading = "Body parameters", long)]
112 injected_files: Option<i32>,
113
114 #[arg(help_heading = "Body parameters", long)]
118 instances: Option<i32>,
119
120 #[arg(help_heading = "Body parameters", long)]
124 key_pairs: Option<i32>,
125
126 #[arg(help_heading = "Body parameters", long)]
130 metadata_items: Option<i32>,
131
132 #[arg(help_heading = "Body parameters", long)]
136 ram: Option<i32>,
137
138 #[arg(help_heading = "Body parameters", long)]
142 security_group_rules: Option<i32>,
143
144 #[arg(help_heading = "Body parameters", long)]
148 security_groups: Option<i32>,
149
150 #[arg(help_heading = "Body parameters", long)]
154 server_group_members: Option<i32>,
155
156 #[arg(help_heading = "Body parameters", long)]
160 server_groups: Option<i32>,
161}
162
163impl QuotaClassSetCommand {
164 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 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 op.show_command_hint()?;
259 Ok(())
260 }
261}