Skip to main content

openstack_cli_compute/v2/server/
restore.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::restore;
32use serde_json::Value;
33
34/// Restores a previously soft-deleted server instance. You cannot use this
35/// method to restore deleted instances.
36///
37/// Specify the `restore` action in the request body.
38///
39/// Policy defaults enable only users with the administrative role or the owner
40/// of the server to perform this operation. Cloud providers can change these
41/// permissions through the `policy.yaml` 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 = "Restore Soft-Deleted Instance (restore 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    /// OpenAPI specifies the field as '{}'.
59    #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
60    restore: Value,
61}
62
63/// Query parameters
64#[derive(Args)]
65struct QueryParameters {}
66
67/// Path parameters
68#[derive(Args)]
69struct PathParameters {
70    /// id parameter for /v2.1/servers/{id}/action API
71    #[arg(
72        help_heading = "Path parameters",
73        id = "path_param_id",
74        value_name = "ID"
75    )]
76    id: String,
77}
78
79impl ServerCommand {
80    /// Perform command action
81    pub async fn take_action<C: CliArgs>(
82        &self,
83        parsed_args: &C,
84        client: &mut AsyncOpenStack,
85    ) -> Result<(), OpenStackCliError> {
86        info!("Action Server");
87
88        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("restore"));
89        op.validate_args(parsed_args)?;
90
91        let mut ep_builder = restore::Request::builder();
92
93        ep_builder.id(&self.path.id);
94
95        // Set body parameters
96        // Set Request.restore data
97        ep_builder.restore(self.restore.clone());
98
99        let ep = ep_builder
100            .build()
101            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
102        openstack_sdk::api::ignore(ep).query_async(client).await?;
103        // Show command specific hints
104        op.show_command_hint()?;
105        Ok(())
106    }
107}