Skip to main content

openstack_cli_compute/v2/server/
remove_floating_ip_21.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//! Action Server command [microversion = 2.1]
19//!
20//! Wraps invoking of the `v2.1/servers/{id}/action` 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::compute::v2::server::remove_floating_ip_21;
33
34/// Removes, or disassociates, a floating IP address from a server.
35///
36/// The IP address is returned to the pool of IP addresses that is available
37/// for all projects. When you remove a floating IP address and that IP address
38/// is still associated with a running instance, it is automatically
39/// disassociated from that instance.
40///
41/// Specify the `removeFloatingIp` action in the request body.
42///
43/// Normal response codes: 202
44///
45/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
46/// itemNotFound(404), conflict(409)
47#[derive(Args)]
48#[command(
49    about = "Remove (Disassociate) Floating Ip (removeFloatingIp Action) (DEPRECATED) (microversion = 2.1)"
50)]
51pub struct ServerCommand {
52    /// Request Query parameters
53    #[command(flatten)]
54    query: QueryParameters,
55
56    /// Path parameters
57    #[command(flatten)]
58    path: PathParameters,
59
60    /// The action to remove or disassociate a floating IP address from the
61    /// server.
62    #[command(flatten)]
63    remove_floating_ip: RemoveFloatingIp,
64}
65
66/// Query parameters
67#[derive(Args)]
68struct QueryParameters {}
69
70/// Path parameters
71#[derive(Args)]
72struct PathParameters {
73    /// id parameter for /v2.1/servers/{id}/action API
74    #[arg(
75        help_heading = "Path parameters",
76        id = "path_param_id",
77        value_name = "ID"
78    )]
79    id: String,
80}
81/// RemoveFloatingIp Body data
82#[derive(Args, Clone)]
83struct RemoveFloatingIp {
84    /// The floating IP address.
85    #[arg(help_heading = "Body parameters", long)]
86    address: String,
87}
88
89impl ServerCommand {
90    /// Perform command action
91    pub async fn take_action<C: CliArgs>(
92        &self,
93        parsed_args: &C,
94        client: &mut AsyncOpenStack,
95    ) -> Result<(), OpenStackCliError> {
96        info!("Action Server");
97
98        let op = OutputProcessor::from_args(
99            parsed_args,
100            Some("compute.server"),
101            Some("remove_floating_ip"),
102        );
103        op.validate_args(parsed_args)?;
104
105        let mut ep_builder = remove_floating_ip_21::Request::builder();
106        ep_builder.header(
107            http::header::HeaderName::from_static("openstack-api-version"),
108            http::header::HeaderValue::from_static("compute 2.1"),
109        );
110
111        ep_builder.id(&self.path.id);
112
113        // Set body parameters
114        // Set Request.remove_floating_ip data
115        let args = &self.remove_floating_ip;
116        let mut remove_floating_ip_builder =
117            remove_floating_ip_21::RemoveFloatingIpBuilder::default();
118
119        remove_floating_ip_builder.address(&args.address);
120
121        ep_builder.remove_floating_ip(
122            remove_floating_ip_builder
123                .build()
124                .wrap_err("error preparing the request data")?,
125        );
126
127        let ep = ep_builder
128            .build()
129            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
130        openstack_sdk::api::ignore(ep).query_async(client).await?;
131        // Show command specific hints
132        op.show_command_hint()?;
133        Ok(())
134    }
135}