Skip to main content

openstack_cli_network/v2/router/
remove_router_interface.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 Router command
19//!
20//! Wraps invoking of the `v2.0/routers/{id}/remove_router_interface` 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_sdk::api::QueryAsync;
31use openstack_sdk::api::network::v2::router::remove_router_interface;
32use openstack_types::network::v2::router::response;
33
34/// Request body
35#[derive(Args)]
36#[command(about = "Remove interface from router")]
37pub struct RouterCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// The ID of the port. One of subnet_id or port_id must be specified.
47    #[arg(help_heading = "Body parameters", long)]
48    port_id: Option<String>,
49
50    /// The ID of the subnet. One of subnet_id or port_id must be specified.
51    #[arg(help_heading = "Body parameters", long)]
52    subnet_id: Option<String>,
53}
54
55/// Query parameters
56#[derive(Args)]
57struct QueryParameters {}
58
59/// Path parameters
60#[derive(Args)]
61struct PathParameters {
62    /// id parameter for /v2.0/routers/{id} API
63    #[arg(
64        help_heading = "Path parameters",
65        id = "path_param_id",
66        value_name = "ID"
67    )]
68    id: String,
69}
70
71impl RouterCommand {
72    /// Perform command action
73    pub async fn take_action<C: CliArgs>(
74        &self,
75        parsed_args: &C,
76        client: &mut AsyncOpenStack,
77    ) -> Result<(), OpenStackCliError> {
78        info!("Action Router");
79
80        let op = OutputProcessor::from_args(
81            parsed_args,
82            Some("network.router"),
83            Some("remove_router_interface"),
84        );
85        op.validate_args(parsed_args)?;
86
87        let mut ep_builder = remove_router_interface::Request::builder();
88
89        ep_builder.id(&self.path.id);
90
91        // Set body parameters
92        // Set Request.port_id data
93        if let Some(arg) = &self.port_id {
94            ep_builder.port_id(arg);
95        }
96
97        // Set Request.subnet_id data
98        if let Some(arg) = &self.subnet_id {
99            ep_builder.subnet_id(arg);
100        }
101
102        let ep = ep_builder
103            .build()
104            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
105
106        let data: serde_json::Value = ep.query_async(client).await?;
107
108        op.output_single::<response::remove_router_interface::RouterResponse>(data.clone())?;
109        // Show command specific hints
110        op.show_command_hint()?;
111        Ok(())
112    }
113}