Skip to main content

openstack_cli_load_balancer/v2/loadbalancer/
stats.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//! Get Loadbalancer command
19//!
20//! Wraps invoking of the `v2/lbaas/loadbalancers/{loadbalancer_id}/stats` 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::load_balancer::v2::loadbalancer::stats;
32use openstack_types::load_balancer::v2::loadbalancer::response;
33
34/// Shows the current statistics for a load balancer.
35///
36/// This operation returns the statistics of a load balancer object identified
37/// by loadbalancer_id.
38///
39/// If you are not an administrative user and the load balancer object does not
40/// belong to your project, the service returns the HTTP `Forbidden (403)`
41/// response code.
42///
43/// This operation does not require a request body.
44#[derive(Args)]
45#[command(about = "Get Load Balancer statistics")]
46pub struct LoadbalancerCommand {
47    /// Request Query parameters
48    #[command(flatten)]
49    query: QueryParameters,
50
51    /// Path parameters
52    #[command(flatten)]
53    path: PathParameters,
54}
55
56/// Query parameters
57#[derive(Args)]
58struct QueryParameters {}
59
60/// Path parameters
61#[derive(Args)]
62struct PathParameters {
63    /// loadbalancer_id parameter for
64    /// /v2/lbaas/loadbalancers/{loadbalancer_id}/stats API
65    #[arg(
66        help_heading = "Path parameters",
67        id = "path_param_id",
68        value_name = "ID"
69    )]
70    id: String,
71}
72
73impl LoadbalancerCommand {
74    /// Perform command action
75    pub async fn take_action<C: CliArgs>(
76        &self,
77        parsed_args: &C,
78        client: &mut AsyncOpenStack,
79    ) -> Result<(), OpenStackCliError> {
80        info!("Get Loadbalancer");
81
82        let op = OutputProcessor::from_args(
83            parsed_args,
84            Some("load-balancer.loadbalancer"),
85            Some("stats"),
86        );
87        op.validate_args(parsed_args)?;
88
89        let mut ep_builder = stats::Request::builder();
90
91        ep_builder.id(&self.path.id);
92
93        let ep = ep_builder
94            .build()
95            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
96
97        let data: serde_json::Value = ep.query_async(client).await?;
98
99        op.output_single::<response::stats::LoadbalancerResponse>(data.clone())?;
100        // Show command specific hints
101        op.show_command_hint()?;
102        Ok(())
103    }
104}