Skip to main content

openstack_cli_block_storage/v3/snapshot/
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 Snapshots command
19//!
20//! Wraps invoking of the `v3/snapshots/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::snapshot::list_detailed;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::block_storage::v3::snapshot::response;
34
35/// Returns a detailed list of snapshots.
36#[derive(Args)]
37pub struct SnapshotsCommand {
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    /// Filters results by consumes_quota field. Resources that don’t use
59    /// quotas are usually temporary internal resources created to perform an
60    /// operation. Default is to not filter by it. Filtering by this option may
61    /// not be always possible in a cloud, see List Resource Filters to
62    /// determine whether this filter is available in your cloud.
63    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
64    consumes_quota: Option<bool>,
65
66    /// Requests a page size of items. Returns a number of items up to a limit
67    /// value. Use the limit parameter to make an initial limited request and
68    /// use the ID of the last-seen item from the response as the marker
69    /// parameter value in a subsequent limited request.
70    #[arg(
71        help_heading = "Query parameters",
72        long("page-size"),
73        visible_alias("limit")
74    )]
75    limit: Option<i32>,
76
77    /// The ID of the last-seen item. Use the limit parameter to make an
78    /// initial limited request and use the ID of the last-seen item from the
79    /// response as the marker parameter value in a subsequent limited request.
80    #[arg(help_heading = "Query parameters", long)]
81    marker: Option<String>,
82
83    /// Used in conjunction with limit to return a slice of items. offset is
84    /// where to start in the list.
85    #[arg(help_heading = "Query parameters", long)]
86    offset: Option<i32>,
87
88    /// Comma-separated list of sort keys and optional sort directions in the
89    /// form of < key > [: < direction > ]. A valid direction is asc
90    /// (ascending) or desc (descending).
91    #[arg(help_heading = "Query parameters", long)]
92    sort: Option<String>,
93
94    /// Sorts by one or more sets of attribute and sort direction combinations.
95    /// If you omit the sort direction in a set, default is desc. Deprecated in
96    /// favour of the combined sort parameter.
97    #[arg(help_heading = "Query parameters", long, value_parser = ["asc","desc"])]
98    sort_dir: Option<String>,
99
100    /// Sorts by an attribute. A valid value is name, status, container_format,
101    /// disk_format, size, id, created_at, or updated_at. Default is
102    /// created_at. The API uses the natural sorting direction of the sort_key
103    /// attribute value. Deprecated in favour of the combined sort parameter.
104    #[arg(help_heading = "Query parameters", long)]
105    sort_key: Option<String>,
106
107    /// Whether to show count in API response or not, default is False.
108    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
109    with_count: Option<bool>,
110}
111
112/// Path parameters
113#[derive(Args)]
114struct PathParameters {}
115
116impl SnapshotsCommand {
117    /// Perform command action
118    pub async fn take_action<C: CliArgs>(
119        &self,
120        parsed_args: &C,
121        client: &mut AsyncOpenStack,
122    ) -> Result<(), OpenStackCliError> {
123        info!("List Snapshots");
124
125        let op =
126            OutputProcessor::from_args(parsed_args, Some("block-storage.snapshot"), Some("list"));
127        op.validate_args(parsed_args)?;
128
129        let mut ep_builder = list_detailed::Request::builder();
130
131        // Set query parameters
132        if let Some(val) = &self.query.all_tenants {
133            ep_builder.all_tenants(*val);
134        }
135        if let Some(val) = &self.query.consumes_quota {
136            ep_builder.consumes_quota(*val);
137        }
138        if let Some(val) = &self.query.limit {
139            ep_builder.limit(*val);
140        }
141        if let Some(val) = &self.query.marker {
142            ep_builder.marker(val);
143        }
144        if let Some(val) = &self.query.offset {
145            ep_builder.offset(*val);
146        }
147        if let Some(val) = &self.query.sort {
148            ep_builder.sort(val);
149        }
150        if let Some(val) = &self.query.sort_dir {
151            ep_builder.sort_dir(val);
152        }
153        if let Some(val) = &self.query.sort_key {
154            ep_builder.sort_key(val);
155        }
156        if let Some(val) = &self.query.with_count {
157            ep_builder.with_count(*val);
158        }
159
160        let ep = ep_builder
161            .build()
162            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
163
164        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
165            .query_async(client)
166            .await?;
167
168        op.output_list::<response::list_detailed::SnapshotResponse>(data.clone())?;
169        // Show command specific hints
170        op.show_command_hint()?;
171        Ok(())
172    }
173}