Skip to main content

openstack_cli_compute/v2/server/
force_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//! Action Server command
19//!
20//! Wraps invoking of the `v2.1/servers/{id}/action` with `POST` 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::force_delete;
32use serde_json::Value;
33
34/// Force-deletes a server before deferred cleanup.
35///
36/// Specify the `forceDelete` action in the request body.
37///
38/// Policy defaults enable only users with the administrative role or the owner
39/// of the server to perform this operation. Cloud providers can change these
40/// permissions through the `policy.yaml` file.
41///
42/// Normal response codes: 202
43///
44/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
45/// conflict(409)
46#[derive(Args)]
47#[command(about = "Force-Delete Server (forceDelete Action)")]
48pub struct ServerCommand {
49    /// Request Query parameters
50    #[command(flatten)]
51    query: QueryParameters,
52
53    /// Path parameters
54    #[command(flatten)]
55    path: PathParameters,
56
57    /// OpenAPI specifies the field as '{}'.
58    #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
59    force_delete: Value,
60}
61
62/// Query parameters
63#[derive(Args)]
64struct QueryParameters {}
65
66/// Path parameters
67#[derive(Args)]
68struct PathParameters {
69    /// id parameter for /v2.1/servers/{id}/action API
70    #[arg(
71        help_heading = "Path parameters",
72        id = "path_param_id",
73        value_name = "ID"
74    )]
75    id: String,
76}
77
78impl ServerCommand {
79    /// Perform command action
80    pub async fn take_action<C: CliArgs>(
81        &self,
82        parsed_args: &C,
83        client: &mut AsyncOpenStack,
84    ) -> Result<(), OpenStackCliError> {
85        info!("Action Server");
86
87        let op =
88            OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("force_delete"));
89        op.validate_args(parsed_args)?;
90
91        let mut ep_builder = force_delete::Request::builder();
92
93        ep_builder.id(&self.path.id);
94
95        // Set body parameters
96        // Set Request.force_delete data
97        ep_builder.force_delete(self.force_delete.clone());
98
99        let ep = ep_builder
100            .build()
101            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
102        openstack_sdk::api::ignore(ep).query_async(client).await?;
103        // Show command specific hints
104        op.show_command_hint()?;
105        Ok(())
106    }
107}