Skip to main content

openstack_cli_compute/v2/server/
rescue.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 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::rescue;
33use openstack_types::compute::v2::server::response;
34
35/// Puts a server in rescue mode and changes its status to `RESCUE`.
36///
37/// Specify the `rescue` action in the request body.
38///
39/// If you specify the `rescue_image_ref` extended attribute, the image is used
40/// to rescue the instance. If you omit an image reference, the base image
41/// reference is used by default.
42///
43/// **Asynchronous Postconditions**
44///
45/// After you successfully rescue a server and make a
46/// `GET /servers/​{server_id}​` request, its status changes to `RESCUE`.
47///
48/// Normal response codes: 200
49///
50/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
51/// itemNotFound(404), conflict(409), notImplemented(501)
52#[derive(Args)]
53#[command(about = "Rescue Server (rescue Action)")]
54pub struct ServerCommand {
55    /// Request Query parameters
56    #[command(flatten)]
57    query: QueryParameters,
58
59    /// Path parameters
60    #[command(flatten)]
61    path: PathParameters,
62
63    /// The action to rescue a server.
64    #[command(flatten)]
65    rescue: Option<Rescue>,
66}
67
68/// Query parameters
69#[derive(Args)]
70struct QueryParameters {}
71
72/// Path parameters
73#[derive(Args)]
74struct PathParameters {
75    /// id parameter for /v2.1/servers/{id}/action API
76    #[arg(
77        help_heading = "Path parameters",
78        id = "path_param_id",
79        value_name = "ID"
80    )]
81    id: String,
82}
83/// Rescue Body data
84#[derive(Args, Clone)]
85struct Rescue {
86    #[arg(help_heading = "Body parameters", long)]
87    admin_pass: Option<String>,
88
89    #[arg(help_heading = "Body parameters", long)]
90    rescue_image_ref: Option<String>,
91}
92
93impl ServerCommand {
94    /// Perform command action
95    pub async fn take_action<C: CliArgs>(
96        &self,
97        parsed_args: &C,
98        client: &mut AsyncOpenStack,
99    ) -> Result<(), OpenStackCliError> {
100        info!("Action Server");
101
102        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("rescue"));
103        op.validate_args(parsed_args)?;
104
105        let mut ep_builder = rescue::Request::builder();
106
107        ep_builder.id(&self.path.id);
108
109        // Set body parameters
110        // Set Request.rescue data
111        if let Some(lrescue) = &self.rescue {
112            let mut rescue_builder = rescue::RescueBuilder::default();
113            if let Some(val) = &lrescue.admin_pass {
114                rescue_builder.admin_pass(val);
115            }
116            if let Some(val) = &lrescue.rescue_image_ref {
117                rescue_builder.rescue_image_ref(val);
118            }
119            ep_builder.rescue(
120                rescue_builder
121                    .build()
122                    .wrap_err("error preparing the request data")?,
123            );
124        }
125
126        let ep = ep_builder
127            .build()
128            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
129
130        let data: serde_json::Value = ep.query_async(client).await?;
131
132        op.output_single::<response::rescue::ServerResponse>(data.clone())?;
133        // Show command specific hints
134        op.show_command_hint()?;
135        Ok(())
136    }
137}