Skip to main content

openstack_cli_compute/v2/server/
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 Server command
19//!
20//! Wraps invoking of the `v2.1/servers/{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::compute::v2::server::delete;
32
33/// Deletes a server.
34///
35/// By default, the instance is going to be (hard) deleted immediately from the
36/// system, but you can set `reclaim_instance_interval` > 0 to make the API
37/// soft delete the instance, so that the instance won’t be deleted until the
38/// `reclaim_instance_interval` has expired since the instance was soft
39/// deleted. The instance marked as `SOFT_DELETED` can be recovered via
40/// `restore` action before it’s really deleted from the system.
41///
42/// **Preconditions**
43///
44/// **Asynchronous postconditions**
45///
46/// **Troubleshooting**
47///
48/// Normal response codes: 204
49///
50/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
51/// conflict(409)
52#[derive(Args)]
53#[command(about = "Delete Server")]
54pub struct ServerCommand {
55    /// Request Query parameters
56    #[command(flatten)]
57    query: QueryParameters,
58
59    /// Path parameters
60    #[command(flatten)]
61    path: PathParameters,
62}
63
64/// Query parameters
65#[derive(Args)]
66struct QueryParameters {}
67
68/// Path parameters
69#[derive(Args)]
70struct PathParameters {
71    /// id parameter for /v2.1/servers/{id} API
72    #[arg(
73        help_heading = "Path parameters",
74        id = "path_param_id",
75        value_name = "ID"
76    )]
77    id: 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!("Delete Server");
88
89        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("delete"));
90        op.validate_args(parsed_args)?;
91
92        let mut ep_builder = delete::Request::builder();
93
94        ep_builder.id(&self.path.id);
95
96        let ep = ep_builder
97            .build()
98            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
99        openstack_sdk::api::ignore(ep).query_async(client).await?;
100        // Show command specific hints
101        op.show_command_hint()?;
102        Ok(())
103    }
104}