Skip to main content

openstack_cli_dns/v2/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 Zones command
19//!
20//! Wraps invoking of the `v2/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::dns::v2::zone::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::dns::v2::zone::response;
34
35/// List all zones
36#[derive(Args)]
37#[command(about = "List Zones")]
38pub struct ZonesCommand {
39    /// Request Query parameters
40    #[command(flatten)]
41    query: QueryParameters,
42
43    /// Request Headers parameters
44    #[command(flatten)]
45    headers: HeaderParameters,
46
47    /// Path parameters
48    #[command(flatten)]
49    path: PathParameters,
50
51    /// Total limit of entities count to return. Use this when there are too many entries.
52    #[arg(long, default_value_t = 10000)]
53    max_items: usize,
54}
55
56/// Query parameters
57#[derive(Args)]
58struct QueryParameters {
59    /// Filter results to only show zones that have a type matching the filter
60    #[arg(help_heading = "Query parameters", long, value_parser = ["CATALOG","PRIMARY","SECONDARY"])]
61    _type: Option<String>,
62
63    /// Filter results to only show zones that have a description matching the
64    /// filter
65    #[arg(help_heading = "Query parameters", long)]
66    description: Option<String>,
67
68    /// Filter results to only show zones that have an email matching the
69    /// filter
70    #[arg(help_heading = "Query parameters", long)]
71    email: Option<String>,
72
73    /// Requests a page size of items. Returns a number of items up to a limit
74    /// value. Use the limit parameter to make an initial limited request and
75    /// use the ID of the last-seen item from the response as the marker
76    /// parameter value in a subsequent limited request.
77    #[arg(
78        help_heading = "Query parameters",
79        long("page-size"),
80        visible_alias("limit")
81    )]
82    limit: Option<i32>,
83
84    /// The ID of the last-seen item. Use the limit parameter to make an
85    /// initial limited request and use the ID of the last-seen item from the
86    /// response as the marker parameter value in a subsequent limited request.
87    #[arg(help_heading = "Query parameters", long)]
88    marker: Option<String>,
89
90    /// Filter results to only show zones that have a name matching the filter
91    #[arg(help_heading = "Query parameters", long)]
92    name: Option<String>,
93
94    /// Sorts the response by the requested sort direction. A valid value is
95    /// asc (ascending) or desc (descending). Default is asc. You can specify
96    /// multiple pairs of sort key and sort direction query parameters. If you
97    /// omit the sort direction in a pair, the API uses the natural sorting
98    /// direction of the server attribute that is provided as the sort_key.
99    #[arg(help_heading = "Query parameters", long, value_parser = ["asc","desc"])]
100    sort_dir: Option<String>,
101
102    /// Sorts the response by the this attribute value. Default is id. You can
103    /// specify multiple pairs of sort key and sort direction query parameters.
104    /// If you omit the sort direction in a pair, the API uses the natural
105    /// sorting direction of the server attribute that is provided as the
106    /// sort_key.
107    #[arg(help_heading = "Query parameters", long, value_parser = ["created_at","id","name","serial","status","tenant_id","ttl","updated_at"])]
108    sort_key: Option<String>,
109
110    /// Filter results to only show zones that have a status matching the
111    /// filter
112    #[arg(help_heading = "Query parameters", long, value_parser = ["ACTIVE","DELETED","ERROR","PENDING","SUCCESS","ZONE"])]
113    status: Option<String>,
114
115    /// Filter results to only show zones that have a ttl matching the filter
116    #[arg(help_heading = "Query parameters", long)]
117    ttl: Option<i32>,
118}
119
120/// Header parameters
121#[derive(Args)]
122struct HeaderParameters {
123    /// If enabled this will show results from all projects in Designate
124    #[arg(long)]
125    x_auth_all_projects: Option<bool>,
126
127    /// This allows a user to impersonate another project
128    #[arg(long)]
129    x_auth_sudo_project_id: Option<String>,
130}
131
132/// Path parameters
133#[derive(Args)]
134struct PathParameters {}
135
136impl ZonesCommand {
137    /// Perform command action
138    pub async fn take_action<C: CliArgs>(
139        &self,
140        parsed_args: &C,
141        client: &mut AsyncOpenStack,
142    ) -> Result<(), OpenStackCliError> {
143        info!("List Zones");
144
145        let op = OutputProcessor::from_args(parsed_args, Some("dns.zone"), Some("list"));
146        op.validate_args(parsed_args)?;
147
148        let mut ep_builder = list::Request::builder();
149        // Set path parameters
150        // Set query parameters
151        if let Some(val) = &self.query.description {
152            ep_builder.description(val);
153        }
154        if let Some(val) = &self.query.email {
155            ep_builder.email(val);
156        }
157        if let Some(val) = &self.query.limit {
158            ep_builder.limit(*val);
159        }
160        if let Some(val) = &self.query.marker {
161            ep_builder.marker(val);
162        }
163        if let Some(val) = &self.query.name {
164            ep_builder.name(val);
165        }
166        if let Some(val) = &self.query.sort_dir {
167            ep_builder.sort_dir(val);
168        }
169        if let Some(val) = &self.query.sort_key {
170            ep_builder.sort_key(val);
171        }
172        if let Some(val) = &self.query.status {
173            ep_builder.status(val);
174        }
175        if let Some(val) = &self.query.ttl {
176            ep_builder.ttl(*val);
177        }
178        if let Some(val) = &self.query._type {
179            ep_builder._type(val);
180        }
181        // Set header parameters
182        if let Some(val) = &self.headers.x_auth_all_projects {
183            ep_builder.header(
184                http::header::HeaderName::from_static("x-auth-all-projects"),
185                http::header::HeaderValue::from_static(if *val { "true" } else { "false" }),
186            );
187        }
188        if let Some(val) = &self.headers.x_auth_sudo_project_id {
189            ep_builder.header(
190                http::header::HeaderName::from_static("x-auth-sudo-project-id"),
191                http::header::HeaderValue::from_str(val)?,
192            );
193        }
194
195        let ep = ep_builder
196            .build()
197            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
198
199        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
200            .query_async(client)
201            .await?;
202
203        op.output_list::<response::list::ZoneResponse>(data.clone())?;
204        // Show command specific hints
205        op.show_command_hint()?;
206        Ok(())
207    }
208}