Skip to main content

openstack_cli_compute/v2/server/
change_password.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 openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::server::change_password;
33
34/// Changes the administrative password for a server.
35///
36/// Specify the `changePassword` 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: badRequest(400), unauthorized(401), forbidden(403),
45/// itemNotFound(404), conflict(409), notImplemented(501)
46#[derive(Args)]
47#[command(about = "Change Administrative Password (changePassword 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 to change an administrative password of the server.
58    #[command(flatten)]
59    change_password: ChangePassword,
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/// ChangePassword Body data
78#[derive(Args, Clone)]
79struct ChangePassword {
80    /// The administrative password for the server.
81    #[arg(help_heading = "Body parameters", long)]
82    admin_pass: String,
83}
84
85impl ServerCommand {
86    /// Perform command action
87    pub async fn take_action<C: CliArgs>(
88        &self,
89        parsed_args: &C,
90        client: &mut AsyncOpenStack,
91    ) -> Result<(), OpenStackCliError> {
92        info!("Action Server");
93
94        let op = OutputProcessor::from_args(
95            parsed_args,
96            Some("compute.server"),
97            Some("change_password"),
98        );
99        op.validate_args(parsed_args)?;
100
101        let mut ep_builder = change_password::Request::builder();
102
103        ep_builder.id(&self.path.id);
104
105        // Set body parameters
106        // Set Request.change_password data
107        let args = &self.change_password;
108        let mut change_password_builder = change_password::ChangePasswordBuilder::default();
109
110        change_password_builder.admin_pass(&args.admin_pass);
111
112        ep_builder.change_password(
113            change_password_builder
114                .build()
115                .wrap_err("error preparing the request data")?,
116        );
117
118        let ep = ep_builder
119            .build()
120            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
121        openstack_sdk::api::ignore(ep).query_async(client).await?;
122        // Show command specific hints
123        op.show_command_hint()?;
124        Ok(())
125    }
126}