Skip to main content

openstack_cli_load_balancer/v2/availability_zone/
set.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//! Set AvailabilityZone command
19//!
20//! Wraps invoking of the `v2/lbaas/availabilityzones/{availabilityzone_id}` with `PUT` 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::set;
33use openstack_types::load_balancer::v2::availability_zone::response;
34
35/// Command without description in OpenAPI
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 the attributes of a PUT 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_id parameter for
59    /// /v2/lbaas/availabilityzones/{availabilityzone_id} API
60    #[arg(
61        help_heading = "Path parameters",
62        id = "path_param_id",
63        value_name = "ID"
64    )]
65    id: String,
66}
67/// AvailabilityZone Body data
68#[derive(Args, Clone)]
69struct AvailabilityZone {
70    #[arg(help_heading = "Body parameters", long)]
71    description: Option<String>,
72
73    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
74    enabled: Option<bool>,
75}
76
77impl AvailabilityZoneCommand {
78    /// Perform command action
79    pub async fn take_action<C: CliArgs>(
80        &self,
81        parsed_args: &C,
82        client: &mut AsyncOpenStack,
83    ) -> Result<(), OpenStackCliError> {
84        info!("Set AvailabilityZone");
85
86        let op = OutputProcessor::from_args(
87            parsed_args,
88            Some("load-balancer.availability_zone"),
89            Some("set"),
90        );
91        op.validate_args(parsed_args)?;
92
93        let mut ep_builder = set::Request::builder();
94
95        ep_builder.id(&self.path.id);
96
97        // Set body parameters
98        // Set Request.availability_zone data
99        let args = &self.availability_zone;
100        let mut availability_zone_builder = set::AvailabilityZoneBuilder::default();
101        if let Some(val) = &args.description {
102            availability_zone_builder.description(val);
103        }
104
105        if let Some(val) = &args.enabled {
106            availability_zone_builder.enabled(*val);
107        }
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::set::AvailabilityZoneResponse>(data.clone())?;
122        // Show command specific hints
123        op.show_command_hint()?;
124        Ok(())
125    }
126}