Skip to main content

openstack_cli_block_storage/v3/cluster/
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 Clusters command
19//!
20//! Wraps invoking of the `v3/clusters/detail` 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::block_storage::v3::cluster::list_detailed;
32use openstack_types::block_storage::v3::cluster::response;
33
34/// Return a detailed list of all existing clusters.
35///
36/// Filter by is_up, disabled, num_hosts, and num_down_hosts.
37#[derive(Args)]
38pub struct ClustersCommand {
39    /// Request Query parameters
40    #[command(flatten)]
41    query: QueryParameters,
42
43    /// Path parameters
44    #[command(flatten)]
45    path: PathParameters,
46}
47
48/// Query parameters
49#[derive(Args)]
50struct QueryParameters {
51    /// The ID of active storage backend. Only in cinder-volume service.
52    #[arg(help_heading = "Query parameters", long)]
53    active_backend_id: Option<String>,
54
55    /// Filter the cluster list result by binary name of the clustered
56    /// services. One of cinder-api, cinder-scheduler, cinder-volume or
57    /// cinder-backup.
58    #[arg(help_heading = "Query parameters", long, value_parser = ["cinder-api","cinder-backup","cinder-scheduler","cinder-volume"])]
59    binary: Option<String>,
60
61    /// Filter the cluster list result by status.
62    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
63    disabled: Option<bool>,
64
65    /// Whether the cluster is frozen or not.
66    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
67    frozen: Option<bool>,
68
69    /// Filter the cluster list result by state.
70    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
71    is_up: Option<bool>,
72
73    /// Filter the cluster list result by cluster name.
74    #[arg(help_heading = "Query parameters", long)]
75    name: Option<String>,
76
77    /// Filter the cluster list result by number of down hosts.
78    #[arg(help_heading = "Query parameters", long)]
79    num_down_hosts: Option<f32>,
80
81    /// Filter the cluster list result by number of hosts.
82    #[arg(help_heading = "Query parameters", long)]
83    num_hosts: Option<f32>,
84
85    /// Filter the cluster list result by replication status.
86    #[arg(help_heading = "Query parameters", long, value_parser = ["disabled","enabled"])]
87    replication_stats: Option<String>,
88}
89
90/// Path parameters
91#[derive(Args)]
92struct PathParameters {}
93
94impl ClustersCommand {
95    /// Perform command action
96    pub async fn take_action<C: CliArgs>(
97        &self,
98        parsed_args: &C,
99        client: &mut AsyncOpenStack,
100    ) -> Result<(), OpenStackCliError> {
101        info!("List Clusters");
102
103        let op =
104            OutputProcessor::from_args(parsed_args, Some("block-storage.cluster"), Some("list"));
105        op.validate_args(parsed_args)?;
106
107        let mut ep_builder = list_detailed::Request::builder();
108
109        // Set query parameters
110        if let Some(val) = &self.query.active_backend_id {
111            ep_builder.active_backend_id(val);
112        }
113        if let Some(val) = &self.query.binary {
114            ep_builder.binary(val);
115        }
116        if let Some(val) = &self.query.disabled {
117            ep_builder.disabled(*val);
118        }
119        if let Some(val) = &self.query.frozen {
120            ep_builder.frozen(*val);
121        }
122        if let Some(val) = &self.query.is_up {
123            ep_builder.is_up(*val);
124        }
125        if let Some(val) = &self.query.name {
126            ep_builder.name(val);
127        }
128        if let Some(val) = &self.query.num_down_hosts {
129            ep_builder.num_down_hosts(*val);
130        }
131        if let Some(val) = &self.query.num_hosts {
132            ep_builder.num_hosts(*val);
133        }
134        if let Some(val) = &self.query.replication_stats {
135            ep_builder.replication_stats(val);
136        }
137
138        let ep = ep_builder
139            .build()
140            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
141
142        let data: Vec<serde_json::Value> = ep.query_async(client).await?;
143
144        op.output_list::<response::list_detailed::ClusterResponse>(data.clone())?;
145        // Show command specific hints
146        op.show_command_hint()?;
147        Ok(())
148    }
149}