Skip to main content

openstack_cli_compute/v2/flavor/
add_tenant_access.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//! Action Flavor command
19//!
20//! Wraps invoking of the `v2.1/flavors/{id}/action` with `POST` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::flavor::add_tenant_access;
33use openstack_types::compute::v2::flavor::response;
34
35/// Adds flavor access to a tenant and flavor.
36///
37/// Specify the `addTenantAccess` action and the `tenant` in the request body.
38///
39/// Normal response codes: 200
40///
41/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
42/// itemNotFound(404), conflict(409)
43#[derive(Args)]
44#[command(about = "Add Flavor Access To Tenant (addTenantAccess Action)")]
45pub struct FlavorCommand {
46    /// Request Query parameters
47    #[command(flatten)]
48    query: QueryParameters,
49
50    /// Path parameters
51    #[command(flatten)]
52    path: PathParameters,
53
54    /// The action.
55    #[command(flatten)]
56    add_tenant_access: AddTenantAccess,
57}
58
59/// Query parameters
60#[derive(Args)]
61struct QueryParameters {}
62
63/// Path parameters
64#[derive(Args)]
65struct PathParameters {
66    /// id parameter for /v2.1/flavors/{id}/action API
67    #[arg(
68        help_heading = "Path parameters",
69        id = "path_param_id",
70        value_name = "ID"
71    )]
72    id: String,
73}
74/// AddTenantAccess Body data
75#[derive(Args, Clone)]
76struct AddTenantAccess {
77    /// The UUID of the tenant in a multi-tenancy cloud.
78    #[arg(help_heading = "Body parameters", long)]
79    tenant: String,
80}
81
82impl FlavorCommand {
83    /// Perform command action
84    pub async fn take_action<C: CliArgs>(
85        &self,
86        parsed_args: &C,
87        client: &mut AsyncOpenStack,
88    ) -> Result<(), OpenStackCliError> {
89        info!("Action Flavor");
90
91        let op = OutputProcessor::from_args(
92            parsed_args,
93            Some("compute.flavor"),
94            Some("add_tenant_access"),
95        );
96        op.validate_args(parsed_args)?;
97
98        let mut ep_builder = add_tenant_access::Request::builder();
99
100        ep_builder.id(&self.path.id);
101
102        // Set body parameters
103        // Set Request.add_tenant_access data
104        let args = &self.add_tenant_access;
105        let mut add_tenant_access_builder = add_tenant_access::AddTenantAccessBuilder::default();
106
107        add_tenant_access_builder.tenant(&args.tenant);
108
109        ep_builder.add_tenant_access(
110            add_tenant_access_builder
111                .build()
112                .wrap_err("error preparing the request data")?,
113        );
114
115        let ep = ep_builder
116            .build()
117            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
118
119        let data: Vec<serde_json::Value> = ep.query_async(client).await?;
120        op.output_list::<response::add_tenant_access::FlavorResponse>(data.clone())?;
121        // Show command specific hints
122        op.show_command_hint()?;
123        Ok(())
124    }
125}