Skip to main content

openstack_cli_compute/v2/server/
unshelve_291.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.91]
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::unshelve_291;
33
34/// Command without description in OpenAPI
35#[derive(Args)]
36#[command(about = "Unshelve (Restore) Shelved Server (unshelve Action) (microversion = 2.91)")]
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    unshelve: Option<Unshelve>,
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/// Unshelve Body data
67#[derive(Args, Clone)]
68struct Unshelve {
69    #[arg(help_heading = "Body parameters", long)]
70    availability_zone: Option<String>,
71
72    /// Set explicit NULL for the availability_zone
73    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "availability_zone")]
74    no_availability_zone: bool,
75
76    #[arg(help_heading = "Body parameters", long)]
77    host: Option<String>,
78}
79
80impl ServerCommand {
81    /// Perform command action
82    pub async fn take_action<C: CliArgs>(
83        &self,
84        parsed_args: &C,
85        client: &mut AsyncOpenStack,
86    ) -> Result<(), OpenStackCliError> {
87        info!("Action Server");
88
89        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("unshelve"));
90        op.validate_args(parsed_args)?;
91
92        let mut ep_builder = unshelve_291::Request::builder();
93        ep_builder.header(
94            http::header::HeaderName::from_static("openstack-api-version"),
95            http::header::HeaderValue::from_static("compute 2.91"),
96        );
97
98        ep_builder.id(&self.path.id);
99
100        // Set body parameters
101        // Set Request.unshelve data
102        if let Some(lunshelve) = &self.unshelve {
103            let mut unshelve_builder = unshelve_291::UnshelveBuilder::default();
104            if let Some(val) = &lunshelve.availability_zone {
105                unshelve_builder.availability_zone(Some(val.into()));
106            }
107            if let Some(val) = &lunshelve.host {
108                unshelve_builder.host(val);
109            }
110            ep_builder.unshelve(
111                unshelve_builder
112                    .build()
113                    .wrap_err("error preparing the request data")?,
114            );
115        }
116
117        let ep = ep_builder
118            .build()
119            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
120        openstack_sdk::api::ignore(ep).query_async(client).await?;
121        // Show command specific hints
122        op.show_command_hint()?;
123        Ok(())
124    }
125}