openstack_cli_compute/v2/simple_tenant_usage.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//! Tenant usage
16
17use clap::{Parser, Subcommand};
18
19use openstack_sdk::AsyncOpenStack;
20
21use openstack_cli_core::{cli::CliArgs, error::OpenStackCliError};
22
23pub mod list;
24pub mod show;
25
26/// Usage reports (os-simple-tenant-usage)
27///
28/// Reports usage statistics of compute and storage resources periodically for an individual tenant
29/// or all tenants. The usage statistics will include all instances’ CPU, memory and local disk
30/// during a specific period.
31///
32/// **Warning**
33///
34/// The os-simple-tenant-usage will report usage statistics based on the latest flavor that is
35/// configured in the virtual machine (VM), and ignoring stop, pause, and other events that might
36/// have happened with the VM. Therefore, it uses the time the VM existed in the cloud environment
37/// to execute the usage accounting.
38///
39/// More information can be found at
40/// http://eavesdrop.openstack.org/meetings/nova/2020/nova.2020-12-03-16.00.log.txt, and
41/// https://review.opendev.org/c/openstack/nova/+/711113
42///
43/// Microversion 2.40 added pagination (and next links) to the usage statistics via optional limit
44/// and marker query parameters. If limit isn’t provided, the configurable max_limit will be used
45/// which currently defaults to 1000. Older microversions will not accept these new paging query
46/// parameters, but they will start to silently limit by max_limit.
47///
48/// ```text
49/// /os-simple-tenant-usage?limit={limit}&marker={instance_uuid}
50/// /os-simple-tenant-usage/{tenant_id}?limit={limit}&marker={instance_uuid}
51/// ```
52///
53/// **Note**
54///
55/// A tenant’s usage statistics may span multiple pages when the number of instances exceeds limit,
56/// and API consumers will need to stitch together the aggregate results if they still want totals
57/// for all instances in a specific time window, grouped by tenant.
58#[derive(Parser)]
59pub struct SimpleTenantUsageCommand {
60 /// subcommand
61 #[command(subcommand)]
62 command: SimpleTenantUsageCommands,
63}
64
65/// Supported subcommands
66#[allow(missing_docs)]
67#[derive(Subcommand)]
68pub enum SimpleTenantUsageCommands {
69 List(list::SimpleTenantUsagesCommand),
70 Show(show::SimpleTenantUsageCommand),
71}
72
73impl SimpleTenantUsageCommand {
74 /// Perform command action
75 pub async fn take_action<C: CliArgs>(
76 &self,
77 parsed_args: &C,
78 session: &mut AsyncOpenStack,
79 ) -> Result<(), OpenStackCliError> {
80 match &self.command {
81 SimpleTenantUsageCommands::List(cmd) => cmd.take_action(parsed_args, session).await,
82 SimpleTenantUsageCommands::Show(cmd) => cmd.take_action(parsed_args, session).await,
83 }
84 }
85}