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.0/floatingips/{id}` with `PUT` method

use clap::Args;
use eyre::WrapErr;
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::network::v2::floatingip::set;
use openstack_types::network::v2::floatingip::response::set::FloatingipResponse;

/// Updates a floating IP and its association with an internal port.
///
/// The association process is the same as the process for the create floating
/// IP operation.
///
/// To disassociate a floating IP from a port, set the `port_id` attribute to
/// null or omit it from the request body.
///
/// This example updates a floating IP:
///
/// Depending on the request body that you submit, this request associates a
/// port with or disassociates a port from a floating IP.
///
/// Normal response codes: 200
///
/// Error response codes: 400, 401, 404, 409, 412
#[derive(Args)]
#[command(about = "Update floating IP")]
pub struct FloatingipCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

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

    /// A `floatingip` object. When you associate a floating IP address with a
    /// VM, the instance has the same public IP address each time that it
    /// boots, basically to maintain a consistent IP address for maintaining
    /// DNS assignment.
    #[command(flatten)]
    floatingip: Floatingip,
}

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

/// Path parameters
#[derive(Args)]
struct PathParameters {
    /// id parameter for /v2.0/floatingips/{id} API
    #[arg(
        help_heading = "Path parameters",
        id = "path_param_id",
        value_name = "ID"
    )]
    id: String,
}
/// Floatingip Body data
#[derive(Args, Clone)]
struct Floatingip {
    /// A human-readable description for the resource. Default is an empty
    /// string.
    #[arg(help_heading = "Body parameters", long)]
    description: Option<String>,

    /// The fixed IP address that is associated with the floating IP. If an
    /// internal port has multiple associated IP addresses, the service chooses
    /// the first IP address unless you explicitly define a fixed IP address in
    /// the `fixed_ip_address` parameter.
    #[arg(help_heading = "Body parameters", long)]
    fixed_ip_address: Option<String>,

    /// Set explicit NULL for the fixed_ip_address
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "fixed_ip_address")]
    no_fixed_ip_address: bool,

    /// The ID of a port associated with the floating IP. To associate the
    /// floating IP with a fixed IP, you must specify the ID of the internal
    /// port. To disassociate the floating IP, `null` should be specified.
    #[arg(help_heading = "Body parameters", long)]
    port_id: Option<String>,

    /// Set explicit NULL for the port_id
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "port_id")]
    no_port_id: bool,

    #[arg(help_heading = "Body parameters", long)]
    qos_policy_id: Option<String>,

    /// Set explicit NULL for the qos_policy_id
    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "qos_policy_id")]
    no_qos_policy_id: bool,
}

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("network.floatingip"), Some("set"));
        op.validate_args(parsed_args)?;

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

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

        // Set body parameters
        // Set Request.floatingip data
        let args = &self.floatingip;
        let mut floatingip_builder = set::FloatingipBuilder::default();
        if let Some(val) = &args.description {
            floatingip_builder.description(val);
        }

        if let Some(val) = &args.fixed_ip_address {
            floatingip_builder.fixed_ip_address(Some(val.into()));
        } else if args.no_fixed_ip_address {
            floatingip_builder.fixed_ip_address(None);
        }

        if let Some(val) = &args.port_id {
            floatingip_builder.port_id(Some(val.into()));
        } else if args.no_port_id {
            floatingip_builder.port_id(None);
        }

        if let Some(val) = &args.qos_policy_id {
            floatingip_builder.qos_policy_id(Some(val.into()));
        } else if args.no_qos_policy_id {
            floatingip_builder.qos_policy_id(None);
        }

        ep_builder.floatingip(
            floatingip_builder
                .build()
                .wrap_err("error preparing the request data")?,
        );

        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(())
    }
}