Skip to main content

openstack_cli_network/v2/subnetpool/
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//! List Subnetpools command
19//!
20//! Wraps invoking of the `v2.0/subnetpools` 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::network::v2::subnetpool::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::network::v2::subnetpool::response;
34
35/// Lists subnet pools that the project has access to.
36///
37/// Default policy settings return only the subnet pools owned by the project
38/// of the user submitting the request, unless the user has administrative
39/// role.
40///
41/// Standard query parameters are supported on the URI. For more information,
42/// see [Filtering and Column Selection](#filtering).
43///
44/// Use the `fields` query parameter to control which fields are returned in
45/// the response body. For more information, see [Fields](#fields).
46///
47/// Pagination query parameters are supported if Neutron configuration supports
48/// it by overriding `allow_pagination=false`. For more information, see
49/// [Pagination](#pagination).
50///
51/// Sorting query parameters are supported if Neutron configuration supports it
52/// with `allow_sorting=true`. For more information, see [Sorting](#sorting).
53///
54/// Normal response codes: 200
55///
56/// Error response codes: 401
57#[derive(Args)]
58#[command(about = "List subnet pools")]
59pub struct SubnetpoolsCommand {
60    /// Request Query parameters
61    #[command(flatten)]
62    query: QueryParameters,
63
64    /// Path parameters
65    #[command(flatten)]
66    path: PathParameters,
67
68    /// Total limit of entities count to return. Use this when there are too many entries.
69    #[arg(long, default_value_t = 10000)]
70    max_items: usize,
71}
72
73/// Query parameters
74#[derive(Args)]
75struct QueryParameters {
76    /// address_scope_id query parameter for /v2.0/subnetpools API
77    #[arg(help_heading = "Query parameters", long)]
78    address_scope_id: Option<String>,
79
80    /// default_prefixlen query parameter for /v2.0/subnetpools API
81    #[arg(help_heading = "Query parameters", long)]
82    default_prefixlen: Option<u32>,
83
84    /// default_quota query parameter for /v2.0/subnetpools API
85    #[arg(help_heading = "Query parameters", long)]
86    default_quota: Option<u32>,
87
88    /// description query parameter for /v2.0/subnetpools API
89    #[arg(help_heading = "Query parameters", long)]
90    description: Option<String>,
91
92    /// id query parameter for /v2.0/subnetpools API
93    #[arg(help_heading = "Query parameters", long)]
94    id: Option<String>,
95
96    /// ip_version query parameter for /v2.0/subnetpools API
97    #[arg(help_heading = "Query parameters", long)]
98    ip_version: Option<String>,
99
100    /// is_default query parameter for /v2.0/subnetpools API
101    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
102    is_default: Option<bool>,
103
104    /// Requests a page size of items. Returns a number of items up to a limit
105    /// value. Use the limit parameter to make an initial limited request and
106    /// use the ID of the last-seen item from the response as the marker
107    /// parameter value in a subsequent limited request.
108    #[arg(
109        help_heading = "Query parameters",
110        long("page-size"),
111        visible_alias("limit")
112    )]
113    limit: Option<u32>,
114
115    /// The ID of the last-seen item. Use the limit parameter to make an
116    /// initial limited request and use the ID of the last-seen item from the
117    /// response as the marker parameter value in a subsequent limited request.
118    #[arg(help_heading = "Query parameters", long)]
119    marker: Option<String>,
120
121    /// max_prefixlen query parameter for /v2.0/subnetpools API
122    #[arg(help_heading = "Query parameters", long)]
123    max_prefixlen: Option<u32>,
124
125    /// min_prefixlen query parameter for /v2.0/subnetpools API
126    #[arg(help_heading = "Query parameters", long)]
127    min_prefixlen: Option<u32>,
128
129    /// name query parameter for /v2.0/subnetpools API
130    #[arg(help_heading = "Query parameters", long)]
131    name: Option<String>,
132
133    /// not-tags query parameter for /v2.0/subnetpools API
134    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
135    not_tags: Option<Vec<String>>,
136
137    /// not-tags-any query parameter for /v2.0/subnetpools API
138    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
139    not_tags_any: Option<Vec<String>>,
140
141    /// Reverse the page direction
142    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
143    page_reverse: Option<bool>,
144
145    /// revision_number query parameter for /v2.0/subnetpools API
146    #[arg(help_heading = "Query parameters", long)]
147    revision_number: Option<String>,
148
149    /// shared query parameter for /v2.0/subnetpools API
150    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
151    shared: Option<bool>,
152
153    /// Sort direction. This is an optional feature and may be silently ignored
154    /// by the server.
155    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
156    sort_dir: Option<Vec<String>>,
157
158    /// Sort results by the attribute. This is an optional feature and may be
159    /// silently ignored by the server.
160    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
161    sort_key: Option<Vec<String>>,
162
163    /// tags query parameter for /v2.0/subnetpools API
164    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
165    tags: Option<Vec<String>>,
166
167    /// tags-any query parameter for /v2.0/subnetpools API
168    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
169    tags_any: Option<Vec<String>>,
170
171    /// tenant_id query parameter for /v2.0/subnetpools API
172    #[arg(help_heading = "Query parameters", long)]
173    tenant_id: Option<String>,
174}
175
176/// Path parameters
177#[derive(Args)]
178struct PathParameters {}
179
180impl SubnetpoolsCommand {
181    /// Perform command action
182    pub async fn take_action<C: CliArgs>(
183        &self,
184        parsed_args: &C,
185        client: &mut AsyncOpenStack,
186    ) -> Result<(), OpenStackCliError> {
187        info!("List Subnetpools");
188
189        let op = OutputProcessor::from_args(parsed_args, Some("network.subnetpool"), Some("list"));
190        op.validate_args(parsed_args)?;
191
192        let mut ep_builder = list::Request::builder();
193
194        // Set query parameters
195        if let Some(val) = &self.query.limit {
196            ep_builder.limit(*val);
197        }
198        if let Some(val) = &self.query.marker {
199            ep_builder.marker(val);
200        }
201        if let Some(val) = &self.query.page_reverse {
202            ep_builder.page_reverse(*val);
203        }
204        if let Some(val) = &self.query.sort_dir {
205            ep_builder.sort_dir(val.iter());
206        }
207        if let Some(val) = &self.query.sort_key {
208            ep_builder.sort_key(val.iter());
209        }
210        if let Some(val) = &self.query.address_scope_id {
211            ep_builder.address_scope_id(val);
212        }
213        if let Some(val) = &self.query.default_prefixlen {
214            ep_builder.default_prefixlen(*val);
215        }
216        if let Some(val) = &self.query.default_quota {
217            ep_builder.default_quota(*val);
218        }
219        if let Some(val) = &self.query.description {
220            ep_builder.description(val);
221        }
222        if let Some(val) = &self.query.id {
223            ep_builder.id(val);
224        }
225        if let Some(val) = &self.query.ip_version {
226            ep_builder.ip_version(val);
227        }
228        if let Some(val) = &self.query.is_default {
229            ep_builder.is_default(*val);
230        }
231        if let Some(val) = &self.query.max_prefixlen {
232            ep_builder.max_prefixlen(*val);
233        }
234        if let Some(val) = &self.query.min_prefixlen {
235            ep_builder.min_prefixlen(*val);
236        }
237        if let Some(val) = &self.query.name {
238            ep_builder.name(val);
239        }
240        if let Some(val) = &self.query.not_tags {
241            ep_builder.not_tags(val.iter());
242        }
243        if let Some(val) = &self.query.not_tags_any {
244            ep_builder.not_tags_any(val.iter());
245        }
246        if let Some(val) = &self.query.revision_number {
247            ep_builder.revision_number(val);
248        }
249        if let Some(val) = &self.query.shared {
250            ep_builder.shared(*val);
251        }
252        if let Some(val) = &self.query.tags {
253            ep_builder.tags(val.iter());
254        }
255        if let Some(val) = &self.query.tags_any {
256            ep_builder.tags_any(val.iter());
257        }
258        if let Some(val) = &self.query.tenant_id {
259            ep_builder.tenant_id(val);
260        }
261
262        let ep = ep_builder
263            .build()
264            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
265
266        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
267            .query_async(client)
268            .await?;
269
270        op.output_list::<response::list::SubnetpoolResponse>(data.clone())?;
271        // Show command specific hints
272        op.show_command_hint()?;
273        Ok(())
274    }
275}