Skip to main content

openstack_cli_network/v2/address_group/
remove_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}/remove_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::remove_addresses;
33use openstack_types::network::v2::address_group::response;
34
35/// Atomically removes a set of IP addresses from the address group’s already
36/// existing addresses.
37///
38/// Normal response codes: 200
39///
40/// Error response codes: 400, 401, 404, 412
41#[derive(Args)]
42#[command(about = "Remove IP addresses to address group")]
43pub struct AddressGroupCommand {
44    /// Request Query parameters
45    #[command(flatten)]
46    query: QueryParameters,
47
48    /// Path parameters
49    #[command(flatten)]
50    path: PathParameters,
51
52    #[command(flatten)]
53    address_group: AddressGroup,
54}
55
56/// Query parameters
57#[derive(Args)]
58struct QueryParameters {}
59
60/// Path parameters
61#[derive(Args)]
62struct PathParameters {
63    /// id parameter for /v2.0/address-groups/{id} API
64    #[arg(
65        help_heading = "Path parameters",
66        id = "path_param_id",
67        value_name = "ID"
68    )]
69    id: String,
70}
71/// AddressGroup Body data
72#[derive(Args, Clone)]
73struct AddressGroup {
74    /// A list of IP addresses.
75    ///
76    /// Parameter is an array, may be provided multiple times.
77    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
78    addresses: Option<Vec<String>>,
79}
80
81impl AddressGroupCommand {
82    /// Perform command action
83    pub async fn take_action<C: CliArgs>(
84        &self,
85        parsed_args: &C,
86        client: &mut AsyncOpenStack,
87    ) -> Result<(), OpenStackCliError> {
88        info!("Action AddressGroup");
89
90        let op = OutputProcessor::from_args(
91            parsed_args,
92            Some("network.address_group"),
93            Some("remove_addresses"),
94        );
95        op.validate_args(parsed_args)?;
96
97        let mut ep_builder = remove_addresses::Request::builder();
98
99        ep_builder.id(&self.path.id);
100
101        // Set body parameters
102        // Set Request.address_group data
103        let args = &self.address_group;
104        let mut address_group_builder = remove_addresses::AddressGroupBuilder::default();
105        if let Some(val) = &args.addresses {
106            address_group_builder.addresses(val.iter().map(Into::into).collect::<Vec<_>>());
107        }
108
109        ep_builder.address_group(
110            address_group_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::remove_addresses::AddressGroupResponse>(data.clone())?;
122        // Show command specific hints
123        op.show_command_hint()?;
124        Ok(())
125    }
126}