Skip to main content

openstack_cli_compute/
v2.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//! Compute API v2 command
16
17use clap::{Parser, Subcommand};
18
19use openstack_cli_core::{cli::CliArgs, error::OpenStackCliError};
20use openstack_sdk::{AsyncOpenStack, types::ServiceType};
21
22pub mod aggregate;
23pub mod assisted_volume_snapshot;
24pub mod availability_zone;
25pub mod extension;
26pub mod flavor;
27pub mod hypervisor;
28pub mod instance_usage_audit_log;
29pub mod keypair;
30pub mod limit;
31pub mod migration;
32pub mod quota_class_set;
33pub mod quota_set;
34pub mod server;
35pub mod server_external_event;
36pub mod server_group;
37pub mod service;
38pub mod simple_tenant_usage;
39
40/// Compute service (Nova) operations
41#[derive(Parser)]
42pub struct ComputeCommand {
43    /// Compute service resource
44    #[command(subcommand)]
45    command: ComputeCommands,
46}
47
48/// Compute resources commands
49#[allow(missing_docs)]
50#[derive(Subcommand)]
51pub enum ComputeCommands {
52    #[command(about = "Host Aggregates")]
53    Aggregate(Box<aggregate::AggregateCommand>),
54    AssistedVolumeSnapshot(Box<assisted_volume_snapshot::AssistedVolumeSnapshotCommand>),
55    AvailabilityZone(Box<availability_zone::AvailabilityZoneCommand>),
56    Extension(Box<extension::ExtensionCommand>),
57    Flavor(Box<flavor::FlavorCommand>),
58    Hypervisor(Box<hypervisor::HypervisorCommand>),
59    InstanceUsageAuditLog(Box<instance_usage_audit_log::InstanceUsageAuditLogCommand>),
60    Keypair(Box<keypair::KeypairCommand>),
61    Limit(Box<limit::LimitCommand>),
62    Migration(Box<migration::MigrationCommand>),
63    QuotaClassSet(Box<quota_class_set::QuotaClassSetCommand>),
64    QuotaSet(Box<quota_set::QuotaSetCommand>),
65    Server(Box<server::ServerCommand>),
66    ServerExternalEvent(Box<server_external_event::ServerExternalEventCommand>),
67    ServerGroup(Box<server_group::ServerGroupCommand>),
68    Service(Box<service::ServiceCommand>),
69    #[command(visible_alias = "usage")]
70    SimpleTenantUsage(Box<simple_tenant_usage::SimpleTenantUsageCommand>),
71}
72
73impl ComputeCommand {
74    /// Perform command action
75    pub async fn take_action<C: CliArgs>(
76        &self,
77        parsed_args: &C,
78        session: &mut AsyncOpenStack,
79    ) -> Result<(), OpenStackCliError> {
80        session
81            .discover_service_endpoint(&ServiceType::Compute)
82            .await?;
83
84        match &self.command {
85            ComputeCommands::Aggregate(cmd) => cmd.take_action(parsed_args, session).await,
86            ComputeCommands::AssistedVolumeSnapshot(cmd) => {
87                cmd.take_action(parsed_args, session).await
88            }
89            ComputeCommands::AvailabilityZone(cmd) => cmd.take_action(parsed_args, session).await,
90            ComputeCommands::Extension(cmd) => cmd.take_action(parsed_args, session).await,
91            ComputeCommands::Hypervisor(cmd) => cmd.take_action(parsed_args, session).await,
92            ComputeCommands::InstanceUsageAuditLog(cmd) => {
93                cmd.take_action(parsed_args, session).await
94            }
95            ComputeCommands::Flavor(cmd) => cmd.take_action(parsed_args, session).await,
96            ComputeCommands::Keypair(cmd) => cmd.take_action(parsed_args, session).await,
97            ComputeCommands::Limit(cmd) => cmd.take_action(parsed_args, session).await,
98            ComputeCommands::Migration(cmd) => cmd.take_action(parsed_args, session).await,
99            ComputeCommands::QuotaClassSet(cmd) => cmd.take_action(parsed_args, session).await,
100            ComputeCommands::QuotaSet(cmd) => cmd.take_action(parsed_args, session).await,
101            ComputeCommands::Server(cmd) => cmd.take_action(parsed_args, session).await,
102            ComputeCommands::ServerExternalEvent(cmd) => {
103                cmd.take_action(parsed_args, session).await
104            }
105            ComputeCommands::ServerGroup(cmd) => cmd.take_action(parsed_args, session).await,
106            ComputeCommands::Service(cmd) => cmd.take_action(parsed_args, session).await,
107            ComputeCommands::SimpleTenantUsage(cmd) => cmd.take_action(parsed_args, session).await,
108        }
109    }
110}