Skip to main content

openstack_cli_compute/v2/service/
set_253.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.53]
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 clap::ValueEnum;
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::service::set_253;
33use openstack_types::compute::v2::service::response;
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.53)")]
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    /// The reason for disabling a service. The minimum length is 1 and the
58    /// maximum length is 255. This may only be requested with
59    /// `status=disabled`.
60    #[arg(help_heading = "Body parameters", long)]
61    disabled_reason: Option<String>,
62
63    /// `forced_down` is a manual override to tell nova that the service in
64    /// question has been fenced manually by the operations team (either hard
65    /// powered off, or network unplugged). That signals that it is safe to
66    /// proceed with `evacuate` or other operations that nova has safety checks
67    /// to prevent for hosts that are up.
68    ///
69    /// Warning
70    ///
71    /// Setting a service forced down without completely fencing it will likely
72    /// result in the corruption of VMs on that host.
73    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
74    forced_down: Option<bool>,
75
76    /// The status of the service. One of `enabled` or `disabled`.
77    #[arg(help_heading = "Body parameters", long)]
78    status: Option<Status>,
79}
80
81/// Query parameters
82#[derive(Args)]
83struct QueryParameters {}
84
85/// Path parameters
86#[derive(Args)]
87struct PathParameters {
88    /// id parameter for /v2.1/os-services/{id} API
89    #[arg(
90        help_heading = "Path parameters",
91        id = "path_param_id",
92        value_name = "ID"
93    )]
94    id: String,
95}
96
97#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
98enum Status {
99    Disabled,
100    Enabled,
101}
102
103impl ServiceCommand {
104    /// Perform command action
105    pub async fn take_action<C: CliArgs>(
106        &self,
107        parsed_args: &C,
108        client: &mut AsyncOpenStack,
109    ) -> Result<(), OpenStackCliError> {
110        info!("Set Service");
111
112        let op = OutputProcessor::from_args(parsed_args, Some("compute.service"), Some("set"));
113        op.validate_args(parsed_args)?;
114
115        let mut ep_builder = set_253::Request::builder();
116        ep_builder.header(
117            http::header::HeaderName::from_static("openstack-api-version"),
118            http::header::HeaderValue::from_static("compute 2.53"),
119        );
120
121        ep_builder.id(&self.path.id);
122
123        // Set body parameters
124        // Set Request.disabled_reason data
125        if let Some(arg) = &self.disabled_reason {
126            ep_builder.disabled_reason(arg);
127        }
128
129        // Set Request.forced_down data
130        if let Some(arg) = &self.forced_down {
131            ep_builder.forced_down(*arg);
132        }
133
134        // Set Request.status data
135        if let Some(arg) = &self.status {
136            let tmp = match arg {
137                Status::Disabled => set_253::Status::Disabled,
138                Status::Enabled => set_253::Status::Enabled,
139            };
140            ep_builder.status(tmp);
141        }
142
143        let ep = ep_builder
144            .build()
145            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
146
147        let data: serde_json::Value = ep.query_async(client).await?;
148
149        op.output_single::<response::set_253::ServiceResponse>(data.clone())?;
150        // Show command specific hints
151        op.show_command_hint()?;
152        Ok(())
153    }
154}