Skip to main content

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