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_sdk::AsyncOpenStack;
26
27use crate::Cli;
28use crate::OpenStackCliError;
29use crate::output::OutputProcessor;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::service::set_20;
33use openstack_types::compute::v2::service::response::set::ServiceResponse;
34
35/// Update a compute service to enable or disable scheduling, including
36/// recording a reason why a compute service was disabled from scheduling. Set
37/// or unset the `forced_down` flag for the service. This operation is only
38/// allowed on services whose `binary` is `nova-compute`.
39///
40/// This API is available starting with microversion 2.53.
41///
42/// Normal response codes: 200
43///
44/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
45/// itemNotFound(404)
46#[derive(Args)]
47#[command(about = "Update Compute Service (microversion = 2.0)")]
48pub struct ServiceCommand {
49 /// Request Query parameters
50 #[command(flatten)]
51 query: QueryParameters,
52
53 /// Path parameters
54 #[command(flatten)]
55 path: PathParameters,
56
57 #[arg(help_heading = "Body parameters", long)]
58 binary: String,
59
60 /// The reason for disabling a service. The minimum length is 1 and the
61 /// maximum length is 255. This may only be requested with
62 /// `status=disabled`.
63 #[arg(help_heading = "Body parameters", long)]
64 disabled_reason: Option<String>,
65
66 #[arg(help_heading = "Body parameters", long)]
67 host: String,
68}
69
70/// Query parameters
71#[derive(Args)]
72struct QueryParameters {}
73
74/// Path parameters
75#[derive(Args)]
76struct PathParameters {
77 /// id parameter for /v2.1/os-services/{id} API
78 #[arg(
79 help_heading = "Path parameters",
80 id = "path_param_id",
81 value_name = "ID"
82 )]
83 id: String,
84}
85
86impl ServiceCommand {
87 /// Perform command action
88 pub async fn take_action(
89 &self,
90 parsed_args: &Cli,
91 client: &mut AsyncOpenStack,
92 ) -> Result<(), OpenStackCliError> {
93 info!("Set Service");
94
95 let op = OutputProcessor::from_args(parsed_args, Some("compute.service"), Some("set"));
96 op.validate_args(parsed_args)?;
97
98 let mut ep_builder = set_20::Request::builder();
99 ep_builder.header(
100 http::header::HeaderName::from_static("openstack-api-version"),
101 http::header::HeaderValue::from_static("compute 2.0"),
102 );
103
104 ep_builder.id(&self.path.id);
105
106 // Set body parameters
107 // Set Request.binary data
108 ep_builder.binary(&self.binary);
109
110 // Set Request.disabled_reason data
111 if let Some(arg) = &self.disabled_reason {
112 ep_builder.disabled_reason(arg);
113 }
114
115 // Set Request.host data
116 ep_builder.host(&self.host);
117
118 let ep = ep_builder
119 .build()
120 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
121
122 let data = ep.query_async(client).await?;
123 op.output_single::<ServiceResponse>(data)?;
124 // Show command specific hints
125 op.show_command_hint()?;
126 Ok(())
127 }
128}