Skip to main content

openstack_cli_network/v2/address_scope/
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 AddressScopes command
19//!
20//! Wraps invoking of the `v2.0/address-scopes` 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::address_scope::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::network::v2::address_scope::response;
34
35/// Lists address scopes that the project has access to.
36///
37/// Default policy settings return only the address scopes 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 address scopes")]
59pub struct AddressScopesCommand {
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    /// id query parameter for /v2.0/address-scopes API
77    #[arg(help_heading = "Query parameters", long)]
78    id: Option<String>,
79
80    /// ip_version query parameter for /v2.0/address-scopes API
81    #[arg(help_heading = "Query parameters", long)]
82    ip_version: Option<i32>,
83
84    /// Requests a page size of items. Returns a number of items up to a limit
85    /// value. Use the limit parameter to make an initial limited request and
86    /// use the ID of the last-seen item from the response as the marker
87    /// parameter value in a subsequent limited request.
88    #[arg(
89        help_heading = "Query parameters",
90        long("page-size"),
91        visible_alias("limit")
92    )]
93    limit: Option<u32>,
94
95    /// The ID of the last-seen item. Use the limit parameter to make an
96    /// initial limited request and use the ID of the last-seen item from the
97    /// response as the marker parameter value in a subsequent limited request.
98    #[arg(help_heading = "Query parameters", long)]
99    marker: Option<String>,
100
101    /// name query parameter for /v2.0/address-scopes API
102    #[arg(help_heading = "Query parameters", long)]
103    name: Option<String>,
104
105    /// Reverse the page direction
106    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
107    page_reverse: Option<bool>,
108
109    /// shared query parameter for /v2.0/address-scopes API
110    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
111    shared: Option<bool>,
112
113    /// Sort direction. This is an optional feature and may be silently ignored
114    /// by the server.
115    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
116    sort_dir: Option<Vec<String>>,
117
118    /// Sort results by the attribute. This is an optional feature and may be
119    /// silently ignored by the server.
120    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
121    sort_key: Option<Vec<String>>,
122
123    /// tenant_id query parameter for /v2.0/address-scopes API
124    #[arg(help_heading = "Query parameters", long)]
125    tenant_id: Option<String>,
126}
127
128/// Path parameters
129#[derive(Args)]
130struct PathParameters {}
131
132impl AddressScopesCommand {
133    /// Perform command action
134    pub async fn take_action<C: CliArgs>(
135        &self,
136        parsed_args: &C,
137        client: &mut AsyncOpenStack,
138    ) -> Result<(), OpenStackCliError> {
139        info!("List AddressScopes");
140
141        let op =
142            OutputProcessor::from_args(parsed_args, Some("network.address_scope"), Some("list"));
143        op.validate_args(parsed_args)?;
144
145        let mut ep_builder = list::Request::builder();
146
147        // Set query parameters
148        if let Some(val) = &self.query.id {
149            ep_builder.id(val);
150        }
151        if let Some(val) = &self.query.ip_version {
152            ep_builder.ip_version(*val);
153        }
154        if let Some(val) = &self.query.name {
155            ep_builder.name(val);
156        }
157        if let Some(val) = &self.query.shared {
158            ep_builder.shared(*val);
159        }
160        if let Some(val) = &self.query.tenant_id {
161            ep_builder.tenant_id(val);
162        }
163        if let Some(val) = &self.query.limit {
164            ep_builder.limit(*val);
165        }
166        if let Some(val) = &self.query.marker {
167            ep_builder.marker(val);
168        }
169        if let Some(val) = &self.query.page_reverse {
170            ep_builder.page_reverse(*val);
171        }
172        if let Some(val) = &self.query.sort_dir {
173            ep_builder.sort_dir(val.iter());
174        }
175        if let Some(val) = &self.query.sort_key {
176            ep_builder.sort_key(val.iter());
177        }
178
179        let ep = ep_builder
180            .build()
181            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
182
183        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
184            .query_async(client)
185            .await?;
186
187        op.output_list::<response::list::AddressScopeResponse>(data.clone())?;
188        // Show command specific hints
189        op.show_command_hint()?;
190        Ok(())
191    }
192}