openstack_cli_compute/v2/server/os_migrate_live_230.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.30]
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::os_migrate_live_230;
33
34/// Command without description in OpenAPI
35#[derive(Args)]
36#[command(about = "Live-Migrate Server (os-migrateLive Action) (microversion = 2.30)")]
37pub struct ServerCommand {
38 /// Request Query parameters
39 #[command(flatten)]
40 query: QueryParameters,
41
42 /// Path parameters
43 #[command(flatten)]
44 path: PathParameters,
45
46 /// The action.
47 #[command(flatten)]
48 os_migrate_live: OsMigrateLive,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Path parameters
56#[derive(Args)]
57struct PathParameters {
58 /// id parameter for /v2.1/servers/{id}/action API
59 #[arg(
60 help_heading = "Path parameters",
61 id = "path_param_id",
62 value_name = "ID"
63 )]
64 id: String,
65}
66/// OsMigrateLive Body data
67#[derive(Args, Clone)]
68struct OsMigrateLive {
69 /// Migrates local disks by using block migration. Set to `auto` which
70 /// means nova will detect whether source and destination hosts on shared
71 /// storage. if they are on shared storage, the live-migration won’t be
72 /// block migration. Otherwise the block migration will be executed. Set to
73 /// `True`, means the request will fail when the source or destination host
74 /// uses shared storage. Set to `False` means the request will fail when
75 /// the source and destination hosts are not on the shared storage.
76 ///
77 /// **New in version 2.25**
78 #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
79 block_migration: bool,
80
81 /// Force a live-migration by not verifying the provided destination host
82 /// by the scheduler.
83 ///
84 /// Warning
85 ///
86 /// This could result in failures to actually live migrate the instance to
87 /// the specified host. It is recommended to either not specify a host so
88 /// that the scheduler will pick one, or specify a host without
89 /// `force=True` set.
90 ///
91 /// **New in version 2.30**
92 ///
93 /// **Available until version 2.67**
94 #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
95 force: Option<bool>,
96
97 /// The host to which to migrate the server. If this parameter is `None`,
98 /// the scheduler chooses a host.
99 ///
100 /// Warning
101 ///
102 /// Prior to microversion 2.30, specifying a host will bypass validation by
103 /// the scheduler, which could result in failures to actually migrate the
104 /// instance to the specified host, or over-subscription of the host. It is
105 /// recommended to either not specify a host so that the scheduler will
106 /// pick one, or specify a host with microversion >= 2.30 and without
107 /// `force=True` set.
108 #[arg(help_heading = "Body parameters", long)]
109 host: String,
110}
111
112impl ServerCommand {
113 /// Perform command action
114 pub async fn take_action<C: CliArgs>(
115 &self,
116 parsed_args: &C,
117 client: &mut AsyncOpenStack,
118 ) -> Result<(), OpenStackCliError> {
119 info!("Action Server");
120
121 let op = OutputProcessor::from_args(
122 parsed_args,
123 Some("compute.server"),
124 Some("os_migrate_live"),
125 );
126 op.validate_args(parsed_args)?;
127
128 let mut ep_builder = os_migrate_live_230::Request::builder();
129 ep_builder.header(
130 http::header::HeaderName::from_static("openstack-api-version"),
131 http::header::HeaderValue::from_static("compute 2.30"),
132 );
133
134 ep_builder.id(&self.path.id);
135
136 // Set body parameters
137 // Set Request.os_migrate_live data
138 let args = &self.os_migrate_live;
139 let mut os_migrate_live_builder = os_migrate_live_230::OsMigrateLiveBuilder::default();
140
141 os_migrate_live_builder.block_migration(args.block_migration);
142
143 if let Some(val) = &args.force {
144 os_migrate_live_builder.force(*val);
145 }
146
147 os_migrate_live_builder.host(args.host.clone());
148
149 ep_builder.os_migrate_live(
150 os_migrate_live_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 openstack_sdk::api::ignore(ep).query_async(client).await?;
159 // Show command specific hints
160 op.show_command_hint()?;
161 Ok(())
162 }
163}