Skip to main content

openstack_cli_load_balancer/v2/availability_zone_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 AvailabilityZoneProfile command
19//!
20//! Wraps invoking of the `v2/lbaas/availabilityzoneprofiles` 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::availability_zone_profile::create;
33use openstack_types::load_balancer::v2::availability_zone_profile::response;
34
35/// Creates an Availability Zone Profile.
36#[derive(Args)]
37pub struct AvailabilityZoneProfileCommand {
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    availability_zone_profile: AvailabilityZoneProfile,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Path parameters
56#[derive(Args)]
57struct PathParameters {}
58/// AvailabilityZoneProfile Body data
59#[derive(Args, Clone)]
60struct AvailabilityZoneProfile {
61    #[arg(help_heading = "Body parameters", long)]
62    availability_zone_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 AvailabilityZoneProfileCommand {
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 AvailabilityZoneProfile");
79
80        let op = OutputProcessor::from_args(
81            parsed_args,
82            Some("load-balancer.availability_zone_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.availability_zone_profile data
91        let args = &self.availability_zone_profile;
92        let mut availability_zone_profile_builder =
93            create::AvailabilityZoneProfileBuilder::default();
94
95        availability_zone_profile_builder.availability_zone_data(&args.availability_zone_data);
96
97        availability_zone_profile_builder.name(&args.name);
98
99        availability_zone_profile_builder.provider_name(&args.provider_name);
100
101        ep_builder.availability_zone_profile(
102            availability_zone_profile_builder
103                .build()
104                .wrap_err("error preparing the request data")?,
105        );
106
107        let ep = ep_builder
108            .build()
109            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
110
111        let data: serde_json::Value = ep.query_async(client).await?;
112
113        op.output_single::<response::create::AvailabilityZoneProfileResponse>(data.clone())?;
114        // Show command specific hints
115        op.show_command_hint()?;
116        Ok(())
117    }
118}