Skip to main content

openstack_cli_dns/v2/reverse/floatingip/
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 Floatingip command
19//!
20//! Wraps invoking of the `v2/reverse/floatingips/{fip_key}` with `PATCH` 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::dns::v2::reverse::floatingip::set;
32use openstack_types::dns::v2::reverse::floatingip::response;
33
34/// Set a PTR record for the given FloatingIP. The domain if it does not exist
35/// will be provisioned automatically.
36#[derive(Args)]
37#[command(about = "Set  FloatingIP’s PTR record")]
38pub struct FloatingipCommand {
39    /// Request Query parameters
40    #[command(flatten)]
41    query: QueryParameters,
42
43    /// Path parameters
44    #[command(flatten)]
45    path: PathParameters,
46
47    /// The floatingip address for this PTR record.
48    #[arg(help_heading = "Body parameters", long)]
49    address: Option<String>,
50
51    /// Description for this PTR record
52    #[arg(help_heading = "Body parameters", long)]
53    description: Option<String>,
54
55    /// Domain name for this PTR record
56    #[arg(help_heading = "Body parameters", long)]
57    ptrdname: Option<String>,
58
59    /// Time to live for this PTR record
60    #[arg(help_heading = "Body parameters", long)]
61    ttl: Option<i32>,
62}
63
64/// Query parameters
65#[derive(Args)]
66struct QueryParameters {}
67
68/// Path parameters
69#[derive(Args)]
70struct PathParameters {
71    /// fip_key parameter for /v2/reverse/floatingips/{fip_key} API
72    #[arg(
73        help_heading = "Path parameters",
74        id = "path_param_fip_key",
75        value_name = "FIP_KEY"
76    )]
77    fip_key: String,
78}
79
80impl FloatingipCommand {
81    /// Perform command action
82    pub async fn take_action<C: CliArgs>(
83        &self,
84        parsed_args: &C,
85        client: &mut AsyncOpenStack,
86    ) -> Result<(), OpenStackCliError> {
87        info!("Set Floatingip");
88
89        let op =
90            OutputProcessor::from_args(parsed_args, Some("dns.reverse/floatingip"), Some("set"));
91        op.validate_args(parsed_args)?;
92
93        let mut ep_builder = set::Request::builder();
94
95        ep_builder.fip_key(&self.path.fip_key);
96
97        // Set body parameters
98        // Set Request.address data
99        if let Some(arg) = &self.address {
100            ep_builder.address(arg);
101        }
102
103        // Set Request.description data
104        if let Some(arg) = &self.description {
105            ep_builder.description(arg);
106        }
107
108        // Set Request.ptrdname data
109        if let Some(arg) = &self.ptrdname {
110            ep_builder.ptrdname(Some(arg.into()));
111        }
112
113        // Set Request.ttl data
114        if let Some(arg) = &self.ttl {
115            ep_builder.ttl(*arg);
116        }
117
118        let ep = ep_builder
119            .build()
120            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
121
122        let data: serde_json::Value = ep.query_async(client).await?;
123
124        op.output_single::<response::set::FloatingipResponse>(data.clone())?;
125        // Show command specific hints
126        op.show_command_hint()?;
127        Ok(())
128    }
129}