openstack_cli/compute/v2/server/
inject_network_info.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
19//!
20//! Wraps invoking of the `v2.1/servers/{id}/action` with `POST` method
21
22use clap::Args;
23use tracing::info;
24
25use openstack_sdk::AsyncOpenStack;
26
27use crate::Cli;
28use crate::OpenStackCliError;
29use crate::output::OutputProcessor;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::server::inject_network_info;
33use serde_json::Value;
34
35/// Injects network information into a server.
36///
37/// Specify the `injectNetworkInfo` action in the request body.
38///
39/// Policy defaults enable only users with the administrative role to perform
40/// this operation. Cloud providers can change these permissions through the
41/// `policy.json` file.
42///
43/// Normal response codes: 202
44///
45/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
46/// conflict(409)
47#[derive(Args)]
48#[command(about = "Inject Network Information (injectNetworkInfo Action)")]
49pub struct ServerCommand {
50    /// Request Query parameters
51    #[command(flatten)]
52    query: QueryParameters,
53
54    /// Path parameters
55    #[command(flatten)]
56    path: PathParameters,
57
58    #[arg(help_heading = "Body parameters", long, value_name="JSON", value_parser=crate::common::parse_json)]
59    inject_network_info: Value,
60}
61
62/// Query parameters
63#[derive(Args)]
64struct QueryParameters {}
65
66/// Path parameters
67#[derive(Args)]
68struct PathParameters {
69    /// id parameter for /v2.1/servers/{id}/action API
70    #[arg(
71        help_heading = "Path parameters",
72        id = "path_param_id",
73        value_name = "ID"
74    )]
75    id: String,
76}
77
78impl ServerCommand {
79    /// Perform command action
80    pub async fn take_action(
81        &self,
82        parsed_args: &Cli,
83        client: &mut AsyncOpenStack,
84    ) -> Result<(), OpenStackCliError> {
85        info!("Action Server");
86
87        let op = OutputProcessor::from_args(
88            parsed_args,
89            Some("compute.server"),
90            Some("inject_network_info"),
91        );
92        op.validate_args(parsed_args)?;
93
94        let mut ep_builder = inject_network_info::Request::builder();
95
96        ep_builder.id(&self.path.id);
97
98        // Set body parameters
99        // Set Request.inject_network_info data
100        ep_builder.inject_network_info(self.inject_network_info.clone());
101
102        let ep = ep_builder
103            .build()
104            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
105        openstack_sdk::api::ignore(ep).query_async(client).await?;
106        // Show command specific hints
107        op.show_command_hint()?;
108        Ok(())
109    }
110}