openstack_cli/network/v2/agent/dhcp_network/
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 DhcpNetwork command
19//!
20//! Wraps invoking of the `v2.0/agents/{agent_id}/dhcp-networks/{id}` with `GET` method
21
22use clap::Args;
23use serde::{Deserialize, Serialize};
24use tracing::info;
25
26use openstack_sdk::AsyncOpenStack;
27
28use crate::Cli;
29use crate::OpenStackCliError;
30use crate::OutputConfig;
31use crate::StructTable;
32use crate::output::OutputProcessor;
33
34use openstack_sdk::api::QueryAsync;
35use openstack_sdk::api::network::v2::agent::dhcp_network::get;
36use serde_json::Value;
37use std::collections::HashMap;
38
39/// Command without description in OpenAPI
40///
41#[derive(Args)]
42pub struct DhcpNetworkCommand {
43    /// Request Query parameters
44    #[command(flatten)]
45    query: QueryParameters,
46
47    /// Path parameters
48    #[command(flatten)]
49    path: PathParameters,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {}
55
56/// Path parameters
57#[derive(Args)]
58struct PathParameters {
59    /// agent_id parameter for /v2.0/agents/{agent_id}/dhcp-networks/{id} API
60    ///
61    #[arg(
62        help_heading = "Path parameters",
63        id = "path_param_agent_id",
64        value_name = "AGENT_ID"
65    )]
66    agent_id: String,
67
68    /// id parameter for /v2.0/agents/{agent_id}/dhcp-networks/{id} API
69    ///
70    #[arg(
71        help_heading = "Path parameters",
72        id = "path_param_id",
73        value_name = "ID"
74    )]
75    id: String,
76}
77/// Response data as HashMap type
78#[derive(Deserialize, Serialize)]
79struct ResponseData(HashMap<String, Value>);
80
81impl StructTable for ResponseData {
82    fn build(&self, _options: &OutputConfig) -> (Vec<String>, Vec<Vec<String>>) {
83        let headers: Vec<String> = Vec::from(["Name".to_string(), "Value".to_string()]);
84        let mut rows: Vec<Vec<String>> = Vec::new();
85        rows.extend(self.0.iter().map(|(k, v)| {
86            Vec::from([
87                k.clone(),
88                serde_json::to_string(&v).expect("Is a valid data"),
89            ])
90        }));
91        (headers, rows)
92    }
93}
94
95impl DhcpNetworkCommand {
96    /// Perform command action
97    pub async fn take_action(
98        &self,
99        parsed_args: &Cli,
100        client: &mut AsyncOpenStack,
101    ) -> Result<(), OpenStackCliError> {
102        info!("Show DhcpNetwork");
103
104        let op = OutputProcessor::from_args(parsed_args);
105        op.validate_args(parsed_args)?;
106
107        let mut ep_builder = get::Request::builder();
108
109        // Set path parameters
110        ep_builder.agent_id(&self.path.agent_id);
111        ep_builder.id(&self.path.id);
112        // Set query parameters
113        // Set body parameters
114
115        let ep = ep_builder
116            .build()
117            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
118
119        let data = ep.query_async(client).await?;
120        op.output_single::<ResponseData>(data)?;
121        Ok(())
122    }
123}