Skip to main content

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