openstack_cli_block_storage/v3/backup/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 Backups command
19//!
20//! Wraps invoking of the `v3/backups/detail` 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::block_storage::v3::backup::list_detailed;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::block_storage::v3::backup::response;
34
35/// Returns a detailed list of backups.
36#[derive(Args)]
37pub struct BackupsCommand {
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 /// Shows details for all project. Admin only.
55 #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
56 all_tenants: Option<bool>,
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<i32>,
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 /// Used in conjunction with limit to return a slice of items. offset is
76 /// where to start in the list.
77 #[arg(help_heading = "Query parameters", long)]
78 offset: Option<i32>,
79
80 /// Comma-separated list of sort keys and optional sort directions in the
81 /// form of < key > [: < direction > ]. A valid direction is asc
82 /// (ascending) or desc (descending).
83 #[arg(help_heading = "Query parameters", long)]
84 sort: Option<String>,
85
86 /// Sorts by one or more sets of attribute and sort direction combinations.
87 /// If you omit the sort direction in a set, default is desc. Deprecated in
88 /// favour of the combined sort parameter.
89 #[arg(help_heading = "Query parameters", long)]
90 sort_dir: Option<String>,
91
92 /// Sorts by an attribute. A valid value is name, status, container_format,
93 /// disk_format, size, id, created_at, or updated_at. Default is
94 /// created_at. The API uses the natural sorting direction of the sort_key
95 /// attribute value. Deprecated in favour of the combined sort parameter.
96 #[arg(help_heading = "Query parameters", long)]
97 sort_key: Option<String>,
98
99 /// Whether to show count in API response or not, default is False.
100 #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
101 with_count: Option<bool>,
102}
103
104/// Path parameters
105#[derive(Args)]
106struct PathParameters {}
107
108impl BackupsCommand {
109 /// Perform command action
110 pub async fn take_action<C: CliArgs>(
111 &self,
112 parsed_args: &C,
113 client: &mut AsyncOpenStack,
114 ) -> Result<(), OpenStackCliError> {
115 info!("List Backups");
116
117 let op =
118 OutputProcessor::from_args(parsed_args, Some("block-storage.backup"), Some("list"));
119 op.validate_args(parsed_args)?;
120
121 let mut ep_builder = list_detailed::Request::builder();
122
123 // Set query parameters
124 if let Some(val) = &self.query.all_tenants {
125 ep_builder.all_tenants(*val);
126 }
127 if let Some(val) = &self.query.limit {
128 ep_builder.limit(*val);
129 }
130 if let Some(val) = &self.query.marker {
131 ep_builder.marker(val);
132 }
133 if let Some(val) = &self.query.offset {
134 ep_builder.offset(*val);
135 }
136 if let Some(val) = &self.query.sort {
137 ep_builder.sort(val);
138 }
139 if let Some(val) = &self.query.sort_dir {
140 ep_builder.sort_dir(val);
141 }
142 if let Some(val) = &self.query.sort_key {
143 ep_builder.sort_key(val);
144 }
145 if let Some(val) = &self.query.with_count {
146 ep_builder.with_count(*val);
147 }
148
149 let ep = ep_builder
150 .build()
151 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
152
153 let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
154 .query_async(client)
155 .await?;
156
157 op.output_list::<response::list_detailed::BackupResponse>(data.clone())?;
158 // Show command specific hints
159 op.show_command_hint()?;
160 Ok(())
161 }
162}