Skip to main content

openstack_cli_network/v2/floatingip_pool/
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 FloatingipPools command
19//!
20//! Wraps invoking of the `v2.0/floatingip-pools` 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_pool::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::network::v2::floatingip_pool::response;
34
35/// Command without description in OpenAPI
36#[derive(Args)]
37pub struct FloatingipPoolsCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// Total limit of entities count to return. Use this when there are too many entries.
47    #[arg(long, default_value_t = 10000)]
48    max_items: usize,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {
54    /// Requests a page size of items. Returns a number of items up to a limit
55    /// value. Use the limit parameter to make an initial limited request and
56    /// use the ID of the last-seen item from the response as the marker
57    /// parameter value in a subsequent limited request.
58    #[arg(
59        help_heading = "Query parameters",
60        long("page-size"),
61        visible_alias("limit")
62    )]
63    limit: Option<u32>,
64
65    /// The ID of the last-seen item. Use the limit parameter to make an
66    /// initial limited request and use the ID of the last-seen item from the
67    /// response as the marker parameter value in a subsequent limited request.
68    #[arg(help_heading = "Query parameters", long)]
69    marker: Option<String>,
70
71    /// Reverse the page direction
72    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
73    page_reverse: Option<bool>,
74
75    /// Sort direction. This is an optional feature and may be silently ignored
76    /// by the server.
77    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
78    sort_dir: Option<Vec<String>>,
79
80    /// Sort results by the attribute. This is an optional feature and may be
81    /// silently ignored by the server.
82    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
83    sort_key: Option<Vec<String>>,
84}
85
86/// Path parameters
87#[derive(Args)]
88struct PathParameters {}
89
90impl FloatingipPoolsCommand {
91    /// Perform command action
92    pub async fn take_action<C: CliArgs>(
93        &self,
94        parsed_args: &C,
95        client: &mut AsyncOpenStack,
96    ) -> Result<(), OpenStackCliError> {
97        info!("List FloatingipPools");
98
99        let op =
100            OutputProcessor::from_args(parsed_args, Some("network.floatingip_pool"), Some("list"));
101        op.validate_args(parsed_args)?;
102
103        let mut ep_builder = list::Request::builder();
104
105        // Set query parameters
106        if let Some(val) = &self.query.limit {
107            ep_builder.limit(*val);
108        }
109        if let Some(val) = &self.query.marker {
110            ep_builder.marker(val);
111        }
112        if let Some(val) = &self.query.page_reverse {
113            ep_builder.page_reverse(*val);
114        }
115        if let Some(val) = &self.query.sort_dir {
116            ep_builder.sort_dir(val.iter());
117        }
118        if let Some(val) = &self.query.sort_key {
119            ep_builder.sort_key(val.iter());
120        }
121
122        let ep = ep_builder
123            .build()
124            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
125
126        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
127            .query_async(client)
128            .await?;
129
130        op.output_list::<response::list::FloatingipPoolResponse>(data.clone())?;
131        // Show command specific hints
132        op.show_command_hint()?;
133        Ok(())
134    }
135}