Skip to main content

openstack_cli_image/v2/image/
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 Image command
19//!
20//! Wraps invoking of the `v2/images/{image_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::image::v2::image::delete;
32
33/// (Since Image API v2.0) Deletes an image.
34///
35/// You cannot delete images with the `protected` attribute set to `true`
36/// (boolean).
37///
38/// Preconditions
39///
40/// Synchronous Postconditions
41///
42/// Normal response codes: 204
43///
44/// Error response codes: 400, 401, 403, 404, 409
45#[derive(Args)]
46#[command(about = "Delete image")]
47pub struct ImageCommand {
48    /// Request Query parameters
49    #[command(flatten)]
50    query: QueryParameters,
51
52    /// Path parameters
53    #[command(flatten)]
54    path: PathParameters,
55}
56
57/// Query parameters
58#[derive(Args)]
59struct QueryParameters {}
60
61/// Path parameters
62#[derive(Args)]
63struct PathParameters {
64    /// image_id parameter for /v2/images/{image_id} API
65    #[arg(
66        help_heading = "Path parameters",
67        id = "path_param_id",
68        value_name = "ID"
69    )]
70    id: String,
71}
72
73impl ImageCommand {
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 Image");
81
82        let op = OutputProcessor::from_args(parsed_args, Some("image.image"), Some("delete"));
83        op.validate_args(parsed_args)?;
84
85        let mut ep_builder = delete::Request::builder();
86
87        ep_builder.id(&self.path.id);
88
89        let ep = ep_builder
90            .build()
91            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
92        openstack_sdk::api::ignore(ep).query_async(client).await?;
93        // Show command specific hints
94        op.show_command_hint()?;
95        Ok(())
96    }
97}