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