Skip to main content

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