Skip to main content

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