Skip to main content

openstack_cli_load_balancer/v2/flavor_profile/
create.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//! Create FlavorProfile command
19//!
20//! Wraps invoking of the `v2/lbaas/flavorprofiles` 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::load_balancer::v2::flavor_profile::create;
33use openstack_types::load_balancer::v2::flavor_profile::response;
34
35/// Creates a flavor Profile.
36#[derive(Args)]
37pub struct FlavorProfileCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// Defines mandatory and optional attributes of a POST request.
47    #[command(flatten)]
48    flavorprofile: Flavorprofile,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Path parameters
56#[derive(Args)]
57struct PathParameters {}
58/// Flavorprofile Body data
59#[derive(Args, Clone)]
60struct Flavorprofile {
61    #[arg(help_heading = "Body parameters", long)]
62    flavor_data: String,
63
64    #[arg(help_heading = "Body parameters", long)]
65    name: String,
66
67    #[arg(help_heading = "Body parameters", long)]
68    provider_name: String,
69}
70
71impl FlavorProfileCommand {
72    /// Perform command action
73    pub async fn take_action<C: CliArgs>(
74        &self,
75        parsed_args: &C,
76        client: &mut AsyncOpenStack,
77    ) -> Result<(), OpenStackCliError> {
78        info!("Create FlavorProfile");
79
80        let op = OutputProcessor::from_args(
81            parsed_args,
82            Some("load-balancer.flavor_profile"),
83            Some("create"),
84        );
85        op.validate_args(parsed_args)?;
86
87        let mut ep_builder = create::Request::builder();
88
89        // Set body parameters
90        // Set Request.flavorprofile data
91        let args = &self.flavorprofile;
92        let mut flavorprofile_builder = create::FlavorprofileBuilder::default();
93
94        flavorprofile_builder.flavor_data(&args.flavor_data);
95
96        flavorprofile_builder.name(&args.name);
97
98        flavorprofile_builder.provider_name(&args.provider_name);
99
100        ep_builder.flavorprofile(
101            flavorprofile_builder
102                .build()
103                .wrap_err("error preparing the request data")?,
104        );
105
106        let ep = ep_builder
107            .build()
108            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
109
110        let data: serde_json::Value = ep.query_async(client).await?;
111
112        op.output_single::<response::create::FlavorProfileResponse>(data.clone())?;
113        // Show command specific hints
114        op.show_command_hint()?;
115        Ok(())
116    }
117}