openstack_cli_network/v2/subnet/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 Subnet command
19//!
20//! Wraps invoking of the `v2.0/subnets/{subnet_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::find;
32use openstack_sdk::api::network::v2::subnet::find;
33use openstack_types::network::v2::subnet::response;
34
35/// Shows details for a subnet.
36///
37/// Use the fields query parameter to filter the results.
38///
39/// Use the `fields` query parameter to control which fields are returned in
40/// the response body. For more information, see [Fields](#fields).
41///
42/// Normal response codes: 200
43///
44/// Error response codes: 401, 404
45#[derive(Args)]
46#[command(about = "Show subnet details")]
47pub struct SubnetCommand {
48 /// Request Query parameters
49 #[command(flatten)]
50 query: QueryParameters,
51
52 /// Path parameters
53 #[command(flatten)]
54 path: PathParameters,
55}
56
57/// Query parameters
58#[derive(Args)]
59struct QueryParameters {}
60
61/// Path parameters
62#[derive(Args)]
63struct PathParameters {
64 /// subnet_id parameter for /v2.0/subnets/{subnet_id} API
65 #[arg(
66 help_heading = "Path parameters",
67 id = "path_param_id",
68 value_name = "ID"
69 )]
70 id: String,
71}
72
73impl SubnetCommand {
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!("Show Subnet");
81
82 let op = OutputProcessor::from_args(parsed_args, Some("network.subnet"), Some("show"));
83 op.validate_args(parsed_args)?;
84
85 let mut find_builder = find::Request::builder();
86
87 find_builder.id(&self.path.id);
88
89 let find_ep = find_builder
90 .build()
91 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
92 let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
93
94 op.output_single::<response::get::SubnetResponse>(find_data.clone())?;
95 // Show command specific hints
96 op.show_command_hint()?;
97 Ok(())
98 }
99}