Skip to main content

openstack_cli_load_balancer/v2/flavor_profile/
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 FlavorProfiles command
19//!
20//! Wraps invoking of the `v2/lbaas/flavorprofiles` 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::load_balancer::v2::flavor_profile::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::load_balancer::v2::flavor_profile::response;
34
35/// Lists all flavor profiles.
36#[derive(Args)]
37pub struct FlavorProfilesCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// Total limit of entities count to return. Use this when there are too many entries.
47    #[arg(long, default_value_t = 10000)]
48    max_items: usize,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {
54    #[arg(help_heading = "Query parameters", long)]
55    flavor_data: Option<String>,
56
57    #[arg(help_heading = "Query parameters", long)]
58    id: Option<String>,
59
60    /// Page size
61    #[arg(
62        help_heading = "Query parameters",
63        long("page-size"),
64        visible_alias("limit")
65    )]
66    limit: Option<i32>,
67
68    /// ID of the last item in the previous list
69    #[arg(help_heading = "Query parameters", long)]
70    marker: Option<String>,
71
72    #[arg(help_heading = "Query parameters", long)]
73    name: Option<String>,
74
75    /// The page direction.
76    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
77    page_reverse: Option<bool>,
78
79    #[arg(help_heading = "Query parameters", long)]
80    provider_name: Option<String>,
81}
82
83/// Path parameters
84#[derive(Args)]
85struct PathParameters {}
86
87impl FlavorProfilesCommand {
88    /// Perform command action
89    pub async fn take_action<C: CliArgs>(
90        &self,
91        parsed_args: &C,
92        client: &mut AsyncOpenStack,
93    ) -> Result<(), OpenStackCliError> {
94        info!("List FlavorProfiles");
95
96        let op = OutputProcessor::from_args(
97            parsed_args,
98            Some("load-balancer.flavor_profile"),
99            Some("list"),
100        );
101        op.validate_args(parsed_args)?;
102
103        let mut ep_builder = list::Request::builder();
104
105        // Set query parameters
106        if let Some(val) = &self.query.flavor_data {
107            ep_builder.flavor_data(val);
108        }
109        if let Some(val) = &self.query.id {
110            ep_builder.id(val);
111        }
112        if let Some(val) = &self.query.limit {
113            ep_builder.limit(*val);
114        }
115        if let Some(val) = &self.query.marker {
116            ep_builder.marker(val);
117        }
118        if let Some(val) = &self.query.name {
119            ep_builder.name(val);
120        }
121        if let Some(val) = &self.query.page_reverse {
122            ep_builder.page_reverse(*val);
123        }
124        if let Some(val) = &self.query.provider_name {
125            ep_builder.provider_name(val);
126        }
127
128        let ep = ep_builder
129            .build()
130            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
131
132        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
133            .query_async(client)
134            .await?;
135
136        op.output_list::<response::list::FlavorProfileResponse>(data.clone())?;
137        // Show command specific hints
138        op.show_command_hint()?;
139        Ok(())
140    }
141}