Skip to main content

openstack_cli_compute/v2/server/
add_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::add_fixed_ip_21;
33
34/// Adds a fixed IP address to a server instance, which associates that address
35/// with the server. The fixed IP address is retrieved from the network that
36/// you specify in the request.
37///
38/// Specify the `addFixedIp` action and the network ID in the request body.
39///
40/// Policy defaults enable only users with the administrative role or the owner
41/// of the server to perform this operation. Cloud providers can change these
42/// permissions through the `policy.yaml` file.
43///
44/// Normal response codes: 202
45///
46/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
47/// itemNotFound(404)
48#[derive(Args)]
49#[command(about = "Add (Associate) Fixed Ip (addFixedIp Action) (DEPRECATED) (microversion = 2.1)")]
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 add a fixed ip address to a server.
60    #[command(flatten)]
61    add_fixed_ip: AddFixedIp,
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/// AddFixedIp Body data
80#[derive(Args, Clone)]
81struct AddFixedIp {
82    /// The network ID.
83    #[arg(help_heading = "Body parameters", long)]
84    network_id: 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 =
97            OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("add_fixed_ip"));
98        op.validate_args(parsed_args)?;
99
100        let mut ep_builder = add_fixed_ip_21::Request::builder();
101        ep_builder.header(
102            http::header::HeaderName::from_static("openstack-api-version"),
103            http::header::HeaderValue::from_static("compute 2.1"),
104        );
105
106        ep_builder.id(&self.path.id);
107
108        // Set body parameters
109        // Set Request.add_fixed_ip data
110        let args = &self.add_fixed_ip;
111        let mut add_fixed_ip_builder = add_fixed_ip_21::AddFixedIpBuilder::default();
112
113        add_fixed_ip_builder.network_id(&args.network_id);
114
115        ep_builder.add_fixed_ip(
116            add_fixed_ip_builder
117                .build()
118                .wrap_err("error preparing the request data")?,
119        );
120
121        let ep = ep_builder
122            .build()
123            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
124        openstack_sdk::api::ignore(ep).query_async(client).await?;
125        // Show command specific hints
126        op.show_command_hint()?;
127        Ok(())
128    }
129}