Skip to main content

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