Skip to main content

openstack_cli_network/v2/ndp_proxy/
set.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//! Set NdpProxy command
19//!
20//! Wraps invoking of the `v2.0/ndp-proxies/{id}` with `PUT` 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::find;
33use openstack_sdk::api::network::v2::ndp_proxy::find;
34use openstack_sdk::api::network::v2::ndp_proxy::set;
35use openstack_types::network::v2::ndp_proxy::response;
36
37/// Command without description in OpenAPI
38#[derive(Args)]
39pub struct NdpProxyCommand {
40    /// Request Query parameters
41    #[command(flatten)]
42    query: QueryParameters,
43
44    /// Path parameters
45    #[command(flatten)]
46    path: PathParameters,
47
48    #[command(flatten)]
49    ndp_proxy: NdpProxy,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {}
55
56/// Path parameters
57#[derive(Args)]
58struct PathParameters {
59    /// id parameter for /v2.0/ndp-proxies/{id} API
60    #[arg(
61        help_heading = "Path parameters",
62        id = "path_param_id",
63        value_name = "ID"
64    )]
65    id: String,
66}
67/// NdpProxy Body data
68#[derive(Args, Clone)]
69struct NdpProxy {
70    #[arg(help_heading = "Body parameters", long)]
71    description: Option<String>,
72
73    #[arg(help_heading = "Body parameters", long)]
74    name: Option<String>,
75}
76
77impl NdpProxyCommand {
78    /// Perform command action
79    pub async fn take_action<C: CliArgs>(
80        &self,
81        parsed_args: &C,
82        client: &mut AsyncOpenStack,
83    ) -> Result<(), OpenStackCliError> {
84        info!("Set NdpProxy");
85
86        let op = OutputProcessor::from_args(parsed_args, Some("network.ndp_proxy"), Some("set"));
87        op.validate_args(parsed_args)?;
88
89        let mut find_builder = find::Request::builder();
90
91        find_builder.id(&self.path.id);
92
93        let find_ep = find_builder
94            .build()
95            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
96        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
97
98        let mut ep_builder = set::Request::builder();
99
100        let resource_id = find_data["id"]
101            .as_str()
102            .ok_or_else(|| eyre::eyre!("resource ID must be a string"))?
103            .to_string();
104        ep_builder.id(resource_id.clone());
105
106        // Set body parameters
107        // Set Request.ndp_proxy data
108        let args = &self.ndp_proxy;
109        let mut ndp_proxy_builder = set::NdpProxyBuilder::default();
110        if let Some(val) = &args.description {
111            ndp_proxy_builder.description(val);
112        }
113
114        if let Some(val) = &args.name {
115            ndp_proxy_builder.name(val);
116        }
117
118        ep_builder.ndp_proxy(
119            ndp_proxy_builder
120                .build()
121                .wrap_err("error preparing the request data")?,
122        );
123
124        let ep = ep_builder
125            .build()
126            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
127
128        let data: serde_json::Value = ep.query_async(client).await?;
129
130        op.output_single::<response::set::NdpProxyResponse>(data.clone())?;
131        // Show command specific hints
132        op.show_command_hint()?;
133        Ok(())
134    }
135}