Skip to main content

openstack_cli_network/v2/agent/l3_router/
create.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//! Create L3Router command
19//!
20//! Wraps invoking of the `v2.0/agents/{agent_id}/l3-routers` with `POST` 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::agent::l3_router::create;
32use openstack_types::network::v2::agent::l3_router::response;
33
34/// Add a router to an l3 agent.
35///
36/// Normal response codes: 201
37///
38/// Error response codes: 400, 401, 404
39#[derive(Args)]
40#[command(about = "Schedule router to an l3 agent")]
41pub struct L3RouterCommand {
42    /// Request Query parameters
43    #[command(flatten)]
44    query: QueryParameters,
45
46    /// Path parameters
47    #[command(flatten)]
48    path: PathParameters,
49
50    /// The ID of the router.
51    #[arg(help_heading = "Body parameters", long)]
52    router_id: String,
53}
54
55/// Query parameters
56#[derive(Args)]
57struct QueryParameters {}
58
59/// Path parameters
60#[derive(Args)]
61struct PathParameters {
62    /// agent_id parameter for /v2.0/agents/{agent_id}/l3-routers/{id} API
63    #[arg(
64        help_heading = "Path parameters",
65        id = "path_param_agent_id",
66        value_name = "AGENT_ID"
67    )]
68    agent_id: String,
69}
70
71impl L3RouterCommand {
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!("Create L3Router");
79
80        let op = OutputProcessor::from_args(
81            parsed_args,
82            Some("network.agent/l3_router"),
83            Some("create"),
84        );
85        op.validate_args(parsed_args)?;
86
87        let mut ep_builder = create::Request::builder();
88
89        ep_builder.agent_id(&self.path.agent_id);
90
91        // Set body parameters
92        // Set Request.router_id data
93        ep_builder.router_id(&self.router_id);
94
95        let ep = ep_builder
96            .build()
97            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
98
99        let data: serde_json::Value = ep.query_async(client).await?;
100
101        op.output_single::<response::create::L3RouterResponse>(data.clone())?;
102        // Show command specific hints
103        op.show_command_hint()?;
104        Ok(())
105    }
106}