Skip to main content

openstack_cli_compute/v2/server/
shelve.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::shelve;
32use serde_json::Value;
33
34/// Shelves a server.
35///
36/// Specify the `shelve` action in the request body.
37///
38/// All associated data and resources are kept but anything still in memory is
39/// not retained. To restore a shelved instance, use the `unshelve` action. To
40/// remove a shelved instance, use the `shelveOffload` action.
41///
42/// Policy defaults enable only users with the administrative role or the owner
43/// of the server to perform this operation. Cloud providers can change these
44/// permissions through the `policy.yaml` file.
45///
46/// **Preconditions**
47///
48/// The server status must be `ACTIVE`, `SHUTOFF`, `PAUSED`, or `SUSPENDED`.
49///
50/// If the server is locked, you must have administrator privileges to shelve
51/// the server.
52///
53/// **Asynchronous Postconditions**
54///
55/// After you successfully shelve a server, its status changes to `SHELVED` and
56/// the image status is `ACTIVE`. The server instance data appears on the
57/// compute node that the Compute service manages.
58///
59/// If you boot the server from volumes or set the `shelved_offload_time`
60/// option to 0, the Compute service automatically deletes the instance on
61/// compute nodes and changes the server status to `SHELVED_OFFLOADED`.
62///
63/// **Troubleshooting**
64///
65/// If the server status does not change to `SHELVED` or `SHELVED_OFFLOADED`,
66/// the shelve operation failed. Ensure that you meet the preconditions and run
67/// the request again. If the request fails again, investigate whether another
68/// operation is running that causes a race condition.
69///
70/// Normal response codes: 202
71///
72/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
73/// conflict(409)
74#[derive(Args)]
75#[command(about = "Shelve Server (shelve Action)")]
76pub struct ServerCommand {
77    /// Request Query parameters
78    #[command(flatten)]
79    query: QueryParameters,
80
81    /// Path parameters
82    #[command(flatten)]
83    path: PathParameters,
84
85    /// OpenAPI specifies the field as '{}'.
86    #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
87    shelve: Value,
88}
89
90/// Query parameters
91#[derive(Args)]
92struct QueryParameters {}
93
94/// Path parameters
95#[derive(Args)]
96struct PathParameters {
97    /// id parameter for /v2.1/servers/{id}/action API
98    #[arg(
99        help_heading = "Path parameters",
100        id = "path_param_id",
101        value_name = "ID"
102    )]
103    id: String,
104}
105
106impl ServerCommand {
107    /// Perform command action
108    pub async fn take_action<C: CliArgs>(
109        &self,
110        parsed_args: &C,
111        client: &mut AsyncOpenStack,
112    ) -> Result<(), OpenStackCliError> {
113        info!("Action Server");
114
115        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("shelve"));
116        op.validate_args(parsed_args)?;
117
118        let mut ep_builder = shelve::Request::builder();
119
120        ep_builder.id(&self.path.id);
121
122        // Set body parameters
123        // Set Request.shelve data
124        ep_builder.shelve(self.shelve.clone());
125
126        let ep = ep_builder
127            .build()
128            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
129        openstack_sdk::api::ignore(ep).query_async(client).await?;
130        // Show command specific hints
131        op.show_command_hint()?;
132        Ok(())
133    }
134}