openstack_cli_compute/v2/server/resize.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::resize;
34
35/// Resizes a server.
36///
37/// Specify the `resize` action in the request body.
38///
39/// **Preconditions**
40///
41/// You can only resize a server when its status is `ACTIVE` or `SHUTOFF`.
42///
43/// If the server is locked, you must have administrator privileges to resize
44/// the server.
45///
46/// **Asynchronous Postconditions**
47///
48/// A successfully resized server shows a `VERIFY_RESIZE` status and `finished`
49/// migration status. If the cloud has configured the
50/// [resize_confirm_window](https://docs.openstack.org/nova/latest/configuration/config.html#DEFAULT.resize_confirm_window)
51/// option of the Compute service to a positive value, the Compute service
52/// automatically confirms the resize operation after the configured interval.
53///
54/// Normal response codes: 202
55///
56/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
57/// itemNotFound(404), conflict(409)
58#[derive(Args)]
59#[command(about = "Resize Server (resize Action)")]
60pub struct ServerCommand {
61 /// Request Query parameters
62 #[command(flatten)]
63 query: QueryParameters,
64
65 /// Path parameters
66 #[command(flatten)]
67 path: PathParameters,
68
69 /// The action to resize a server.
70 #[command(flatten)]
71 resize: Resize,
72}
73
74/// Query parameters
75#[derive(Args)]
76struct QueryParameters {}
77
78/// Path parameters
79#[derive(Args)]
80struct PathParameters {
81 /// id parameter for /v2.1/servers/{id}/action API
82 #[arg(
83 help_heading = "Path parameters",
84 id = "path_param_id",
85 value_name = "ID"
86 )]
87 id: String,
88}
89
90#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
91enum OsDcfDiskConfig {
92 Auto,
93 Manual,
94}
95
96/// Resize Body data
97#[derive(Args, Clone)]
98struct Resize {
99 /// The flavor ID for resizing the server. The size of the disk in the
100 /// flavor being resized to must be greater than or equal to the size of
101 /// the disk in the current flavor.
102 ///
103 /// If a specified flavor ID is the same as the current one of the server,
104 /// the request returns a `Bad Request (400)` response code.
105 #[arg(help_heading = "Body parameters", long)]
106 flavor_ref: String,
107
108 /// Controls how the API partitions the disk when you create, rebuild, or
109 /// resize servers. A server inherits the `OS-DCF:diskConfig` value from
110 /// the image from which it was created, and an image inherits the
111 /// `OS-DCF:diskConfig` value from the server from which it was created. To
112 /// override the inherited setting, you can include this attribute in the
113 /// request body of a server create, rebuild, or resize request. If the
114 /// `OS-DCF:diskConfig` value for an image is `MANUAL`, you cannot create a
115 /// server from that image and set its `OS-DCF:diskConfig` value to `AUTO`.
116 /// A valid value is:
117 ///
118 /// - `AUTO`. The API builds the server with a single partition the size of
119 /// the target flavor disk. The API automatically adjusts the file system
120 /// to fit the entire partition.
121 /// - `MANUAL`. The API builds the server by using whatever partition
122 /// scheme and file system is in the source image. If the target flavor
123 /// disk is larger, the API does not partition the remaining disk space.
124 #[arg(help_heading = "Body parameters", long)]
125 os_dcf_disk_config: Option<OsDcfDiskConfig>,
126}
127
128impl ServerCommand {
129 /// Perform command action
130 pub async fn take_action<C: CliArgs>(
131 &self,
132 parsed_args: &C,
133 client: &mut AsyncOpenStack,
134 ) -> Result<(), OpenStackCliError> {
135 info!("Action Server");
136
137 let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("resize"));
138 op.validate_args(parsed_args)?;
139
140 let mut ep_builder = resize::Request::builder();
141
142 ep_builder.id(&self.path.id);
143
144 // Set body parameters
145 // Set Request.resize data
146 let args = &self.resize;
147 let mut resize_builder = resize::ResizeBuilder::default();
148 if let Some(val) = &args.os_dcf_disk_config {
149 let tmp = match val {
150 OsDcfDiskConfig::Auto => resize::OsDcfDiskConfig::Auto,
151 OsDcfDiskConfig::Manual => resize::OsDcfDiskConfig::Manual,
152 };
153 resize_builder.os_dcf_disk_config(tmp);
154 }
155
156 resize_builder.flavor_ref(&args.flavor_ref);
157
158 ep_builder.resize(
159 resize_builder
160 .build()
161 .wrap_err("error preparing the request data")?,
162 );
163
164 let ep = ep_builder
165 .build()
166 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
167 openstack_sdk::api::ignore(ep).query_async(client).await?;
168 // Show command specific hints
169 op.show_command_hint()?;
170 Ok(())
171 }
172}