Skip to main content

openstack_cli_network/v2/address_group/
add_addresses.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 AddressGroup command
19//!
20//! Wraps invoking of the `v2.0/address-groups/{id}/add_addresses` 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::network::v2::address_group::add_addresses;
33use openstack_types::network::v2::address_group::response;
34
35/// Command without description in OpenAPI
36#[derive(Args)]
37pub struct AddressGroupCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    #[command(flatten)]
47    address_group: AddressGroup,
48}
49
50/// Query parameters
51#[derive(Args)]
52struct QueryParameters {}
53
54/// Path parameters
55#[derive(Args)]
56struct PathParameters {
57    /// id parameter for /v2.0/address-groups/{id} API
58    #[arg(
59        help_heading = "Path parameters",
60        id = "path_param_id",
61        value_name = "ID"
62    )]
63    id: String,
64}
65/// AddressGroup Body data
66#[derive(Args, Clone)]
67struct AddressGroup {
68    /// A list of IP addresses.
69    ///
70    /// Parameter is an array, may be provided multiple times.
71    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
72    addresses: Option<Vec<String>>,
73}
74
75impl AddressGroupCommand {
76    /// Perform command action
77    pub async fn take_action<C: CliArgs>(
78        &self,
79        parsed_args: &C,
80        client: &mut AsyncOpenStack,
81    ) -> Result<(), OpenStackCliError> {
82        info!("Action AddressGroup");
83
84        let op = OutputProcessor::from_args(
85            parsed_args,
86            Some("network.address_group"),
87            Some("add_addresses"),
88        );
89        op.validate_args(parsed_args)?;
90
91        let mut ep_builder = add_addresses::Request::builder();
92
93        ep_builder.id(&self.path.id);
94
95        // Set body parameters
96        // Set Request.address_group data
97        let args = &self.address_group;
98        let mut address_group_builder = add_addresses::AddressGroupBuilder::default();
99        if let Some(val) = &args.addresses {
100            address_group_builder.addresses(val.iter().map(Into::into).collect::<Vec<_>>());
101        }
102
103        ep_builder.address_group(
104            address_group_builder
105                .build()
106                .wrap_err("error preparing the request data")?,
107        );
108
109        let ep = ep_builder
110            .build()
111            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
112
113        let data: serde_json::Value = ep.query_async(client).await?;
114
115        op.output_single::<response::add_addresses::AddressGroupResponse>(data.clone())?;
116        // Show command specific hints
117        op.show_command_hint()?;
118        Ok(())
119    }
120}