Skip to main content

openstack_cli_network/v2/qos/policy/
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 Policies command
19//!
20//! Wraps invoking of the `v2.0/qos/policies` 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::network::v2::qos::policy::list;
32use openstack_sdk::api::{Pagination, paged};
33use openstack_types::network::v2::qos::policy::response;
34
35/// Lists all QoS policies associated with your project. One policy can contain
36/// more than one rule type.
37///
38/// The list might be empty.
39///
40/// Standard query parameters are supported on the URI. For more information,
41/// see [Filtering and Column Selection](#filtering).
42///
43/// Use the `fields` query parameter to control which fields are returned in
44/// the response body. For more information, see [Fields](#fields).
45///
46/// Pagination query parameters are supported if Neutron configuration supports
47/// it by overriding `allow_pagination=false`. For more information, see
48/// [Pagination](#pagination).
49///
50/// Sorting query parameters are supported if Neutron configuration supports it
51/// with `allow_sorting=true`. For more information, see [Sorting](#sorting).
52///
53/// Normal response codes: 200
54///
55/// Error response codes: 401
56#[derive(Args)]
57#[command(about = "List QoS policies")]
58pub struct PoliciesCommand {
59    /// Request Query parameters
60    #[command(flatten)]
61    query: QueryParameters,
62
63    /// Path parameters
64    #[command(flatten)]
65    path: PathParameters,
66
67    /// Total limit of entities count to return. Use this when there are too many entries.
68    #[arg(long, default_value_t = 10000)]
69    max_items: usize,
70}
71
72/// Query parameters
73#[derive(Args)]
74struct QueryParameters {
75    /// description query parameter for /v2.0/qos/policies API
76    #[arg(help_heading = "Query parameters", long)]
77    description: Option<String>,
78
79    /// id query parameter for /v2.0/qos/policies API
80    #[arg(help_heading = "Query parameters", long)]
81    id: Option<String>,
82
83    /// is_default query parameter for /v2.0/qos/policies API
84    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
85    is_default: Option<bool>,
86
87    /// Requests a page size of items. Returns a number of items up to a limit
88    /// value. Use the limit parameter to make an initial limited request and
89    /// use the ID of the last-seen item from the response as the marker
90    /// parameter value in a subsequent limited request.
91    #[arg(
92        help_heading = "Query parameters",
93        long("page-size"),
94        visible_alias("limit")
95    )]
96    limit: Option<u32>,
97
98    /// The ID of the last-seen item. Use the limit parameter to make an
99    /// initial limited request and use the ID of the last-seen item from the
100    /// response as the marker parameter value in a subsequent limited request.
101    #[arg(help_heading = "Query parameters", long)]
102    marker: Option<String>,
103
104    /// name query parameter for /v2.0/qos/policies API
105    #[arg(help_heading = "Query parameters", long)]
106    name: Option<String>,
107
108    /// not-tags query parameter for /v2.0/qos/policies API
109    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
110    not_tags: Option<Vec<String>>,
111
112    /// not-tags-any query parameter for /v2.0/qos/policies API
113    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
114    not_tags_any: Option<Vec<String>>,
115
116    /// Reverse the page direction
117    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
118    page_reverse: Option<bool>,
119
120    /// revision_number query parameter for /v2.0/qos/policies API
121    #[arg(help_heading = "Query parameters", long)]
122    revision_number: Option<String>,
123
124    /// shared query parameter for /v2.0/qos/policies API
125    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
126    shared: Option<bool>,
127
128    /// Sort direction. This is an optional feature and may be silently ignored
129    /// by the server.
130    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
131    sort_dir: Option<Vec<String>>,
132
133    /// Sort results by the attribute. This is an optional feature and may be
134    /// silently ignored by the server.
135    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
136    sort_key: Option<Vec<String>>,
137
138    /// tags query parameter for /v2.0/qos/policies API
139    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
140    tags: Option<Vec<String>>,
141
142    /// tags-any query parameter for /v2.0/qos/policies API
143    #[arg(action=clap::ArgAction::Append, help_heading = "Query parameters", long)]
144    tags_any: Option<Vec<String>>,
145
146    /// tenant_id query parameter for /v2.0/qos/policies API
147    #[arg(help_heading = "Query parameters", long)]
148    tenant_id: Option<String>,
149}
150
151/// Path parameters
152#[derive(Args)]
153struct PathParameters {}
154
155impl PoliciesCommand {
156    /// Perform command action
157    pub async fn take_action<C: CliArgs>(
158        &self,
159        parsed_args: &C,
160        client: &mut AsyncOpenStack,
161    ) -> Result<(), OpenStackCliError> {
162        info!("List Policies");
163
164        let op = OutputProcessor::from_args(parsed_args, Some("network.qos/policy"), Some("list"));
165        op.validate_args(parsed_args)?;
166
167        let mut ep_builder = list::Request::builder();
168
169        // Set query parameters
170        if let Some(val) = &self.query.limit {
171            ep_builder.limit(*val);
172        }
173        if let Some(val) = &self.query.marker {
174            ep_builder.marker(val);
175        }
176        if let Some(val) = &self.query.page_reverse {
177            ep_builder.page_reverse(*val);
178        }
179        if let Some(val) = &self.query.description {
180            ep_builder.description(val);
181        }
182        if let Some(val) = &self.query.id {
183            ep_builder.id(val);
184        }
185        if let Some(val) = &self.query.is_default {
186            ep_builder.is_default(*val);
187        }
188        if let Some(val) = &self.query.name {
189            ep_builder.name(val);
190        }
191        if let Some(val) = &self.query.not_tags {
192            ep_builder.not_tags(val.iter());
193        }
194        if let Some(val) = &self.query.not_tags_any {
195            ep_builder.not_tags_any(val.iter());
196        }
197        if let Some(val) = &self.query.revision_number {
198            ep_builder.revision_number(val);
199        }
200        if let Some(val) = &self.query.shared {
201            ep_builder.shared(*val);
202        }
203        if let Some(val) = &self.query.tags {
204            ep_builder.tags(val.iter());
205        }
206        if let Some(val) = &self.query.tags_any {
207            ep_builder.tags_any(val.iter());
208        }
209        if let Some(val) = &self.query.tenant_id {
210            ep_builder.tenant_id(val);
211        }
212        if let Some(val) = &self.query.sort_dir {
213            ep_builder.sort_dir(val.iter());
214        }
215        if let Some(val) = &self.query.sort_key {
216            ep_builder.sort_key(val.iter());
217        }
218
219        let ep = ep_builder
220            .build()
221            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
222
223        let data: Vec<serde_json::Value> = paged(ep, Pagination::Limit(self.max_items))
224            .query_async(client)
225            .await?;
226
227        op.output_list::<response::list::PolicyResponse>(data.clone())?;
228        // Show command specific hints
229        op.show_command_hint()?;
230        Ok(())
231    }
232}