openstack_cli 0.13.5

OpenStack client rewritten in Rust
Documentation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.

//! Set Floatingip command
//!
//! Wraps invoking of the `v2/reverse/floatingips/{fip_key}` with `PATCH` method

use clap::Args;
use tracing::info;

use openstack_sdk::AsyncOpenStack;

use crate::Cli;
use crate::OpenStackCliError;
use crate::output::OutputProcessor;

use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::dns::v2::reverse::floatingip::set;
use openstack_types::dns::v2::reverse::floatingip::response::set::FloatingipResponse;

/// Set a PTR record for the given FloatingIP. The domain if it does not exist
/// will be provisioned automatically.
#[derive(Args)]
#[command(about = "Set  FloatingIP’s PTR record")]
pub struct FloatingipCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

    /// Path parameters
    #[command(flatten)]
    path: PathParameters,

    /// The floatingip address for this PTR record.
    #[arg(help_heading = "Body parameters", long)]
    address: Option<String>,

    /// Description for this PTR record
    #[arg(help_heading = "Body parameters", long)]
    description: Option<String>,

    /// Domain name for this PTR record
    #[arg(help_heading = "Body parameters", long)]
    ptrdname: Option<String>,

    /// Time to live for this PTR record
    #[arg(help_heading = "Body parameters", long)]
    ttl: Option<i32>,
}

/// Query parameters
#[derive(Args)]
struct QueryParameters {}

/// Path parameters
#[derive(Args)]
struct PathParameters {
    /// fip_key parameter for /v2/reverse/floatingips/{fip_key} API
    #[arg(
        help_heading = "Path parameters",
        id = "path_param_fip_key",
        value_name = "FIP_KEY"
    )]
    fip_key: String,
}

impl FloatingipCommand {
    /// Perform command action
    pub async fn take_action(
        &self,
        parsed_args: &Cli,
        client: &mut AsyncOpenStack,
    ) -> Result<(), OpenStackCliError> {
        info!("Set Floatingip");

        let op =
            OutputProcessor::from_args(parsed_args, Some("dns.reverse/floatingip"), Some("set"));
        op.validate_args(parsed_args)?;

        let mut ep_builder = set::Request::builder();

        ep_builder.fip_key(&self.path.fip_key);

        // Set body parameters
        // Set Request.address data
        if let Some(arg) = &self.address {
            ep_builder.address(arg);
        }

        // Set Request.description data
        if let Some(arg) = &self.description {
            ep_builder.description(arg);
        }

        // Set Request.ptrdname data
        if let Some(arg) = &self.ptrdname {
            ep_builder.ptrdname(Some(arg.into()));
        }

        // Set Request.ttl data
        if let Some(arg) = &self.ttl {
            ep_builder.ttl(*arg);
        }

        let ep = ep_builder
            .build()
            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;

        let data = ep.query_async(client).await?;
        op.output_single::<FloatingipResponse>(data)?;
        // Show command specific hints
        op.show_command_hint()?;
        Ok(())
    }
}