Skip to main content

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