openstack_cli_placement/v1.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//! Placement v1 commands
16
17use clap::{Parser, Subcommand};
18
19use openstack_cli_core::{cli::CliArgs, error::OpenStackCliError};
20use openstack_sdk::{AsyncOpenStack, types::ServiceType};
21
22pub mod allocation;
23pub mod allocation_candidate;
24pub mod reshaper;
25pub mod resource_class;
26pub mod resource_provider;
27pub mod r#trait;
28pub mod usage;
29
30/// The placement API service was introduced in the 14.0.0 Newton release within the nova
31/// repository and extracted to the placement repository in the 19.0.0 Stein release. This is a
32/// REST API stack and data model used to track resource provider inventories and usages, along
33/// with different classes of resources. For example, a resource provider can be a compute node, a
34/// shared storage pool, or an IP allocation pool. The placement service tracks the inventory and
35/// usage of each provider. For example, an instance created on a compute node may be a consumer of
36/// resources such as RAM and CPU from a compute node resource provider, disk from an external
37/// shared storage pool resource provider and IP addresses from an external IP pool resource
38/// provider.
39///
40/// The types of resources consumed are tracked as classes. The service provides a set of standard
41/// resource classes (for example DISK_GB, MEMORY_MB, and VCPU) and provides the ability to define
42/// custom resource classes as needed.
43///
44/// Each resource provider may also have a set of traits which describe qualitative aspects of the
45/// resource provider. Traits describe an aspect of a resource provider that cannot itself be
46/// consumed but a workload may wish to specify. For example, available disk may be solid state
47/// drives (SSD).
48#[derive(Parser)]
49pub struct PlacementCommand {
50 /// Placement service resource
51 #[command(subcommand)]
52 command: PlacementCommands,
53}
54
55/// Supported subcommands
56#[allow(missing_docs)]
57#[derive(Subcommand)]
58pub enum PlacementCommands {
59 Allocation(Box<allocation::AllocationCommand>),
60 AllocationCandidate(Box<allocation_candidate::AllocationCandidateCommand>),
61 Reshaper(Box<reshaper::ReshaperCommand>),
62 ResourceClass(Box<resource_class::ResourceClassCommand>),
63 ResourceProvider(Box<resource_provider::ResourceProviderCommand>),
64 Trait(Box<r#trait::TraitCommand>),
65 Usage(Box<usage::UsageCommand>),
66}
67
68impl PlacementCommand {
69 /// Perform command action
70 pub async fn take_action<C: CliArgs>(
71 &self,
72 parsed_args: &C,
73 session: &mut AsyncOpenStack,
74 ) -> Result<(), OpenStackCliError> {
75 session
76 .discover_service_endpoint(&ServiceType::Placement)
77 .await?;
78
79 match &self.command {
80 PlacementCommands::Allocation(cmd) => cmd.take_action(parsed_args, session).await,
81 PlacementCommands::AllocationCandidate(cmd) => {
82 cmd.take_action(parsed_args, session).await
83 }
84 PlacementCommands::Reshaper(cmd) => cmd.take_action(parsed_args, session).await,
85 PlacementCommands::ResourceClass(cmd) => cmd.take_action(parsed_args, session).await,
86 PlacementCommands::ResourceProvider(cmd) => cmd.take_action(parsed_args, session).await,
87 PlacementCommands::Trait(cmd) => cmd.take_action(parsed_args, session).await,
88 PlacementCommands::Usage(cmd) => cmd.take_action(parsed_args, session).await,
89 }
90 }
91}