Skip to main content

openstack_cli_compute/v2/server/
os_reset_state.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 clap::ValueEnum;
32use openstack_sdk::api::QueryAsync;
33use openstack_sdk::api::compute::v2::server::os_reset_state;
34
35/// Resets the state of a server.
36///
37/// Specify the `os-resetState` action and the `state` in the request body.
38///
39/// Policy defaults enable only users with the administrative role to perform
40/// this operation. Cloud providers can change these permissions through the
41/// `policy.yaml` file.
42///
43/// Normal response codes: 202
44///
45/// Error response codes: unauthorized(401), forbidden(403), itemNotFound(404)
46#[derive(Args)]
47#[command(about = "Reset Server State (os-resetState Action)")]
48pub struct ServerCommand {
49    /// Request Query parameters
50    #[command(flatten)]
51    query: QueryParameters,
52
53    /// Path parameters
54    #[command(flatten)]
55    path: PathParameters,
56
57    /// The action.
58    #[command(flatten)]
59    os_reset_state: OsResetState,
60}
61
62/// Query parameters
63#[derive(Args)]
64struct QueryParameters {}
65
66/// Path parameters
67#[derive(Args)]
68struct PathParameters {
69    /// id parameter for /v2.1/servers/{id}/action API
70    #[arg(
71        help_heading = "Path parameters",
72        id = "path_param_id",
73        value_name = "ID"
74    )]
75    id: String,
76}
77
78#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
79enum State {
80    Active,
81    Error,
82}
83
84/// OsResetState Body data
85#[derive(Args, Clone)]
86struct OsResetState {
87    /// The state of the server to be set, `active` or `error` are valid.
88    #[arg(help_heading = "Body parameters", long)]
89    state: State,
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 =
102            OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("os_reset_state"));
103        op.validate_args(parsed_args)?;
104
105        let mut ep_builder = os_reset_state::Request::builder();
106
107        ep_builder.id(&self.path.id);
108
109        // Set body parameters
110        // Set Request.os_reset_state data
111        let args = &self.os_reset_state;
112        let mut os_reset_state_builder = os_reset_state::OsResetStateBuilder::default();
113
114        let tmp = match &args.state {
115            State::Active => os_reset_state::State::Active,
116            State::Error => os_reset_state::State::Error,
117        };
118        os_reset_state_builder.state(tmp);
119
120        ep_builder.os_reset_state(
121            os_reset_state_builder
122                .build()
123                .wrap_err("error preparing the request data")?,
124        );
125
126        let ep = ep_builder
127            .build()
128            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
129        openstack_sdk::api::ignore(ep).query_async(client).await?;
130        // Show command specific hints
131        op.show_command_hint()?;
132        Ok(())
133    }
134}