openstack_cli_compute/v2/service/set_211.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//! Set Service command [microversion = 2.11]
19//!
20//! Wraps invoking of the `v2.1/os-services/{id}` with `PUT` 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::service::set_211;
32use openstack_types::compute::v2::service::response;
33
34/// Update a compute service to enable or disable scheduling, including
35/// recording a reason why a compute service was disabled from scheduling. Set
36/// or unset the `forced_down` flag for the service. This operation is only
37/// allowed on services whose `binary` is `nova-compute`.
38///
39/// This API is available starting with microversion 2.53.
40///
41/// Normal response codes: 200
42///
43/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
44/// itemNotFound(404)
45#[derive(Args)]
46#[command(about = "Update Compute Service (microversion = 2.11)")]
47pub struct ServiceCommand {
48 /// Request Query parameters
49 #[command(flatten)]
50 query: QueryParameters,
51
52 /// Path parameters
53 #[command(flatten)]
54 path: PathParameters,
55
56 #[arg(help_heading = "Body parameters", long)]
57 binary: String,
58
59 /// The reason for disabling a service. The minimum length is 1 and the
60 /// maximum length is 255. This may only be requested with
61 /// `status=disabled`.
62 #[arg(help_heading = "Body parameters", long)]
63 disabled_reason: Option<String>,
64
65 /// `forced_down` is a manual override to tell nova that the service in
66 /// question has been fenced manually by the operations team (either hard
67 /// powered off, or network unplugged). That signals that it is safe to
68 /// proceed with `evacuate` or other operations that nova has safety checks
69 /// to prevent for hosts that are up.
70 ///
71 /// Warning
72 ///
73 /// Setting a service forced down without completely fencing it will likely
74 /// result in the corruption of VMs on that host.
75 #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
76 forced_down: Option<bool>,
77
78 #[arg(help_heading = "Body parameters", long)]
79 host: String,
80}
81
82/// Query parameters
83#[derive(Args)]
84struct QueryParameters {}
85
86/// Path parameters
87#[derive(Args)]
88struct PathParameters {
89 /// id parameter for /v2.1/os-services/{id} API
90 #[arg(
91 help_heading = "Path parameters",
92 id = "path_param_id",
93 value_name = "ID"
94 )]
95 id: String,
96}
97
98impl ServiceCommand {
99 /// Perform command action
100 pub async fn take_action<C: CliArgs>(
101 &self,
102 parsed_args: &C,
103 client: &mut AsyncOpenStack,
104 ) -> Result<(), OpenStackCliError> {
105 info!("Set Service");
106
107 let op = OutputProcessor::from_args(parsed_args, Some("compute.service"), Some("set"));
108 op.validate_args(parsed_args)?;
109
110 let mut ep_builder = set_211::Request::builder();
111 ep_builder.header(
112 http::header::HeaderName::from_static("openstack-api-version"),
113 http::header::HeaderValue::from_static("compute 2.11"),
114 );
115
116 ep_builder.id(&self.path.id);
117
118 // Set body parameters
119 // Set Request.binary data
120 ep_builder.binary(&self.binary);
121
122 // Set Request.disabled_reason data
123 if let Some(arg) = &self.disabled_reason {
124 ep_builder.disabled_reason(arg);
125 }
126
127 // Set Request.forced_down data
128 if let Some(arg) = &self.forced_down {
129 ep_builder.forced_down(*arg);
130 }
131
132 // Set Request.host data
133 ep_builder.host(&self.host);
134
135 let ep = ep_builder
136 .build()
137 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
138
139 let data: serde_json::Value = ep.query_async(client).await?;
140
141 op.output_single::<response::set_20_a::ServiceResponse>(data.clone())
142 .or_else(|_| op.output_single::<response::set_20_b::ServiceResponse>(data.clone()))?;
143 // Show command specific hints
144 op.show_command_hint()?;
145 Ok(())
146 }
147}