Skip to main content

openstack_cli_network/v2/ndp_proxy/
create.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//! Create NdpProxy command
19//!
20//! Wraps invoking of the `v2.0/ndp-proxies` with `POST` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::network::v2::ndp_proxy::create;
33use openstack_types::network::v2::ndp_proxy::response;
34
35/// Command without description in OpenAPI
36#[derive(Args)]
37pub struct NdpProxyCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    #[command(flatten)]
47    ndp_proxy: NdpProxy,
48}
49
50/// Query parameters
51#[derive(Args)]
52struct QueryParameters {}
53
54/// Path parameters
55#[derive(Args)]
56struct PathParameters {}
57/// NdpProxy Body data
58#[derive(Args, Clone)]
59struct NdpProxy {
60    #[arg(help_heading = "Body parameters", long)]
61    description: Option<String>,
62
63    #[arg(help_heading = "Body parameters", long)]
64    ip_address: Option<String>,
65
66    /// Set explicit NULL for the ip_address
67    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "ip_address")]
68    no_ip_address: bool,
69
70    #[arg(help_heading = "Body parameters", long)]
71    name: Option<String>,
72
73    #[arg(help_heading = "Body parameters", long)]
74    port_id: Option<String>,
75
76    #[arg(help_heading = "Body parameters", long)]
77    project_id: Option<String>,
78
79    #[arg(help_heading = "Body parameters", long)]
80    router_id: Option<String>,
81}
82
83impl NdpProxyCommand {
84    /// Perform command action
85    pub async fn take_action<C: CliArgs>(
86        &self,
87        parsed_args: &C,
88        client: &mut AsyncOpenStack,
89    ) -> Result<(), OpenStackCliError> {
90        info!("Create NdpProxy");
91
92        let op = OutputProcessor::from_args(parsed_args, Some("network.ndp_proxy"), Some("create"));
93        op.validate_args(parsed_args)?;
94
95        let mut ep_builder = create::Request::builder();
96
97        // Set body parameters
98        // Set Request.ndp_proxy data
99        let args = &self.ndp_proxy;
100        let mut ndp_proxy_builder = create::NdpProxyBuilder::default();
101        if let Some(val) = &args.description {
102            ndp_proxy_builder.description(val);
103        }
104
105        if let Some(val) = &args.ip_address {
106            ndp_proxy_builder.ip_address(Some(val.into()));
107        } else if args.no_ip_address {
108            ndp_proxy_builder.ip_address(None);
109        }
110
111        if let Some(val) = &args.name {
112            ndp_proxy_builder.name(val);
113        }
114
115        if let Some(val) = &args.port_id {
116            ndp_proxy_builder.port_id(val);
117        }
118
119        if let Some(val) = &args.project_id {
120            ndp_proxy_builder.project_id(val);
121        }
122
123        if let Some(val) = &args.router_id {
124            ndp_proxy_builder.router_id(val);
125        }
126
127        ep_builder.ndp_proxy(
128            ndp_proxy_builder
129                .build()
130                .wrap_err("error preparing the request data")?,
131        );
132
133        let ep = ep_builder
134            .build()
135            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
136
137        let data: serde_json::Value = ep.query_async(client).await?;
138
139        op.output_single::<response::create::NdpProxyResponse>(data.clone())?;
140        // Show command specific hints
141        op.show_command_hint()?;
142        Ok(())
143    }
144}