Skip to main content

openstack_cli_compute/v2/service/
list.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//! List Services command
19//!
20//! Wraps invoking of the `v2.1/os-services` with `GET` 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::list;
32use openstack_types::compute::v2::service::response;
33
34/// Lists all running Compute services.
35///
36/// Provides details why any services were disabled.
37///
38/// Normal response codes: 200
39///
40/// Error response codes: unauthorized(401), forbidden(403)
41#[derive(Args)]
42#[command(about = "List Compute Services")]
43pub struct ServicesCommand {
44    /// Request Query parameters
45    #[command(flatten)]
46    query: QueryParameters,
47
48    /// Path parameters
49    #[command(flatten)]
50    path: PathParameters,
51}
52
53/// Query parameters
54#[derive(Args)]
55struct QueryParameters {
56    #[arg(help_heading = "Query parameters", long)]
57    binary: Option<String>,
58
59    #[arg(help_heading = "Query parameters", long)]
60    host: Option<String>,
61}
62
63/// Path parameters
64#[derive(Args)]
65struct PathParameters {}
66
67impl ServicesCommand {
68    /// Perform command action
69    pub async fn take_action<C: CliArgs>(
70        &self,
71        parsed_args: &C,
72        client: &mut AsyncOpenStack,
73    ) -> Result<(), OpenStackCliError> {
74        info!("List Services");
75
76        let op = OutputProcessor::from_args(parsed_args, Some("compute.service"), Some("list"));
77        op.validate_args(parsed_args)?;
78
79        let mut ep_builder = list::Request::builder();
80
81        // Set query parameters
82        if let Some(val) = &self.query.binary {
83            ep_builder.binary(val);
84        }
85        if let Some(val) = &self.query.host {
86            ep_builder.host(val);
87        }
88
89        let ep = ep_builder
90            .build()
91            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
92
93        let data: Vec<serde_json::Value> = ep.query_async(client).await?;
94
95        op.output_list::<response::list_20::ServiceResponse>(data.clone())
96            .or_else(|_| op.output_list::<response::list_211::ServiceResponse>(data.clone()))
97            .or_else(|_| op.output_list::<response::list_253::ServiceResponse>(data.clone()))
98            .or_else(|_| op.output_list::<response::list_269::ServiceResponse>(data.clone()))?;
99        // Show command specific hints
100        op.show_command_hint()?;
101        Ok(())
102    }
103}