Skip to main content

openstack_cli_compute/v2/simple_tenant_usage/
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 SimpleTenantUsages command
19//!
20//! Wraps invoking of the `v2.1/os-simple-tenant-usage` 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::compute::v2::simple_tenant_usage::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::compute::v2::simple_tenant_usage::response;
34
35/// Lists usage statistics for all tenants.
36///
37/// Normal response codes: 200
38///
39/// Error response codes: badRequest(400), unauthorized(401), forbidden(403)
40#[derive(Args)]
41#[command(about = "List Tenant Usage Statistics For All Tenants")]
42pub struct SimpleTenantUsagesCommand {
43    /// Request Query parameters
44    #[command(flatten)]
45    query: QueryParameters,
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    #[arg(help_heading = "Query parameters", long)]
60    detailed: Option<String>,
61
62    #[arg(help_heading = "Query parameters", long)]
63    end: Option<String>,
64
65    /// Requests a page size of items. Returns a number of items up to a limit
66    /// value. Use the limit parameter to make an initial limited request and
67    /// use the ID of the last-seen item from the response as the marker
68    /// parameter value in a subsequent limited request.
69    #[arg(
70        help_heading = "Query parameters",
71        long("page-size"),
72        visible_alias("limit")
73    )]
74    limit: Option<u32>,
75
76    /// The ID of the last-seen item. Use the limit parameter to make an
77    /// initial limited request and use the ID of the last-seen item from the
78    /// response as the marker parameter value in a subsequent limited request.
79    #[arg(help_heading = "Query parameters", long)]
80    marker: Option<String>,
81
82    #[arg(help_heading = "Query parameters", long)]
83    start: Option<String>,
84}
85
86/// Path parameters
87#[derive(Args)]
88struct PathParameters {}
89
90impl SimpleTenantUsagesCommand {
91    /// Perform command action
92    pub async fn take_action<C: CliArgs>(
93        &self,
94        parsed_args: &C,
95        client: &mut AsyncOpenStack,
96    ) -> Result<(), OpenStackCliError> {
97        info!("List SimpleTenantUsages");
98
99        let op = OutputProcessor::from_args(
100            parsed_args,
101            Some("compute.simple_tenant_usage"),
102            Some("list"),
103        );
104        op.validate_args(parsed_args)?;
105
106        let mut ep_builder = list::Request::builder();
107
108        // Set query parameters
109        if let Some(val) = &self.query.detailed {
110            ep_builder.detailed(val);
111        }
112        if let Some(val) = &self.query.end {
113            ep_builder.end(val);
114        }
115        if let Some(val) = &self.query.limit {
116            ep_builder.limit(*val);
117        }
118        if let Some(val) = &self.query.marker {
119            ep_builder.marker(val);
120        }
121        if let Some(val) = &self.query.start {
122            ep_builder.start(val);
123        }
124
125        let ep = ep_builder
126            .build()
127            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
128
129        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
130            .query_async(client)
131            .await?;
132
133        op.output_list::<response::list_21::SimpleTenantUsageResponse>(data.clone())
134            .or_else(|_| {
135                op.output_list::<response::list_240::SimpleTenantUsageResponse>(data.clone())
136            })?;
137        // Show command specific hints
138        op.show_command_hint()?;
139        Ok(())
140    }
141}