Skip to main content

openstack_cli_compute/v2/server/
os_stop.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 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::os_stop;
32use serde_json::Value;
33
34/// Stops a running server and changes its status to `SHUTOFF`.
35///
36/// Specify the `os-stop` action in the request body.
37///
38/// **Preconditions**
39///
40/// The server status must be `ACTIVE` or `ERROR`.
41///
42/// If the server is locked, you must have administrator privileges to stop the
43/// server.
44///
45/// **Asynchronous Postconditions**
46///
47/// After you successfully stop a server, its status changes to `SHUTOFF`. This
48/// API operation does not delete the server instance data and the data will be
49/// available again after `os-start` action.
50///
51/// Normal response codes: 202
52///
53/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
54/// conflict(409)
55#[derive(Args)]
56#[command(about = "Stop Server (os-stop Action)")]
57pub struct ServerCommand {
58    /// Request Query parameters
59    #[command(flatten)]
60    query: QueryParameters,
61
62    /// Path parameters
63    #[command(flatten)]
64    path: PathParameters,
65
66    /// OpenAPI specifies the field as '{}'.
67    #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
68    os_stop: Value,
69}
70
71/// Query parameters
72#[derive(Args)]
73struct QueryParameters {}
74
75/// Path parameters
76#[derive(Args)]
77struct PathParameters {
78    /// id parameter for /v2.1/servers/{id}/action API
79    #[arg(
80        help_heading = "Path parameters",
81        id = "path_param_id",
82        value_name = "ID"
83    )]
84    id: 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(parsed_args, Some("compute.server"), Some("os_stop"));
97        op.validate_args(parsed_args)?;
98
99        let mut ep_builder = os_stop::Request::builder();
100
101        ep_builder.id(&self.path.id);
102
103        // Set body parameters
104        // Set Request.os_stop data
105        ep_builder.os_stop(self.os_stop.clone());
106
107        let ep = ep_builder
108            .build()
109            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
110        openstack_sdk::api::ignore(ep).query_async(client).await?;
111        // Show command specific hints
112        op.show_command_hint()?;
113        Ok(())
114    }
115}