Skip to main content

openstack_cli_compute/v2/server/
migrate_256.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.56]
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::migrate_256;
33
34/// Migrates a server to a host.
35///
36/// Specify the `migrate` action in the request body.
37///
38/// Up to microversion 2.55, the scheduler chooses the host. Starting from
39/// microversion 2.56, the `host` parameter is available to specify the
40/// destination host. If you specify `null` or don’t specify this parameter,
41/// the scheduler chooses a host.
42///
43/// **Asynchronous Postconditions**
44///
45/// A successfully migrated server shows a `VERIFY_RESIZE` status and
46/// `finished` migration status. If the cloud has configured the
47/// [resize_confirm_window](https://docs.openstack.org/nova/latest/configuration/config.html#DEFAULT.resize_confirm_window)
48/// option of the Compute service to a positive value, the Compute service
49/// automatically confirms the migrate operation after the configured interval.
50///
51/// There are two different policies for this action, depending on whether the
52/// host parameter is set. Both defaults enable only users with the
53/// administrative role to perform this operation. Cloud providers can change
54/// these permissions through the `policy.yaml` file.
55///
56/// Normal response codes: 202
57///
58/// Error response codes: badRequest(400), unauthorized(401), forbidden(403)
59/// itemNotFound(404), conflict(409)
60#[derive(Args)]
61#[command(about = "Migrate Server (migrate Action) (microversion = 2.56)")]
62pub struct ServerCommand {
63    /// Request Query parameters
64    #[command(flatten)]
65    query: QueryParameters,
66
67    /// Path parameters
68    #[command(flatten)]
69    path: PathParameters,
70
71    /// The action to cold migrate a server. This parameter can be `null`. Up
72    /// to microversion 2.55, this parameter should be `null`.
73    #[command(flatten)]
74    migrate: Option<Migrate>,
75}
76
77/// Query parameters
78#[derive(Args)]
79struct QueryParameters {}
80
81/// Path parameters
82#[derive(Args)]
83struct PathParameters {
84    /// id parameter for /v2.1/servers/{id}/action API
85    #[arg(
86        help_heading = "Path parameters",
87        id = "path_param_id",
88        value_name = "ID"
89    )]
90    id: String,
91}
92/// Migrate Body data
93#[derive(Args, Clone)]
94struct Migrate {
95    #[arg(help_heading = "Body parameters", long)]
96    host: Option<String>,
97
98    /// Set explicit NULL for the host
99    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "host")]
100    no_host: bool,
101}
102
103impl ServerCommand {
104    /// Perform command action
105    pub async fn take_action<C: CliArgs>(
106        &self,
107        parsed_args: &C,
108        client: &mut AsyncOpenStack,
109    ) -> Result<(), OpenStackCliError> {
110        info!("Action Server");
111
112        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("migrate"));
113        op.validate_args(parsed_args)?;
114
115        let mut ep_builder = migrate_256::Request::builder();
116        ep_builder.header(
117            http::header::HeaderName::from_static("openstack-api-version"),
118            http::header::HeaderValue::from_static("compute 2.56"),
119        );
120
121        ep_builder.id(&self.path.id);
122
123        // Set body parameters
124        // Set Request.migrate data
125        if let Some(lmigrate) = &self.migrate {
126            let mut migrate_builder = migrate_256::MigrateBuilder::default();
127            if let Some(val) = &lmigrate.host {
128                migrate_builder.host(Some(val.into()));
129            }
130            ep_builder.migrate(
131                migrate_builder
132                    .build()
133                    .wrap_err("error preparing the request data")?,
134            );
135        }
136
137        let ep = ep_builder
138            .build()
139            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
140        openstack_sdk::api::ignore(ep).query_async(client).await?;
141        // Show command specific hints
142        op.show_command_hint()?;
143        Ok(())
144    }
145}