Skip to main content

openstack_cli_compute/v2/server/
lock_273.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.73]
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_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::server::lock_273;
33
34/// Command without description in OpenAPI
35#[derive(Args)]
36#[command(about = "Lock Server (lock Action) (microversion = 2.73)")]
37pub struct ServerCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// The action to lock a server. This parameter can be `null`. Up to
47    /// microversion 2.73, this parameter should be `null`.
48    #[command(flatten)]
49    lock: Option<Lock>,
50}
51
52/// Query parameters
53#[derive(Args)]
54struct QueryParameters {}
55
56/// Path parameters
57#[derive(Args)]
58struct PathParameters {
59    /// id parameter for /v2.1/servers/{id}/action API
60    #[arg(
61        help_heading = "Path parameters",
62        id = "path_param_id",
63        value_name = "ID"
64    )]
65    id: String,
66}
67/// Lock Body data
68#[derive(Args, Clone)]
69struct Lock {
70    #[arg(help_heading = "Body parameters", long)]
71    locked_reason: Option<String>,
72}
73
74impl ServerCommand {
75    /// Perform command action
76    pub async fn take_action<C: CliArgs>(
77        &self,
78        parsed_args: &C,
79        client: &mut AsyncOpenStack,
80    ) -> Result<(), OpenStackCliError> {
81        info!("Action Server");
82
83        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("lock"));
84        op.validate_args(parsed_args)?;
85
86        let mut ep_builder = lock_273::Request::builder();
87        ep_builder.header(
88            http::header::HeaderName::from_static("openstack-api-version"),
89            http::header::HeaderValue::from_static("compute 2.73"),
90        );
91
92        ep_builder.id(&self.path.id);
93
94        // Set body parameters
95        // Set Request.lock data
96        if let Some(llock) = &self.lock {
97            let mut lock_builder = lock_273::LockBuilder::default();
98            if let Some(val) = &llock.locked_reason {
99                lock_builder.locked_reason(val);
100            }
101            ep_builder.lock(
102                lock_builder
103                    .build()
104                    .wrap_err("error preparing the request data")?,
105            );
106        }
107
108        let ep = ep_builder
109            .build()
110            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
111        openstack_sdk::api::ignore(ep).query_async(client).await?;
112        // Show command specific hints
113        op.show_command_hint()?;
114        Ok(())
115    }
116}