Skip to main content

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