openstack_cli_compute/v2/server/os_migrate_live_225.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.25]
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_225;
33
34/// Command without description in OpenAPI
35#[derive(Args)]
36#[command(about = "Live-Migrate Server (os-migrateLive Action) (microversion = 2.25)")]
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 /// The host to which to migrate the server. If this parameter is `None`,
82 /// the scheduler chooses a host.
83 ///
84 /// Warning
85 ///
86 /// Prior to microversion 2.30, specifying a host will bypass validation by
87 /// the scheduler, which could result in failures to actually migrate the
88 /// instance to the specified host, or over-subscription of the host. It is
89 /// recommended to either not specify a host so that the scheduler will
90 /// pick one, or specify a host with microversion >= 2.30 and without
91 /// `force=True` set.
92 #[arg(help_heading = "Body parameters", long)]
93 host: String,
94}
95
96impl ServerCommand {
97 /// Perform command action
98 pub async fn take_action<C: CliArgs>(
99 &self,
100 parsed_args: &C,
101 client: &mut AsyncOpenStack,
102 ) -> Result<(), OpenStackCliError> {
103 info!("Action Server");
104
105 let op = OutputProcessor::from_args(
106 parsed_args,
107 Some("compute.server"),
108 Some("os_migrate_live"),
109 );
110 op.validate_args(parsed_args)?;
111
112 let mut ep_builder = os_migrate_live_225::Request::builder();
113 ep_builder.header(
114 http::header::HeaderName::from_static("openstack-api-version"),
115 http::header::HeaderValue::from_static("compute 2.25"),
116 );
117
118 ep_builder.id(&self.path.id);
119
120 // Set body parameters
121 // Set Request.os_migrate_live data
122 let args = &self.os_migrate_live;
123 let mut os_migrate_live_builder = os_migrate_live_225::OsMigrateLiveBuilder::default();
124
125 os_migrate_live_builder.block_migration(args.block_migration);
126
127 os_migrate_live_builder.host(args.host.clone());
128
129 ep_builder.os_migrate_live(
130 os_migrate_live_builder
131 .build()
132 .wrap_err("error preparing the request data")?,
133 );
134
135 let ep = ep_builder
136 .build()
137 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
138 openstack_sdk::api::ignore(ep).query_async(client).await?;
139 // Show command specific hints
140 op.show_command_hint()?;
141 Ok(())
142 }
143}