Skip to main content

openstack_cli_compute/v2/server/
unlock_21.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 [microversion = 2.1]
19//!
20//! Wraps invoking of the `v2.1/servers/{id}/action` 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::compute::v2::server::unlock_21;
32use serde_json::Value;
33
34/// Unlocks a locked server.
35///
36/// Specify the `unlock` action in the request body.
37///
38/// Policy defaults enable only users with the administrative role or the owner
39/// of the server to perform this operation. Cloud providers can change these
40/// permissions through the `policy.yaml` file.
41///
42/// Normal response codes: 202
43///
44/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404)
45#[derive(Args)]
46#[command(about = "Unlock Server (unlock Action) (microversion = 2.1)")]
47pub struct ServerCommand {
48    /// Request Query parameters
49    #[command(flatten)]
50    query: QueryParameters,
51
52    /// Path parameters
53    #[command(flatten)]
54    path: PathParameters,
55
56    /// OpenAPI specifies the field as '{}'.
57    #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
58    unlock: Value,
59}
60
61/// Query parameters
62#[derive(Args)]
63struct QueryParameters {}
64
65/// Path parameters
66#[derive(Args)]
67struct PathParameters {
68    /// id parameter for /v2.1/servers/{id}/action API
69    #[arg(
70        help_heading = "Path parameters",
71        id = "path_param_id",
72        value_name = "ID"
73    )]
74    id: String,
75}
76
77impl ServerCommand {
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 Server");
85
86        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("unlock"));
87        op.validate_args(parsed_args)?;
88
89        let mut ep_builder = unlock_21::Request::builder();
90        ep_builder.header(
91            http::header::HeaderName::from_static("openstack-api-version"),
92            http::header::HeaderValue::from_static("compute 2.1"),
93        );
94
95        ep_builder.id(&self.path.id);
96
97        // Set body parameters
98        // Set Request.unlock data
99        ep_builder.unlock(self.unlock.clone());
100
101        let ep = ep_builder
102            .build()
103            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
104        openstack_sdk::api::ignore(ep).query_async(client).await?;
105        // Show command specific hints
106        op.show_command_hint()?;
107        Ok(())
108    }
109}