openstack_cli_compute/v2/service/delete.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//! Delete Service command
19//!
20//! Wraps invoking of the `v2.1/os-services/{id}` with `DELETE` 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::delete;
32
33/// Deletes a service. If it’s a `nova-compute` service, then the corresponding
34/// host will be removed from all the host aggregates as well.
35///
36/// Attempts to delete a `nova-compute` service which is still hosting
37/// instances will result in a 409 HTTPConflict response. The instances will
38/// need to be migrated or deleted before a compute service can be deleted.
39///
40/// Similarly, attempts to delete a `nova-compute` service which is involved in
41/// in-progress migrations will result in a 409 HTTPConflict response. The
42/// migrations will need to be completed, for example confirming or reverting a
43/// resize, or the instances will need to be deleted before the compute service
44/// can be deleted.
45///
46/// Normal response codes: 204
47///
48/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
49/// itemNotFound(404), conflict(409)
50#[derive(Args)]
51#[command(about = "Delete Compute Service")]
52pub struct ServiceCommand {
53 /// Request Query parameters
54 #[command(flatten)]
55 query: QueryParameters,
56
57 /// Path parameters
58 #[command(flatten)]
59 path: PathParameters,
60}
61
62/// Query parameters
63#[derive(Args)]
64struct QueryParameters {}
65
66/// Path parameters
67#[derive(Args)]
68struct PathParameters {
69 /// id parameter for /v2.1/os-services/{id} API
70 #[arg(
71 help_heading = "Path parameters",
72 id = "path_param_id",
73 value_name = "ID"
74 )]
75 id: String,
76}
77
78impl ServiceCommand {
79 /// Perform command action
80 pub async fn take_action<C: CliArgs>(
81 &self,
82 parsed_args: &C,
83 client: &mut AsyncOpenStack,
84 ) -> Result<(), OpenStackCliError> {
85 info!("Delete Service");
86
87 let op = OutputProcessor::from_args(parsed_args, Some("compute.service"), Some("delete"));
88 op.validate_args(parsed_args)?;
89
90 let mut ep_builder = delete::Request::builder();
91
92 ep_builder.id(&self.path.id);
93
94 let ep = ep_builder
95 .build()
96 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
97 openstack_sdk::api::ignore(ep).query_async(client).await?;
98 // Show command specific hints
99 op.show_command_hint()?;
100 Ok(())
101 }
102}