Skip to main content

openstack_cli_image/v2/
image.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//! Glance `Image` resource commands
16
17use clap::{Parser, Subcommand};
18
19use openstack_sdk::AsyncOpenStack;
20
21use openstack_cli_core::{cli::CliArgs, error::OpenStackCliError};
22
23pub mod create;
24pub mod deactivate;
25pub mod delete;
26/// Image data operations
27pub mod file {
28    pub mod download;
29    pub mod upload;
30}
31pub mod list;
32pub mod patch;
33pub mod reactivate;
34pub mod show;
35
36/// Image (Glance) commands
37#[derive(Parser)]
38pub struct ImageCommand {
39    /// subcommand
40    #[command(subcommand)]
41    command: ImageCommands,
42}
43
44/// Supported subcommands
45#[allow(missing_docs)]
46#[derive(Subcommand)]
47pub enum ImageCommands {
48    Create(create::ImageCommand),
49    /// Deactivates an image. (Since Image API v2.3)
50    ///
51    /// By default, this operation is restricted to administrators only.
52    #[command(about = "Deactivate image")]
53    Deactivate(deactivate::ImageCommand),
54    Delete(delete::ImageCommand),
55    Download(Box<file::download::FileCommand>),
56    List(Box<list::ImagesCommand>),
57    /// Reactivates an image. (Since Image API v2.3)
58    ///
59    /// By default, this operation is restricted to administrators only
60    #[command(about = "Reactivate image")]
61    Reactivate(reactivate::ImageCommand),
62    Set(patch::ImageCommand),
63    Show(show::ImageCommand),
64    Upload(file::upload::FileCommand),
65}
66
67impl ImageCommand {
68    /// Perform command action
69    pub async fn take_action<C: CliArgs>(
70        &self,
71        parsed_args: &C,
72        session: &mut AsyncOpenStack,
73    ) -> Result<(), OpenStackCliError> {
74        match &self.command {
75            ImageCommands::Create(cmd) => cmd.take_action(parsed_args, session).await,
76            ImageCommands::Deactivate(cmd) => cmd.take_action(parsed_args, session).await,
77            ImageCommands::Delete(cmd) => cmd.take_action(parsed_args, session).await,
78            ImageCommands::Download(cmd) => cmd.take_action(parsed_args, session).await,
79            ImageCommands::List(cmd) => cmd.take_action(parsed_args, session).await,
80            ImageCommands::Reactivate(cmd) => cmd.take_action(parsed_args, session).await,
81            ImageCommands::Set(cmd) => cmd.take_action(parsed_args, session).await,
82            ImageCommands::Show(cmd) => cmd.take_action(parsed_args, session).await,
83            ImageCommands::Upload(cmd) => cmd.take_action(parsed_args, session).await,
84        }
85    }
86}