openstack_cli_load_balancer/v2/loadbalancer/delete.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//! Delete Loadbalancer command
19//!
20//! Wraps invoking of the `v2/lbaas/loadbalancers/{loadbalancer_id}` with `DELETE` method
21
22use clap::Args;
23use tracing::info;
24
25use openstack_cli_core::cli::CliArgs;
26use openstack_cli_core::error::OpenStackCliError;
27use openstack_cli_core::output::OutputProcessor;
28use openstack_sdk::AsyncOpenStack;
29
30use openstack_sdk::api::QueryAsync;
31use openstack_sdk::api::load_balancer::v2::loadbalancer::delete;
32
33/// Removes a load balancer and its associated configuration from the project.
34///
35/// The optional parameter `cascade` when defined as `true` will delete all
36/// child objects of the load balancer.
37///
38/// The API immediately purges any and all configuration data, depending on the
39/// configuration settings. You cannot recover it.
40#[derive(Args)]
41#[command(about = "Remove a Load Balancer")]
42pub struct LoadbalancerCommand {
43 /// Request Query parameters
44 #[command(flatten)]
45 query: QueryParameters,
46
47 /// Path parameters
48 #[command(flatten)]
49 path: PathParameters,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {
55 /// If true will delete all child objects of the load balancer.
56 #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
57 cascade: Option<bool>,
58}
59
60/// Path parameters
61#[derive(Args)]
62struct PathParameters {
63 /// loadbalancer_id parameter for /v2/lbaas/loadbalancers/{loadbalancer_id}
64 /// API
65 #[arg(
66 help_heading = "Path parameters",
67 id = "path_param_id",
68 value_name = "ID"
69 )]
70 id: String,
71}
72
73impl LoadbalancerCommand {
74 /// Perform command action
75 pub async fn take_action<C: CliArgs>(
76 &self,
77 parsed_args: &C,
78 client: &mut AsyncOpenStack,
79 ) -> Result<(), OpenStackCliError> {
80 info!("Delete Loadbalancer");
81
82 let op = OutputProcessor::from_args(
83 parsed_args,
84 Some("load-balancer.loadbalancer"),
85 Some("delete"),
86 );
87 op.validate_args(parsed_args)?;
88
89 let mut ep_builder = delete::Request::builder();
90
91 ep_builder.id(&self.path.id);
92 // Set query parameters
93 if let Some(val) = &self.query.cascade {
94 ep_builder.cascade(*val);
95 }
96
97 let ep = ep_builder
98 .build()
99 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
100 openstack_sdk::api::ignore(ep).query_async(client).await?;
101 // Show command specific hints
102 op.show_command_hint()?;
103 Ok(())
104 }
105}