Skip to main content

openstack_cli_load_balancer/v2/availability_zone/
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 AvailabilityZone command
19//!
20//! Wraps invoking of the `v2/lbaas/availabilityzones` 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::create;
33use openstack_types::load_balancer::v2::availability_zone::response;
34
35/// Creates an Availability Zone.
36#[derive(Args)]
37pub struct AvailabilityZoneCommand {
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: AvailabilityZone,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Path parameters
56#[derive(Args)]
57struct PathParameters {}
58/// AvailabilityZone Body data
59#[derive(Args, Clone)]
60struct AvailabilityZone {
61    #[arg(help_heading = "Body parameters", long)]
62    availability_zone_profile_id: String,
63
64    #[arg(help_heading = "Body parameters", long)]
65    description: Option<String>,
66
67    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
68    enabled: Option<bool>,
69
70    #[arg(help_heading = "Body parameters", long)]
71    name: String,
72}
73
74impl AvailabilityZoneCommand {
75    /// Perform command action
76    pub async fn take_action<C: CliArgs>(
77        &self,
78        parsed_args: &C,
79        client: &mut AsyncOpenStack,
80    ) -> Result<(), OpenStackCliError> {
81        info!("Create AvailabilityZone");
82
83        let op = OutputProcessor::from_args(
84            parsed_args,
85            Some("load-balancer.availability_zone"),
86            Some("create"),
87        );
88        op.validate_args(parsed_args)?;
89
90        let mut ep_builder = create::Request::builder();
91
92        // Set body parameters
93        // Set Request.availability_zone data
94        let args = &self.availability_zone;
95        let mut availability_zone_builder = create::AvailabilityZoneBuilder::default();
96
97        availability_zone_builder.availability_zone_profile_id(&args.availability_zone_profile_id);
98
99        if let Some(val) = &args.description {
100            availability_zone_builder.description(val);
101        }
102
103        if let Some(val) = &args.enabled {
104            availability_zone_builder.enabled(*val);
105        }
106
107        availability_zone_builder.name(&args.name);
108
109        ep_builder.availability_zone(
110            availability_zone_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: serde_json::Value = ep.query_async(client).await?;
120
121        op.output_single::<response::create::AvailabilityZoneResponse>(data.clone())?;
122        // Show command specific hints
123        op.show_command_hint()?;
124        Ok(())
125    }
126}