Skip to main content

openstack_cli_compute/v2/server/
evacuate_229.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.29]
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_229;
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.29)")]
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    /// Force an evacuation by not verifying the provided destination host by
78    /// the scheduler.
79    ///
80    /// Warning
81    ///
82    /// This could result in failures to actually evacuate the instance to the
83    /// specified host. It is recommended to either not specify a host so that
84    /// the scheduler will pick one, or specify a host without `force=True`
85    /// set.
86    ///
87    /// Furthermore, this should not be specified when evacuating instances
88    /// managed by a clustered hypervisor driver like ironic since you cannot
89    /// specify a node, so the compute service will pick a node randomly which
90    /// may not be able to accommodate the instance.
91    ///
92    /// **New in version 2.29**
93    ///
94    /// **Available until version 2.67**
95    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
96    force: Option<bool>,
97
98    /// The name or ID of the host to which the server is evacuated. If you
99    /// omit this parameter, the scheduler chooses a host.
100    ///
101    /// Warning
102    ///
103    /// Prior to microversion 2.29, specifying a host will bypass validation by
104    /// the scheduler, which could result in failures to actually evacuate the
105    /// instance to the specified host, or over-subscription of the host. It is
106    /// recommended to either not specify a host so that the scheduler will
107    /// pick one, or specify a host with microversion >= 2.29 and without
108    /// `force=True` set.
109    #[arg(help_heading = "Body parameters", long)]
110    host: Option<String>,
111}
112
113impl ServerCommand {
114    /// Perform command action
115    pub async fn take_action<C: CliArgs>(
116        &self,
117        parsed_args: &C,
118        client: &mut AsyncOpenStack,
119    ) -> Result<(), OpenStackCliError> {
120        info!("Action Server");
121
122        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("evacuate"));
123        op.validate_args(parsed_args)?;
124
125        let mut ep_builder = evacuate_229::Request::builder();
126        ep_builder.header(
127            http::header::HeaderName::from_static("openstack-api-version"),
128            http::header::HeaderValue::from_static("compute 2.29"),
129        );
130
131        ep_builder.id(&self.path.id);
132
133        // Set body parameters
134        // Set Request.evacuate data
135        let args = &self.evacuate;
136        let mut evacuate_builder = evacuate_229::EvacuateBuilder::default();
137        if let Some(val) = &args.admin_pass {
138            evacuate_builder.admin_pass(val);
139        }
140
141        if let Some(val) = &args.force {
142            evacuate_builder.force(*val);
143        }
144
145        if let Some(val) = &args.host {
146            evacuate_builder.host(val);
147        }
148
149        ep_builder.evacuate(
150            evacuate_builder
151                .build()
152                .wrap_err("error preparing the request data")?,
153        );
154
155        let ep = ep_builder
156            .build()
157            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
158
159        let data: serde_json::Value = ep.query_async(client).await?;
160
161        op.output_single::<response::evacuate::ServerResponse>(data.clone())?;
162        // Show command specific hints
163        op.show_command_hint()?;
164        Ok(())
165    }
166}