Skip to main content

openstack_cli_compute/v2/server/
os_start.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_start;
32use serde_json::Value;
33
34/// Starts a stopped server and changes its status to `ACTIVE`.
35///
36/// Specify the `os-start` action in the request body.
37///
38/// **Preconditions**
39///
40/// The server status must be `SHUTOFF`.
41///
42/// If the server is locked, you must have administrator privileges to start
43/// the server.
44///
45/// **Asynchronous Postconditions**
46///
47/// After you successfully start a server, its status changes to `ACTIVE`.
48///
49/// **Troubleshooting**
50///
51/// If the server status does not change to `ACTIVE`, the start operation
52/// failed. Ensure that you meet the preconditions and run the request again.
53/// If the request fails again, investigate whether another operation is
54/// running that causes a race condition.
55///
56/// Normal response codes: 202
57///
58/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404),
59/// conflict(409)
60#[derive(Args)]
61#[command(about = "Start Server (os-start Action)")]
62pub struct ServerCommand {
63    /// Request Query parameters
64    #[command(flatten)]
65    query: QueryParameters,
66
67    /// Path parameters
68    #[command(flatten)]
69    path: PathParameters,
70
71    /// OpenAPI specifies the field as '{}'.
72    #[arg(default_value_t=Value::Null, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
73    os_start: Value,
74}
75
76/// Query parameters
77#[derive(Args)]
78struct QueryParameters {}
79
80/// Path parameters
81#[derive(Args)]
82struct PathParameters {
83    /// id parameter for /v2.1/servers/{id}/action API
84    #[arg(
85        help_heading = "Path parameters",
86        id = "path_param_id",
87        value_name = "ID"
88    )]
89    id: String,
90}
91
92impl ServerCommand {
93    /// Perform command action
94    pub async fn take_action<C: CliArgs>(
95        &self,
96        parsed_args: &C,
97        client: &mut AsyncOpenStack,
98    ) -> Result<(), OpenStackCliError> {
99        info!("Action Server");
100
101        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("os_start"));
102        op.validate_args(parsed_args)?;
103
104        let mut ep_builder = os_start::Request::builder();
105
106        ep_builder.id(&self.path.id);
107
108        // Set body parameters
109        // Set Request.os_start data
110        ep_builder.os_start(self.os_start.clone());
111
112        let ep = ep_builder
113            .build()
114            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
115        openstack_sdk::api::ignore(ep).query_async(client).await?;
116        // Show command specific hints
117        op.show_command_hint()?;
118        Ok(())
119    }
120}