Skip to main content

openstack_cli_compute/v2/server/
reset_network.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_cli_core::cli::CliArgs;
26use openstack_cli_core::error::OpenStackCliError;
27use openstack_cli_core::output::OutputProcessor;
28use openstack_sdk::AsyncOpenStack;
29
30use openstack_sdk::api::QueryAsync;
31use openstack_sdk::api::compute::v2::server::reset_network;
32
33/// Resets networking on a server.
34///
35/// Specify the `resetNetwork` action in the request body.
36///
37/// Policy defaults enable only users with the administrative role to perform
38/// this operation. Cloud providers can change these permissions through the
39/// `policy.yaml` file.
40///
41/// Normal response codes: 202
42///
43/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
44/// conflict(409), gone(410)
45#[derive(Args)]
46#[command(about = "Reset Networking On A Server (resetNetwork Action) (DEPRECATED)")]
47pub struct ServerCommand {
48    /// Request Query parameters
49    #[command(flatten)]
50    query: QueryParameters,
51
52    /// Path parameters
53    #[command(flatten)]
54    path: PathParameters,
55}
56
57/// Query parameters
58#[derive(Args)]
59struct QueryParameters {}
60
61/// Path parameters
62#[derive(Args)]
63struct PathParameters {
64    /// id parameter for /v2.1/servers/{id}/action API
65    #[arg(
66        help_heading = "Path parameters",
67        id = "path_param_id",
68        value_name = "ID"
69    )]
70    id: String,
71}
72
73impl ServerCommand {
74    /// Perform command action
75    pub async fn take_action<C: CliArgs>(
76        &self,
77        parsed_args: &C,
78        client: &mut AsyncOpenStack,
79    ) -> Result<(), OpenStackCliError> {
80        info!("Action Server");
81
82        let op =
83            OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("reset_network"));
84        op.validate_args(parsed_args)?;
85
86        let mut ep_builder = reset_network::Request::builder();
87
88        ep_builder.id(&self.path.id);
89
90        let ep = ep_builder
91            .build()
92            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
93        openstack_sdk::api::ignore(ep).query_async(client).await?;
94        // Show command specific hints
95        op.show_command_hint()?;
96        Ok(())
97    }
98}