Skip to main content

openstack_cli_compute/v2/server/
rebuild_290.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 [microversion = 2.90]
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_cli_core::common::parse_key_val;
33use openstack_sdk::api::QueryAsync;
34use openstack_sdk::api::compute::v2::server::rebuild_290;
35use openstack_types::compute::v2::server::response;
36
37/// Command without description in OpenAPI
38#[derive(Args)]
39#[command(about = "Rebuild Server (rebuild Action) (microversion = 2.90)")]
40pub struct ServerCommand {
41    /// Request Query parameters
42    #[command(flatten)]
43    query: QueryParameters,
44
45    /// Path parameters
46    #[command(flatten)]
47    path: PathParameters,
48
49    /// The action to rebuild a server.
50    #[command(flatten)]
51    rebuild: Rebuild,
52}
53
54/// Query parameters
55#[derive(Args)]
56struct QueryParameters {}
57
58/// Path parameters
59#[derive(Args)]
60struct PathParameters {
61    /// id parameter for /v2.1/servers/{id}/action API
62    #[arg(
63        help_heading = "Path parameters",
64        id = "path_param_id",
65        value_name = "ID"
66    )]
67    id: String,
68}
69
70#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
71enum OsDcfDiskConfig {
72    Auto,
73    Manual,
74}
75
76/// Rebuild Body data
77#[derive(Args, Clone)]
78struct Rebuild {
79    /// IPv4 address that should be used to access this server.
80    #[arg(help_heading = "Body parameters", long)]
81    access_ipv4: Option<String>,
82
83    /// IPv6 address that should be used to access this server.
84    #[arg(help_heading = "Body parameters", long)]
85    access_ipv6: Option<String>,
86
87    /// The administrative password of the server. If you omit this parameter,
88    /// the operation generates a new password.
89    #[arg(help_heading = "Body parameters", long)]
90    admin_pass: Option<String>,
91
92    /// A free form description of the server. Limited to 255 characters in
93    /// length. Before microversion 2.19 this was set to the server name.
94    ///
95    /// **New in version 2.19**
96    #[arg(help_heading = "Body parameters", long)]
97    description: Option<String>,
98
99    /// Set explicit NULL for the description
100    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "description")]
101    no_description: bool,
102
103    /// The hostname to configure for the instance in the metadata service.
104    ///
105    /// Starting with microversion 2.94, this can be a Fully Qualified Domain
106    /// Name (FQDN) of up to 255 characters in length.
107    ///
108    /// Note
109    ///
110    /// This information is published via the metadata service and requires
111    /// application such as `cloud-init` to propagate it through to the
112    /// instance.
113    ///
114    /// **New in version 2.90**
115    #[arg(help_heading = "Body parameters", long)]
116    hostname: Option<String>,
117
118    /// The UUID of the image to rebuild for your server instance. It must be a
119    /// valid UUID otherwise API will return 400. To rebuild a volume-backed
120    /// server with a new image, at least microversion 2.93 needs to be
121    /// provided in the request else the request will fall back to old
122    /// behaviour i.e. the API will return 400 (for an image different from the
123    /// image used when creating the volume). For non-volume-backed servers,
124    /// specifying a new image will result in validating that the image is
125    /// acceptable for the current compute host on which the server exists. If
126    /// the new image is not valid, the server will go into `ERROR` status.
127    #[arg(help_heading = "Body parameters", long)]
128    image_ref: String,
129
130    /// Key pair name for rebuild API. If `null` is specified, the existing
131    /// keypair is unset.
132    ///
133    /// Note
134    ///
135    /// Users within the same project are able to rebuild other user’s
136    /// instances in that project with a new keypair. Keys are owned by users
137    /// (which is the only resource that’s true of). Servers are owned by
138    /// projects. Because of this a rebuild with a key_name is looking up the
139    /// keypair by the user calling rebuild.
140    ///
141    /// **New in version 2.54**
142    #[arg(help_heading = "Body parameters", long)]
143    key_name: Option<String>,
144
145    /// Set explicit NULL for the key_name
146    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "key_name")]
147    no_key_name: bool,
148
149    /// Metadata key and value pairs. The maximum size of the metadata key and
150    /// value is 255 bytes each.
151    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
152    metadata: Option<Vec<(String, String)>>,
153
154    /// The server name.
155    #[arg(help_heading = "Body parameters", long)]
156    name: Option<String>,
157
158    /// Controls how the API partitions the disk when you create, rebuild, or
159    /// resize servers. A server inherits the `OS-DCF:diskConfig` value from
160    /// the image from which it was created, and an image inherits the
161    /// `OS-DCF:diskConfig` value from the server from which it was created. To
162    /// override the inherited setting, you can include this attribute in the
163    /// request body of a server create, rebuild, or resize request. If the
164    /// `OS-DCF:diskConfig` value for an image is `MANUAL`, you cannot create a
165    /// server from that image and set its `OS-DCF:diskConfig` value to `AUTO`.
166    /// A valid value is:
167    ///
168    /// - `AUTO`. The API builds the server with a single partition the size of
169    ///   the target flavor disk. The API automatically adjusts the file system
170    ///   to fit the entire partition.
171    /// - `MANUAL`. The API builds the server by using whatever partition
172    ///   scheme and file system is in the source image. If the target flavor
173    ///   disk is larger, the API does not partition the remaining disk space.
174    #[arg(help_heading = "Body parameters", long)]
175    os_dcf_disk_config: Option<OsDcfDiskConfig>,
176
177    /// Indicates whether the server is rebuilt with the preservation of the
178    /// ephemeral partition (`true`).
179    ///
180    /// Note
181    ///
182    /// This only works with baremetal servers provided by Ironic. Passing it
183    /// to any other server instance results in a fault and will prevent the
184    /// rebuild from happening.
185    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
186    preserve_ephemeral: Option<bool>,
187
188    /// A list of trusted certificate IDs, which are used during image
189    /// signature verification to verify the signing certificate. The list is
190    /// restricted to a maximum of 50 IDs. This parameter is optional in server
191    /// rebuild requests if allowed by policy, and is not supported for
192    /// volume-backed instances.
193    ///
194    /// If `null` is specified, the existing trusted certificate IDs are either
195    /// unset or reset to the configured defaults.
196    ///
197    /// **New in version 2.63**
198    ///
199    /// Parameter is an array, may be provided multiple times.
200    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
201    trusted_image_certificates: Option<Vec<String>>,
202
203    /// Configuration information or scripts to use upon rebuild. Must be
204    /// Base64 encoded. Restricted to 65535 bytes. If `null` is specified, the
205    /// existing user_data is unset.
206    ///
207    /// **New in version 2.57**
208    #[arg(help_heading = "Body parameters", long)]
209    user_data: Option<String>,
210
211    /// Set explicit NULL for the user_data
212    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "user_data")]
213    no_user_data: bool,
214}
215
216impl ServerCommand {
217    /// Perform command action
218    pub async fn take_action<C: CliArgs>(
219        &self,
220        parsed_args: &C,
221        client: &mut AsyncOpenStack,
222    ) -> Result<(), OpenStackCliError> {
223        info!("Action Server");
224
225        let op = OutputProcessor::from_args(parsed_args, Some("compute.server"), Some("rebuild"));
226        op.validate_args(parsed_args)?;
227
228        let mut ep_builder = rebuild_290::Request::builder();
229        ep_builder.header(
230            http::header::HeaderName::from_static("openstack-api-version"),
231            http::header::HeaderValue::from_static("compute 2.90"),
232        );
233
234        ep_builder.id(&self.path.id);
235
236        // Set body parameters
237        // Set Request.rebuild data
238        let args = &self.rebuild;
239        let mut rebuild_builder = rebuild_290::RebuildBuilder::default();
240        if let Some(val) = &args.os_dcf_disk_config {
241            let tmp = match val {
242                OsDcfDiskConfig::Auto => rebuild_290::OsDcfDiskConfig::Auto,
243                OsDcfDiskConfig::Manual => rebuild_290::OsDcfDiskConfig::Manual,
244            };
245            rebuild_builder.os_dcf_disk_config(tmp);
246        }
247
248        if let Some(val) = &args.access_ipv4 {
249            rebuild_builder.access_ipv4(val);
250        }
251
252        if let Some(val) = &args.access_ipv6 {
253            rebuild_builder.access_ipv6(val);
254        }
255
256        if let Some(val) = &args.admin_pass {
257            rebuild_builder.admin_pass(val);
258        }
259
260        if let Some(val) = &args.description {
261            rebuild_builder.description(Some(val.into()));
262        } else if args.no_description {
263            rebuild_builder.description(None);
264        }
265
266        if let Some(val) = &args.hostname {
267            rebuild_builder.hostname(val);
268        }
269
270        rebuild_builder.image_ref(&args.image_ref);
271
272        if let Some(val) = &args.key_name {
273            rebuild_builder.key_name(Some(val.into()));
274        } else if args.no_key_name {
275            rebuild_builder.key_name(None);
276        }
277
278        if let Some(val) = &args.metadata {
279            rebuild_builder.metadata(val.iter().cloned());
280        }
281
282        if let Some(val) = &args.name {
283            rebuild_builder.name(val);
284        }
285
286        if let Some(val) = &args.preserve_ephemeral {
287            rebuild_builder.preserve_ephemeral(*val);
288        }
289
290        if let Some(val) = &args.trusted_image_certificates {
291            rebuild_builder
292                .trusted_image_certificates(val.iter().map(Into::into).collect::<Vec<_>>());
293        }
294
295        if let Some(val) = &args.user_data {
296            rebuild_builder.user_data(Some(val.into()));
297        } else if args.no_user_data {
298            rebuild_builder.user_data(None);
299        }
300
301        ep_builder.rebuild(
302            rebuild_builder
303                .build()
304                .wrap_err("error preparing the request data")?,
305        );
306
307        let ep = ep_builder
308            .build()
309            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
310
311        let data: serde_json::Value = ep.query_async(client).await?;
312
313        op.output_single::<response::rebuild_275::ServerResponse>(data.clone())?;
314        // Show command specific hints
315        op.show_command_hint()?;
316        Ok(())
317    }
318}