Skip to main content

openstack_cli_network/v2/subnetpool/
add_prefixes.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 Subnetpool command
19//!
20//! Wraps invoking of the `v2.0/subnetpools/{id}/add_prefixes` with `PUT` method
21
22use clap::Args;
23use tracing::info;
24
25use openstack_cli_core::cli::CliArgs;
26use openstack_cli_core::error::OpenStackCliError;
27use openstack_cli_core::output::OutputProcessor;
28use openstack_sdk::AsyncOpenStack;
29
30use openstack_cli_core::common::parse_key_val;
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::network::v2::subnetpool::add_prefixes;
33use openstack_types::network::v2::subnetpool::response;
34use serde_json::Value;
35
36/// Request of the subnetpools/id/add_prefixes:put operation
37#[derive(Args)]
38#[command(about = "Add prefixes")]
39pub struct SubnetpoolCommand {
40    /// Request Query parameters
41    #[command(flatten)]
42    query: QueryParameters,
43
44    /// Path parameters
45    #[command(flatten)]
46    path: PathParameters,
47
48    #[arg(long="property", value_name="key=value", value_parser=parse_key_val::<String, Value>)]
49    #[arg(help_heading = "Body parameters")]
50    properties: Option<Vec<(String, Value)>>,
51}
52
53/// Query parameters
54#[derive(Args)]
55struct QueryParameters {}
56
57/// Path parameters
58#[derive(Args)]
59struct PathParameters {
60    /// id parameter for /v2.0/subnetpools/{id}/remove_prefixes API
61    #[arg(
62        help_heading = "Path parameters",
63        id = "path_param_id",
64        value_name = "ID"
65    )]
66    id: String,
67}
68
69impl SubnetpoolCommand {
70    /// Perform command action
71    pub async fn take_action<C: CliArgs>(
72        &self,
73        parsed_args: &C,
74        client: &mut AsyncOpenStack,
75    ) -> Result<(), OpenStackCliError> {
76        info!("Action Subnetpool");
77
78        let op = OutputProcessor::from_args(
79            parsed_args,
80            Some("network.subnetpool"),
81            Some("add_prefixes"),
82        );
83        op.validate_args(parsed_args)?;
84
85        let mut ep_builder = add_prefixes::Request::builder();
86
87        ep_builder.id(&self.path.id);
88
89        // Set body parameters
90        if let Some(properties) = &self.properties {
91            ep_builder.properties(properties.iter().cloned());
92        }
93
94        let ep = ep_builder
95            .build()
96            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
97
98        let data: serde_json::Value = ep.query_async(client).await?;
99
100        op.output_single::<response::add_prefixes::SubnetpoolResponse>(data.clone())?;
101        // Show command specific hints
102        op.show_command_hint()?;
103        Ok(())
104    }
105}