Skip to main content

openstack_cli_compute/v2/server/
remove_fixed_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_fixed_ip_21;
33
34/// Removes, or disassociates, a fixed IP address from a server.
35///
36/// Specify the `removeFixedIp` action in the request body.
37///
38/// Policy defaults enable only users with the administrative role or the owner
39/// of the server to perform this operation. Cloud providers can change these
40/// permissions through the `policy.yaml` file.
41///
42/// Normal response codes: 202
43///
44/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
45/// itemNotFound(404)
46#[derive(Args)]
47#[command(
48    about = "Remove (Disassociate) Fixed Ip (removeFixedIp Action) (DEPRECATED) (microversion = 2.1)"
49)]
50pub struct ServerCommand {
51    /// Request Query parameters
52    #[command(flatten)]
53    query: QueryParameters,
54
55    /// Path parameters
56    #[command(flatten)]
57    path: PathParameters,
58
59    /// The action to remove a fixed ip address from a server.
60    #[command(flatten)]
61    remove_fixed_ip: RemoveFixedIp,
62}
63
64/// Query parameters
65#[derive(Args)]
66struct QueryParameters {}
67
68/// Path parameters
69#[derive(Args)]
70struct PathParameters {
71    /// id parameter for /v2.1/servers/{id}/action API
72    #[arg(
73        help_heading = "Path parameters",
74        id = "path_param_id",
75        value_name = "ID"
76    )]
77    id: String,
78}
79/// RemoveFixedIp Body data
80#[derive(Args, Clone)]
81struct RemoveFixedIp {
82    /// The IP address.
83    #[arg(help_heading = "Body parameters", long)]
84    address: String,
85}
86
87impl ServerCommand {
88    /// Perform command action
89    pub async fn take_action<C: CliArgs>(
90        &self,
91        parsed_args: &C,
92        client: &mut AsyncOpenStack,
93    ) -> Result<(), OpenStackCliError> {
94        info!("Action Server");
95
96        let op = OutputProcessor::from_args(
97            parsed_args,
98            Some("compute.server"),
99            Some("remove_fixed_ip"),
100        );
101        op.validate_args(parsed_args)?;
102
103        let mut ep_builder = remove_fixed_ip_21::Request::builder();
104        ep_builder.header(
105            http::header::HeaderName::from_static("openstack-api-version"),
106            http::header::HeaderValue::from_static("compute 2.1"),
107        );
108
109        ep_builder.id(&self.path.id);
110
111        // Set body parameters
112        // Set Request.remove_fixed_ip data
113        let args = &self.remove_fixed_ip;
114        let mut remove_fixed_ip_builder = remove_fixed_ip_21::RemoveFixedIpBuilder::default();
115
116        remove_fixed_ip_builder.address(&args.address);
117
118        ep_builder.remove_fixed_ip(
119            remove_fixed_ip_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        openstack_sdk::api::ignore(ep).query_async(client).await?;
128        // Show command specific hints
129        op.show_command_hint()?;
130        Ok(())
131    }
132}