Skip to main content

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