openstack_cli_compute/v2/server/unrescue.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::unrescue;
32use serde_json::Value;
33
34/// Unrescues a server. Changes status to `ACTIVE`.
35///
36/// Specify the `unrescue` action in the request body.
37///
38/// **Preconditions**
39///
40/// The server must exist.
41///
42/// You can only unrescue a server when its status is `RESCUE`.
43///
44/// **Asynchronous Postconditions**
45///
46/// After you successfully unrescue a server and make a
47/// `GET /servers/{server_id}` request, its status changes to `ACTIVE`.
48///
49/// Normal response codes: 202
50///
51/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
52/// conflict(409), notImplemented(501)
53#[derive(Args)]
54#[command(about = "Unrescue Server (unrescue Action)")]
55pub struct ServerCommand {
56 /// Request Query parameters
57 #[command(flatten)]
58 query: QueryParameters,
59
60 /// Path parameters
61 #[command(flatten)]
62 path: PathParameters,
63
64 /// OpenAPI specifies the field as '{}'.
65 #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
66 unrescue: Value,
67}
68
69/// Query parameters
70#[derive(Args)]
71struct QueryParameters {}
72
73/// Path parameters
74#[derive(Args)]
75struct PathParameters {
76 /// id parameter for /v2.1/servers/{id}/action API
77 #[arg(
78 help_heading = "Path parameters",
79 id = "path_param_id",
80 value_name = "ID"
81 )]
82 id: String,
83}
84
85impl ServerCommand {
86 /// Perform command action
87 pub async fn take_action<C: CliArgs>(
88 &self,
89 parsed_args: &C,
90 client: &mut AsyncOpenStack,
91 ) -> Result<(), OpenStackCliError> {
92 info!("Action Server");
93
94 let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("unrescue"));
95 op.validate_args(parsed_args)?;
96
97 let mut ep_builder = unrescue::Request::builder();
98
99 ep_builder.id(&self.path.id);
100
101 // Set body parameters
102 // Set Request.unrescue data
103 ep_builder.unrescue(self.unrescue.clone());
104
105 let ep = ep_builder
106 .build()
107 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
108 openstack_sdk::api::ignore(ep).query_async(client).await?;
109 // Show command specific hints
110 op.show_command_hint()?;
111 Ok(())
112 }
113}