Skip to main content

openstack_cli_network/v2/port/binding/
activate.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 Binding command
19//!
20//! Wraps invoking of the `v2.0/ports/{port_id}/bindings/{id}/activate` 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::port::binding::activate;
32use openstack_types::network::v2::port::binding::response;
33
34/// Normal response codes: 200
35///
36/// Error response codes: 400, 401, 404, 412
37#[derive(Args)]
38#[command(about = "Activate Port binding")]
39pub struct BindingCommand {
40    /// Request Query parameters
41    #[command(flatten)]
42    query: QueryParameters,
43
44    /// Path parameters
45    #[command(flatten)]
46    path: PathParameters,
47
48    /// The hostname of the system the agent is running on.
49    #[arg(help_heading = "Body parameters", long)]
50    host: String,
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/ports/{port_id}/bindings/{id} API
61    #[arg(
62        help_heading = "Path parameters",
63        id = "path_param_id",
64        value_name = "ID"
65    )]
66    id: String,
67
68    /// port_id parameter for /v2.0/ports/{port_id}/bindings/{id} API
69    #[arg(
70        help_heading = "Path parameters",
71        id = "path_param_port_id",
72        value_name = "PORT_ID"
73    )]
74    port_id: String,
75}
76
77impl BindingCommand {
78    /// Perform command action
79    pub async fn take_action<C: CliArgs>(
80        &self,
81        parsed_args: &C,
82        client: &mut AsyncOpenStack,
83    ) -> Result<(), OpenStackCliError> {
84        info!("Action Binding");
85
86        let op =
87            OutputProcessor::from_args(parsed_args, Some("network.port/binding"), Some("activate"));
88        op.validate_args(parsed_args)?;
89
90        let mut ep_builder = activate::Request::builder();
91
92        ep_builder.id(&self.path.id);
93        ep_builder.port_id(&self.path.port_id);
94
95        // Set body parameters
96        // Set Request.host data
97        ep_builder.host(&self.host);
98
99        let ep = ep_builder
100            .build()
101            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
102
103        let data: serde_json::Value = ep.query_async(client).await?;
104
105        op.output_single::<response::activate::BindingResponse>(data.clone())?;
106        // Show command specific hints
107        op.show_command_hint()?;
108        Ok(())
109    }
110}