Skip to main content

openstack_cli_network/v2/metering/metering_label_rule/
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 MeteringLabelRule command
19//!
20//! Wraps invoking of the `v2.0/metering/metering-label-rules/{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::network::v2::metering::metering_label_rule::get;
32use openstack_types::network::v2::metering::metering_label_rule::response;
33
34/// Shows details for a metering label rule.
35///
36/// The response body shows this information for each metering label rule:
37///
38/// Use the `fields` query parameter to control which fields are returned in
39/// the response body. For more information, see [Fields](#fields).
40///
41/// Normal response codes: 200
42///
43/// Error response codes: 401, 404
44#[derive(Args)]
45#[command(about = "Show metering label rule details")]
46pub struct MeteringLabelRuleCommand {
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    /// id parameter for /v2.0/metering/metering-label-rules/{id} API
64    #[arg(
65        help_heading = "Path parameters",
66        id = "path_param_id",
67        value_name = "ID"
68    )]
69    id: String,
70}
71
72impl MeteringLabelRuleCommand {
73    /// Perform command action
74    pub async fn take_action<C: CliArgs>(
75        &self,
76        parsed_args: &C,
77        client: &mut AsyncOpenStack,
78    ) -> Result<(), OpenStackCliError> {
79        info!("Show MeteringLabelRule");
80
81        let op = OutputProcessor::from_args(
82            parsed_args,
83            Some("network.metering/metering_label_rule"),
84            Some("show"),
85        );
86        op.validate_args(parsed_args)?;
87
88        let mut ep_builder = get::Request::builder();
89
90        ep_builder.id(&self.path.id);
91
92        let ep = ep_builder
93            .build()
94            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
95
96        let data: serde_json::Value = ep.query_async(client).await?;
97
98        op.output_single::<response::get::MeteringLabelRuleResponse>(data.clone())?;
99        // Show command specific hints
100        op.show_command_hint()?;
101        Ok(())
102    }
103}