Skip to main content

openstack_cli_compute/v2/simple_tenant_usage/
show.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//! Show SimpleTenantUsage command
19//!
20//! Wraps invoking of the `v2.1/os-simple-tenant-usage/{id}` 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::get;
32use openstack_types::compute::v2::simple_tenant_usage::response;
33
34/// Shows usage statistics for a tenant.
35///
36/// Normal response codes: 200
37///
38/// Error response codes: badRequest(400), unauthorized(401), forbidden(403)
39#[derive(Args)]
40#[command(about = "Show Usage Statistics For Tenant")]
41pub struct SimpleTenantUsageCommand {
42    /// Request Query parameters
43    #[command(flatten)]
44    query: QueryParameters,
45
46    /// Path parameters
47    #[command(flatten)]
48    path: PathParameters,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {
54    #[arg(help_heading = "Query parameters", long)]
55    end: Option<String>,
56
57    /// Requests a page size of items. Returns a number of items up to a limit
58    /// value. Use the limit parameter to make an initial limited request and
59    /// use the ID of the last-seen item from the response as the marker
60    /// parameter value in a subsequent limited request.
61    #[arg(
62        help_heading = "Query parameters",
63        long("page-size"),
64        visible_alias("limit")
65    )]
66    limit: Option<u32>,
67
68    /// The ID of the last-seen item. Use the limit parameter to make an
69    /// initial limited request and use the ID of the last-seen item from the
70    /// response as the marker parameter value in a subsequent limited request.
71    #[arg(help_heading = "Query parameters", long)]
72    marker: Option<String>,
73
74    #[arg(help_heading = "Query parameters", long)]
75    start: Option<String>,
76}
77
78/// Path parameters
79#[derive(Args)]
80struct PathParameters {
81    /// id parameter for /v2.1/os-simple-tenant-usage/{id} API
82    #[arg(
83        help_heading = "Path parameters",
84        id = "path_param_id",
85        value_name = "ID"
86    )]
87    id: String,
88}
89
90impl SimpleTenantUsageCommand {
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!("Show SimpleTenantUsage");
98
99        let op = OutputProcessor::from_args(
100            parsed_args,
101            Some("compute.simple_tenant_usage"),
102            Some("show"),
103        );
104        op.validate_args(parsed_args)?;
105
106        let mut ep_builder = get::Request::builder();
107
108        ep_builder.id(&self.path.id);
109        // Set query parameters
110        if let Some(val) = &self.query.end {
111            ep_builder.end(val);
112        }
113        if let Some(val) = &self.query.limit {
114            ep_builder.limit(*val);
115        }
116        if let Some(val) = &self.query.marker {
117            ep_builder.marker(val);
118        }
119        if let Some(val) = &self.query.start {
120            ep_builder.start(val);
121        }
122
123        let ep = ep_builder
124            .build()
125            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
126
127        let data: serde_json::Value = ep.query_async(client).await?;
128
129        op.output_single::<response::get_21_a::SimpleTenantUsageResponse>(data.clone())
130            .or_else(|_| {
131                op.output_single::<response::get_21_b::SimpleTenantUsageResponse>(data.clone())
132            })
133            .or_else(|_| {
134                op.output_single::<response::get_240_a::SimpleTenantUsageResponse>(data.clone())
135            })
136            .or_else(|_| {
137                op.output_single::<response::get_240_b::SimpleTenantUsageResponse>(data.clone())
138            })?;
139        // Show command specific hints
140        op.show_command_hint()?;
141        Ok(())
142    }
143}