openstack_cli_compute/v2/server/shelve_offload.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_offload;
32use serde_json::Value;
33
34/// Shelf-offloads, or removes, a shelved server.
35///
36/// Specify the `shelveOffload` action in the request body.
37///
38/// Data and resource associations are deleted. If an instance is no longer
39/// needed, you can remove that instance from the hypervisor to minimize
40/// resource usage.
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 `SHELVED`.
49///
50/// If the server is locked, you must have administrator privileges to
51/// shelve-offload the server.
52///
53/// **Asynchronous Postconditions**
54///
55/// After you successfully shelve-offload a server, its status changes to
56/// `SHELVED_OFFLOADED`. The server instance data appears on the compute node.
57///
58/// **Troubleshooting**
59///
60/// If the server status does not change to `SHELVED_OFFLOADED`, the
61/// shelve-offload operation failed. Ensure that you meet the preconditions and
62/// run the request again. If the request fails again, investigate whether
63/// another operation is running that causes a race condition.
64///
65/// Normal response codes: 202
66///
67/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
68/// conflict(409)
69#[derive(Args)]
70#[command(about = "Shelf-Offload (Remove) Server (shelveOffload Action)")]
71pub struct ServerCommand {
72 /// Request Query parameters
73 #[command(flatten)]
74 query: QueryParameters,
75
76 /// Path parameters
77 #[command(flatten)]
78 path: PathParameters,
79
80 /// OpenAPI specifies the field as '{}'.
81 #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
82 shelve_offload: Value,
83}
84
85/// Query parameters
86#[derive(Args)]
87struct QueryParameters {}
88
89/// Path parameters
90#[derive(Args)]
91struct PathParameters {
92 /// id parameter for /v2.1/servers/{id}/action API
93 #[arg(
94 help_heading = "Path parameters",
95 id = "path_param_id",
96 value_name = "ID"
97 )]
98 id: String,
99}
100
101impl ServerCommand {
102 /// Perform command action
103 pub async fn take_action<C: CliArgs>(
104 &self,
105 parsed_args: &C,
106 client: &mut AsyncOpenStack,
107 ) -> Result<(), OpenStackCliError> {
108 info!("Action Server");
109
110 let op =
111 OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("shelve_offload"));
112 op.validate_args(parsed_args)?;
113
114 let mut ep_builder = shelve_offload::Request::builder();
115
116 ep_builder.id(&self.path.id);
117
118 // Set body parameters
119 // Set Request.shelve_offload data
120 ep_builder.shelve_offload(self.shelve_offload.clone());
121
122 let ep = ep_builder
123 .build()
124 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
125 openstack_sdk::api::ignore(ep).query_async(client).await?;
126 // Show command specific hints
127 op.show_command_hint()?;
128 Ok(())
129 }
130}