Skip to main content

openstack_cli_network/v2/router/
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 Routers command
19//!
20//! Wraps invoking of the `v2.0/routers` 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::router::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::network::v2::router::response;
34
35/// Lists logical routers that the project who submits the request can access.
36///
37/// Default policy settings return only those routers that the project who
38/// submits the request owns, unless an administrative user submits the
39/// request.
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 routers")]
59pub struct RoutersCommand {
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    /// admin_state_up query parameter for /v2.0/routers API
77    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
78    admin_state_up: Option<bool>,
79
80    /// description query parameter for /v2.0/routers API
81    #[arg(help_heading = "Query parameters", long)]
82    description: Option<String>,
83
84    /// enable_ndp_proxy query parameter for /v2.0/routers API
85    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
86    enable_ndp_proxy: Option<bool>,
87
88    /// id query parameter for /v2.0/routers API
89    #[arg(help_heading = "Query parameters", long)]
90    id: Option<String>,
91
92    /// Requests a page size of items. Returns a number of items up to a limit
93    /// value. Use the limit parameter to make an initial limited request and
94    /// use the ID of the last-seen item from the response as the marker
95    /// parameter value in a subsequent limited request.
96    #[arg(
97        help_heading = "Query parameters",
98        long("page-size"),
99        visible_alias("limit")
100    )]
101    limit: Option<u32>,
102
103    /// The ID of the last-seen item. Use the limit parameter to make an
104    /// initial limited request and use the ID of the last-seen item from the
105    /// response as the marker parameter value in a subsequent limited request.
106    #[arg(help_heading = "Query parameters", long)]
107    marker: Option<String>,
108
109    /// name query parameter for /v2.0/routers API
110    #[arg(help_heading = "Query parameters", long)]
111    name: Option<String>,
112
113    /// not-tags query parameter for /v2.0/routers API
114    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
115    not_tags: Option<Vec<String>>,
116
117    /// not-tags-any query parameter for /v2.0/routers API
118    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
119    not_tags_any: Option<Vec<String>>,
120
121    /// Reverse the page direction
122    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
123    page_reverse: Option<bool>,
124
125    /// revision_number query parameter for /v2.0/routers API
126    #[arg(help_heading = "Query parameters", long)]
127    revision_number: Option<String>,
128
129    /// Sort direction. This is an optional feature and may be silently ignored
130    /// by the server.
131    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
132    sort_dir: Option<Vec<String>>,
133
134    /// Sort results by the attribute. This is an optional feature and may be
135    /// silently ignored by the server.
136    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
137    sort_key: Option<Vec<String>>,
138
139    /// tags query parameter for /v2.0/routers API
140    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
141    tags: Option<Vec<String>>,
142
143    /// tags-any query parameter for /v2.0/routers API
144    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
145    tags_any: Option<Vec<String>>,
146
147    /// tenant_id query parameter for /v2.0/routers API
148    #[arg(help_heading = "Query parameters", long)]
149    tenant_id: Option<String>,
150}
151
152/// Path parameters
153#[derive(Args)]
154struct PathParameters {}
155
156impl RoutersCommand {
157    /// Perform command action
158    pub async fn take_action<C: CliArgs>(
159        &self,
160        parsed_args: &C,
161        client: &mut AsyncOpenStack,
162    ) -> Result<(), OpenStackCliError> {
163        info!("List Routers");
164
165        let op = OutputProcessor::from_args(parsed_args, Some("network.router"), Some("list"));
166        op.validate_args(parsed_args)?;
167
168        let mut ep_builder = list::Request::builder();
169
170        // Set query parameters
171        if let Some(val) = &self.query.limit {
172            ep_builder.limit(*val);
173        }
174        if let Some(val) = &self.query.marker {
175            ep_builder.marker(val);
176        }
177        if let Some(val) = &self.query.page_reverse {
178            ep_builder.page_reverse(*val);
179        }
180        if let Some(val) = &self.query.admin_state_up {
181            ep_builder.admin_state_up(*val);
182        }
183        if let Some(val) = &self.query.description {
184            ep_builder.description(val);
185        }
186        if let Some(val) = &self.query.enable_ndp_proxy {
187            ep_builder.enable_ndp_proxy(*val);
188        }
189        if let Some(val) = &self.query.id {
190            ep_builder.id(val);
191        }
192        if let Some(val) = &self.query.name {
193            ep_builder.name(val);
194        }
195        if let Some(val) = &self.query.not_tags {
196            ep_builder.not_tags(val.iter());
197        }
198        if let Some(val) = &self.query.not_tags_any {
199            ep_builder.not_tags_any(val.iter());
200        }
201        if let Some(val) = &self.query.revision_number {
202            ep_builder.revision_number(val);
203        }
204        if let Some(val) = &self.query.tags {
205            ep_builder.tags(val.iter());
206        }
207        if let Some(val) = &self.query.tags_any {
208            ep_builder.tags_any(val.iter());
209        }
210        if let Some(val) = &self.query.tenant_id {
211            ep_builder.tenant_id(val);
212        }
213        if let Some(val) = &self.query.sort_dir {
214            ep_builder.sort_dir(val.iter());
215        }
216        if let Some(val) = &self.query.sort_key {
217            ep_builder.sort_key(val.iter());
218        }
219
220        let ep = ep_builder
221            .build()
222            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
223
224        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
225            .query_async(client)
226            .await?;
227
228        op.output_list::<response::list::RouterResponse>(data.clone())?;
229        // Show command specific hints
230        op.show_command_hint()?;
231        Ok(())
232    }
233}