Skip to main content

openstack_cli_network/v2/quota/
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 Quota command
19//!
20//! Wraps invoking of the `v2.0/quotas/{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::network::v2::quota::set;
33use openstack_types::network::v2::quota::response;
34
35/// Updates quotas for a project. Use when non-default quotas are desired.
36///
37/// Normal response codes: 200
38///
39/// Error response codes: 401, 403
40#[derive(Args)]
41#[command(about = "Update quota for a project")]
42pub struct QuotaCommand {
43    /// Request Query parameters
44    #[command(flatten)]
45    query: QueryParameters,
46
47    /// Path parameters
48    #[command(flatten)]
49    path: PathParameters,
50
51    /// A `quota` object.
52    #[command(flatten)]
53    quota: Quota,
54}
55
56/// Query parameters
57#[derive(Args)]
58struct QueryParameters {}
59
60/// Path parameters
61#[derive(Args)]
62struct PathParameters {
63    /// id parameter for /v2.0/quotas/{id} API
64    #[arg(
65        help_heading = "Path parameters",
66        id = "path_param_id",
67        value_name = "ID"
68    )]
69    id: String,
70}
71/// Quota Body data
72#[derive(Args, Clone)]
73struct Quota {
74    /// The number of floating IP addresses allowed for each project. A value
75    /// of `-1` means no limit.
76    #[arg(help_heading = "Body parameters", long)]
77    floatingip: Option<i32>,
78
79    /// The number of networks allowed for each project. A value of `-1` means
80    /// no limit.
81    #[arg(help_heading = "Body parameters", long)]
82    network: Option<i32>,
83
84    /// The number of ports allowed for each project. A value of `-1` means no
85    /// limit.
86    #[arg(help_heading = "Body parameters", long)]
87    port: Option<i32>,
88
89    /// The ID of the project.
90    #[arg(help_heading = "Body parameters", long)]
91    project_id: Option<String>,
92
93    /// The number of role-based access control (RBAC) policies for each
94    /// project. A value of `-1` means no limit.
95    #[arg(help_heading = "Body parameters", long)]
96    rbac_policy: Option<i32>,
97
98    /// The number of routers allowed for each project. A value of `-1` means
99    /// no limit.
100    #[arg(help_heading = "Body parameters", long)]
101    router: Option<i32>,
102
103    /// The number of security groups allowed for each project. A value of `-1`
104    /// means no limit.
105    #[arg(help_heading = "Body parameters", long)]
106    security_group: Option<i32>,
107
108    /// The number of security group rules allowed for each project. A value of
109    /// `-1` means no limit.
110    #[arg(help_heading = "Body parameters", long)]
111    security_group_rule: Option<i32>,
112
113    /// The number of subnets allowed for each project. A value of `-1` means
114    /// no limit.
115    #[arg(help_heading = "Body parameters", long)]
116    subnet: Option<i32>,
117
118    /// The number of subnet pools allowed for each project. A value of `-1`
119    /// means no limit.
120    #[arg(help_heading = "Body parameters", long)]
121    subnetpool: Option<i32>,
122}
123
124impl QuotaCommand {
125    /// Perform command action
126    pub async fn take_action<C: CliArgs>(
127        &self,
128        parsed_args: &C,
129        client: &mut AsyncOpenStack,
130    ) -> Result<(), OpenStackCliError> {
131        info!("Set Quota");
132
133        let op = OutputProcessor::from_args(parsed_args, Some("network.quota"), Some("set"));
134        op.validate_args(parsed_args)?;
135
136        let mut ep_builder = set::Request::builder();
137
138        ep_builder.id(&self.path.id);
139
140        // Set body parameters
141        // Set Request.quota data
142        let args = &self.quota;
143        let mut quota_builder = set::QuotaBuilder::default();
144        if let Some(val) = &args.floatingip {
145            quota_builder.floatingip(*val);
146        }
147
148        if let Some(val) = &args.network {
149            quota_builder.network(*val);
150        }
151
152        if let Some(val) = &args.port {
153            quota_builder.port(*val);
154        }
155
156        if let Some(val) = &args.project_id {
157            quota_builder.project_id(val);
158        }
159
160        if let Some(val) = &args.rbac_policy {
161            quota_builder.rbac_policy(*val);
162        }
163
164        if let Some(val) = &args.router {
165            quota_builder.router(*val);
166        }
167
168        if let Some(val) = &args.security_group {
169            quota_builder.security_group(*val);
170        }
171
172        if let Some(val) = &args.security_group_rule {
173            quota_builder.security_group_rule(*val);
174        }
175
176        if let Some(val) = &args.subnet {
177            quota_builder.subnet(*val);
178        }
179
180        if let Some(val) = &args.subnetpool {
181            quota_builder.subnetpool(*val);
182        }
183
184        ep_builder.quota(
185            quota_builder
186                .build()
187                .wrap_err("error preparing the request data")?,
188        );
189
190        let ep = ep_builder
191            .build()
192            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
193
194        let data: serde_json::Value = ep.query_async(client).await?;
195
196        op.output_single::<response::set::QuotaResponse>(data.clone())?;
197        // Show command specific hints
198        op.show_command_hint()?;
199        Ok(())
200    }
201}