openstack_cli_compute/v2/service/set_20.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.0]
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_20;
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.0)")]
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 #[arg(help_heading = "Body parameters", long)]
66 host: String,
67}
68
69/// Query parameters
70#[derive(Args)]
71struct QueryParameters {}
72
73/// Path parameters
74#[derive(Args)]
75struct PathParameters {
76 /// id parameter for /v2.1/os-services/{id} API
77 #[arg(
78 help_heading = "Path parameters",
79 id = "path_param_id",
80 value_name = "ID"
81 )]
82 id: String,
83}
84
85impl ServiceCommand {
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!("Set Service");
93
94 let op = OutputProcessor::from_args(parsed_args, Some("compute.service"), Some("set"));
95 op.validate_args(parsed_args)?;
96
97 let mut ep_builder = set_20::Request::builder();
98 ep_builder.header(
99 http::header::HeaderName::from_static("openstack-api-version"),
100 http::header::HeaderValue::from_static("compute 2.0"),
101 );
102
103 ep_builder.id(&self.path.id);
104
105 // Set body parameters
106 // Set Request.binary data
107 ep_builder.binary(&self.binary);
108
109 // Set Request.disabled_reason data
110 if let Some(arg) = &self.disabled_reason {
111 ep_builder.disabled_reason(arg);
112 }
113
114 // Set Request.host data
115 ep_builder.host(&self.host);
116
117 let ep = ep_builder
118 .build()
119 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
120
121 let data: serde_json::Value = ep.query_async(client).await?;
122
123 op.output_single::<response::set_20_a::ServiceResponse>(data.clone())
124 .or_else(|_| op.output_single::<response::set_20_b::ServiceResponse>(data.clone()))?;
125 // Show command specific hints
126 op.show_command_hint()?;
127 Ok(())
128 }
129}