openstack_cli_compute/v2/server/evacuate_268.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 [microversion = 2.68]
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::evacuate_268;
33use openstack_types::compute::v2::server::response;
34
35/// Command without description in OpenAPI
36#[derive(Args)]
37#[command(about = "Evacuate Server (evacuate Action) (microversion = 2.68)")]
38pub struct ServerCommand {
39 /// Request Query parameters
40 #[command(flatten)]
41 query: QueryParameters,
42
43 /// Path parameters
44 #[command(flatten)]
45 path: PathParameters,
46
47 /// The action to evacuate a server to another host.
48 #[command(flatten)]
49 evacuate: Evacuate,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {}
55
56/// Path parameters
57#[derive(Args)]
58struct PathParameters {
59 /// id parameter for /v2.1/servers/{id}/action API
60 #[arg(
61 help_heading = "Path parameters",
62 id = "path_param_id",
63 value_name = "ID"
64 )]
65 id: String,
66}
67/// Evacuate Body data
68#[derive(Args, Clone)]
69struct Evacuate {
70 /// An administrative password to access the evacuated server. If you omit
71 /// this parameter, the operation generates a new password. Up to API
72 /// version 2.13, if `onSharedStorage` is set to `True` and this parameter
73 /// is specified, an error is raised.
74 #[arg(help_heading = "Body parameters", long)]
75 admin_pass: Option<String>,
76
77 /// The name or ID of the host to which the server is evacuated. If you
78 /// omit this parameter, the scheduler chooses a host.
79 ///
80 /// Warning
81 ///
82 /// Prior to microversion 2.29, specifying a host will bypass validation by
83 /// the scheduler, which could result in failures to actually evacuate the
84 /// instance to the specified host, or over-subscription of the host. It is
85 /// recommended to either not specify a host so that the scheduler will
86 /// pick one, or specify a host with microversion >= 2.29 and without
87 /// `force=True` set.
88 #[arg(help_heading = "Body parameters", long)]
89 host: Option<String>,
90}
91
92impl ServerCommand {
93 /// Perform command action
94 pub async fn take_action<C: CliArgs>(
95 &self,
96 parsed_args: &C,
97 client: &mut AsyncOpenStack,
98 ) -> Result<(), OpenStackCliError> {
99 info!("Action Server");
100
101 let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("evacuate"));
102 op.validate_args(parsed_args)?;
103
104 let mut ep_builder = evacuate_268::Request::builder();
105 ep_builder.header(
106 http::header::HeaderName::from_static("openstack-api-version"),
107 http::header::HeaderValue::from_static("compute 2.68"),
108 );
109
110 ep_builder.id(&self.path.id);
111
112 // Set body parameters
113 // Set Request.evacuate data
114 let args = &self.evacuate;
115 let mut evacuate_builder = evacuate_268::EvacuateBuilder::default();
116 if let Some(val) = &args.admin_pass {
117 evacuate_builder.admin_pass(val);
118 }
119
120 if let Some(val) = &args.host {
121 evacuate_builder.host(val);
122 }
123
124 ep_builder.evacuate(
125 evacuate_builder
126 .build()
127 .wrap_err("error preparing the request data")?,
128 );
129
130 let ep = ep_builder
131 .build()
132 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
133
134 let data: serde_json::Value = ep.query_async(client).await?;
135
136 op.output_single::<response::evacuate::ServerResponse>(data.clone())?;
137 // Show command specific hints
138 op.show_command_hint()?;
139 Ok(())
140 }
141}