Skip to main content

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