Skip to main content

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