Skip to main content

openstack_cli_network/v2/network_ip_availability/
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 NetworkIpAvailability command
19//!
20//! Wraps invoking of the `v2.0/network-ip-availabilities/{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::network_ip_availability::get;
32use openstack_types::network::v2::network_ip_availability::response;
33
34/// Shows network IP availability details for a network.
35///
36/// By default policy configuration, only administrative users can retrieve IP
37/// availability. Otherwise, `Not Found (404)` will be returned.
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 Network IP Availability")]
47pub struct NetworkIpAvailabilityCommand {
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    /// id parameter for /v2.0/network-ip-availabilities/{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 NetworkIpAvailabilityCommand {
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 NetworkIpAvailability");
81
82        let op = OutputProcessor::from_args(
83            parsed_args,
84            Some("network.network_ip_availability"),
85            Some("show"),
86        );
87        op.validate_args(parsed_args)?;
88
89        let mut ep_builder = get::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::get::NetworkIpAvailabilityResponse>(data.clone())?;
100        // Show command specific hints
101        op.show_command_hint()?;
102        Ok(())
103    }
104}