Skip to main content

openstack_cli_compute/v2/server/
remove_security_group.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 Server command
19//!
20//! Wraps invoking of the `v2.1/servers/{id}/action` with `POST` 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_cli_core::common::parse_key_val;
32use openstack_sdk::api::QueryAsync;
33use openstack_sdk::api::compute::v2::server::remove_security_group;
34use serde_json::Value;
35
36/// Removes a security group from a server.
37///
38/// Specify the `removeSecurityGroup` action in the request body.
39///
40/// Normal response codes: 202
41///
42/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
43/// itemNotFound(404), conflict(409)
44#[derive(Args)]
45#[command(about = "Remove Security Group From A Server (removeSecurityGroup Action)")]
46pub struct ServerCommand {
47    /// Request Query parameters
48    #[command(flatten)]
49    query: QueryParameters,
50
51    /// Path parameters
52    #[command(flatten)]
53    path: PathParameters,
54
55    /// The action to remove a security group from the server.
56    #[command(flatten)]
57    remove_security_group: RemoveSecurityGroup,
58    /// Additional properties to be sent with the request
59    #[arg(long="property", value_name="key=value", value_parser=parse_key_val::<String, Value>)]
60    #[arg(help_heading = "Body parameters")]
61    properties: Option<Vec<(String, Value)>>,
62}
63
64/// Query parameters
65#[derive(Args)]
66struct QueryParameters {}
67
68/// Path parameters
69#[derive(Args)]
70struct PathParameters {
71    /// id parameter for /v2.1/servers/{id}/action API
72    #[arg(
73        help_heading = "Path parameters",
74        id = "path_param_id",
75        value_name = "ID"
76    )]
77    id: String,
78}
79/// RemoveSecurityGroup Body data
80#[derive(Args, Clone)]
81struct RemoveSecurityGroup {
82    /// The security group name.
83    #[arg(help_heading = "Body parameters", long)]
84    name: String,
85}
86
87impl ServerCommand {
88    /// Perform command action
89    pub async fn take_action<C: CliArgs>(
90        &self,
91        parsed_args: &C,
92        client: &mut AsyncOpenStack,
93    ) -> Result<(), OpenStackCliError> {
94        info!("Action Server");
95
96        let op = OutputProcessor::from_args(
97            parsed_args,
98            Some("compute.server"),
99            Some("remove_security_group"),
100        );
101        op.validate_args(parsed_args)?;
102
103        let mut ep_builder = remove_security_group::Request::builder();
104
105        ep_builder.id(&self.path.id);
106
107        // Set body parameters
108        // Set Request.remove_security_group data
109        let args = &self.remove_security_group;
110        let mut remove_security_group_builder =
111            remove_security_group::RemoveSecurityGroupBuilder::default();
112
113        remove_security_group_builder.name(&args.name);
114
115        ep_builder.remove_security_group(
116            remove_security_group_builder
117                .build()
118                .wrap_err("error preparing the request data")?,
119        );
120
121        if let Some(properties) = &self.properties {
122            ep_builder.properties(properties.iter().cloned());
123        }
124
125        let ep = ep_builder
126            .build()
127            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
128        openstack_sdk::api::ignore(ep).query_async(client).await?;
129        // Show command specific hints
130        op.show_command_hint()?;
131        Ok(())
132    }
133}