Skip to main content

openstack_cli_compute/v2/server/
revert_resize.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::revert_resize;
32use serde_json::Value;
33
34/// Cancels and reverts a pending resize action for a server.
35///
36/// Specify the `revertResize` action in the request body.
37///
38/// **Preconditions**
39///
40/// You can only revert the resized server where the status is `VERIFY_RESIZE`
41/// and the OS-EXT-STS:vm_state is `resized`.
42///
43/// If the server is locked, you must have administrator privileges to revert
44/// the resizing.
45///
46/// **Asynchronous Postconditions**
47///
48/// After you make this request, you typically must keep polling the server
49/// status to determine whether the request succeeded. A reverting resize
50/// operation shows a status of `REVERT_RESIZE` and a task_state of
51/// `resize_reverting`. If successful, the status will return to `ACTIVE` or
52/// `SHUTOFF`. You can also see the reverted server in the compute node that
53/// OpenStack Compute manages.
54///
55/// **Troubleshooting**
56///
57/// If the server status remains `VERIFY_RESIZE`, the request failed. Ensure
58/// you meet the preconditions and run the request again. If the request fails
59/// again, investigate the compute back end.
60///
61/// The server is not reverted in the compute node that OpenStack Compute
62/// manages.
63///
64/// Normal response codes: 202
65///
66/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
67/// itemNotFound(404), conflict(409)
68#[derive(Args)]
69#[command(about = "Revert Resized Server (revertResize Action)")]
70pub struct ServerCommand {
71    /// Request Query parameters
72    #[command(flatten)]
73    query: QueryParameters,
74
75    /// Path parameters
76    #[command(flatten)]
77    path: PathParameters,
78
79    /// OpenAPI specifies the field as '{}'.
80    #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
81    revert_resize: Value,
82}
83
84/// Query parameters
85#[derive(Args)]
86struct QueryParameters {}
87
88/// Path parameters
89#[derive(Args)]
90struct PathParameters {
91    /// id parameter for /v2.1/servers/{id}/action API
92    #[arg(
93        help_heading = "Path parameters",
94        id = "path_param_id",
95        value_name = "ID"
96    )]
97    id: String,
98}
99
100impl ServerCommand {
101    /// Perform command action
102    pub async fn take_action<C: CliArgs>(
103        &self,
104        parsed_args: &C,
105        client: &mut AsyncOpenStack,
106    ) -> Result<(), OpenStackCliError> {
107        info!("Action Server");
108
109        let op =
110            OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("revert_resize"));
111        op.validate_args(parsed_args)?;
112
113        let mut ep_builder = revert_resize::Request::builder();
114
115        ep_builder.id(&self.path.id);
116
117        // Set body parameters
118        // Set Request.revert_resize data
119        ep_builder.revert_resize(self.revert_resize.clone());
120
121        let ep = ep_builder
122            .build()
123            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
124        openstack_sdk::api::ignore(ep).query_async(client).await?;
125        // Show command specific hints
126        op.show_command_hint()?;
127        Ok(())
128    }
129}