Skip to main content

openstack_cli_compute/v2/aggregate/
remove_host.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 Aggregate command
19//!
20//! Wraps invoking of the `v2.1/os-aggregates/{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::aggregate::remove_host;
33use openstack_types::compute::v2::aggregate::response;
34
35/// Command without description in OpenAPI
36#[derive(Args)]
37pub struct AggregateCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    #[command(flatten)]
47    remove_host: RemoveHost,
48}
49
50/// Query parameters
51#[derive(Args)]
52struct QueryParameters {}
53
54/// Path parameters
55#[derive(Args)]
56struct PathParameters {
57    /// id parameter for /v2.1/os-aggregates/{id}/action API
58    #[arg(
59        help_heading = "Path parameters",
60        id = "path_param_id",
61        value_name = "ID"
62    )]
63    id: String,
64}
65/// RemoveHost Body data
66#[derive(Args, Clone)]
67struct RemoveHost {
68    #[arg(help_heading = "Body parameters", long)]
69    host: String,
70}
71
72impl AggregateCommand {
73    /// Perform command action
74    pub async fn take_action<C: CliArgs>(
75        &self,
76        parsed_args: &C,
77        client: &mut AsyncOpenStack,
78    ) -> Result<(), OpenStackCliError> {
79        info!("Action Aggregate");
80
81        let op =
82            OutputProcessor::from_args(parsed_args, Some("compute.aggregate"), Some("remove_host"));
83        op.validate_args(parsed_args)?;
84
85        let mut ep_builder = remove_host::Request::builder();
86
87        ep_builder.id(&self.path.id);
88
89        // Set body parameters
90        // Set Request.remove_host data
91        let args = &self.remove_host;
92        let mut remove_host_builder = remove_host::RemoveHostBuilder::default();
93
94        remove_host_builder.host(&args.host);
95
96        ep_builder.remove_host(
97            remove_host_builder
98                .build()
99                .wrap_err("error preparing the request data")?,
100        );
101
102        let ep = ep_builder
103            .build()
104            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
105
106        let data: serde_json::Value = ep.query_async(client).await?;
107
108        op.output_single::<response::remove_host_21::AggregateResponse>(data.clone())
109            .or_else(|_| {
110                op.output_single::<response::remove_host_241::AggregateResponse>(data.clone())
111            })?;
112        // Show command specific hints
113        op.show_command_hint()?;
114        Ok(())
115    }
116}