Skip to main content

openstack_cli_network/v2/vpn/ipsec_site_connection/
create.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//! Create IpsecSiteConnection command
19//!
20//! Wraps invoking of the `v2.0/vpn/ipsec-site-connections` with `POST` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use clap::ValueEnum;
32use openstack_sdk::api::QueryAsync;
33use openstack_sdk::api::network::v2::vpn::ipsec_site_connection::create;
34use openstack_types::network::v2::vpn::ipsec_site_connection::response;
35
36/// Creates a site-to-site IPsec connection for a service.
37///
38/// Normal response codes: 201
39///
40/// Error response codes: 400, 401
41#[derive(Args)]
42#[command(about = "Create IPsec connection")]
43pub struct IpsecSiteConnectionCommand {
44    /// Request Query parameters
45    #[command(flatten)]
46    query: QueryParameters,
47
48    /// Path parameters
49    #[command(flatten)]
50    path: PathParameters,
51
52    /// An `ipsec_site_connection` object.
53    #[command(flatten)]
54    ipsec_site_connection: IpsecSiteConnection,
55}
56
57/// Query parameters
58#[derive(Args)]
59struct QueryParameters {}
60
61/// Path parameters
62#[derive(Args)]
63struct PathParameters {}
64
65#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
66enum Initiator {
67    BiDirectional,
68    ResponseOnly,
69}
70
71/// IpsecSiteConnection Body data
72#[derive(Args, Clone)]
73struct IpsecSiteConnection {
74    /// The administrative state of the resource, which is up (`true`) or down
75    /// (`false`).
76    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
77    admin_state_up: Option<bool>,
78
79    /// A human-readable description for the resource. Default is an empty
80    /// string.
81    #[arg(help_heading = "Body parameters", long)]
82    description: Option<String>,
83
84    /// A dictionary with dead peer detection (DPD) protocol controls.
85    #[arg(help_heading = "Body parameters", long)]
86    dpd: Option<String>,
87
88    /// The ID of the IKE policy.
89    #[arg(help_heading = "Body parameters", long)]
90    ikepolicy_id: Option<String>,
91
92    /// Indicates whether this VPN can only respond to connections or both
93    /// respond to and initiate connections. A valid value is `response- only`
94    /// or `bi-directional`. Default is `bi-directional`.
95    #[arg(help_heading = "Body parameters", long)]
96    initiator: Option<Initiator>,
97
98    /// The ID of the IPsec policy.
99    #[arg(help_heading = "Body parameters", long)]
100    ipsecpolicy_id: Option<String>,
101
102    /// The ID for the endpoint group that contains private subnets for the
103    /// local side of the connection. Yo must specify this parameter with the
104    /// `peer_ep_group_id` parameter unless in backward- compatible mode where
105    /// `peer_cidrs` is provided with a `subnet_id` for the VPN service.
106    #[arg(help_heading = "Body parameters", long)]
107    local_ep_group_id: Option<String>,
108
109    /// Set explicit NULL for the local_ep_group_id
110    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "local_ep_group_id")]
111    no_local_ep_group_id: bool,
112
113    /// An ID to be used instead of the external IP address for a virtual
114    /// router used in traffic between instances on different networks in
115    /// east-west traffic. Most often, local ID would be domain name, email
116    /// address, etc. If this is not configured then the external IP address
117    /// will be used as the ID.
118    #[arg(help_heading = "Body parameters", long)]
119    local_id: Option<String>,
120
121    /// The maximum transmission unit (MTU) value to address fragmentation.
122    /// Minimum value is 68 for IPv4, and 1280 for IPv6.
123    #[arg(help_heading = "Body parameters", long)]
124    mtu: Option<u32>,
125
126    /// Human-readable name of the resource. Default is an empty string.
127    #[arg(help_heading = "Body parameters", long)]
128    name: Option<String>,
129
130    /// The peer gateway public IPv4 or IPv6 address or FQDN.
131    #[arg(help_heading = "Body parameters", long)]
132    peer_address: Option<String>,
133
134    /// (Deprecated) Unique list of valid peer private CIDRs in the form \<
135    /// net_address > / < prefix > .
136    ///
137    /// Parameter is an array, may be provided multiple times.
138    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
139    peer_cidrs: Option<Vec<String>>,
140
141    /// The ID for the endpoint group that contains private CIDRs in the form
142    /// \< net_address > / < prefix > for the peer side of the connection. You
143    /// must specify this parameter with the `local_ep_group_id` parameter
144    /// unless in backward-compatible mode where `peer_cidrs` is provided with
145    /// a `subnet_id` for the VPN service.
146    #[arg(help_heading = "Body parameters", long)]
147    peer_ep_group_id: Option<String>,
148
149    /// Set explicit NULL for the peer_ep_group_id
150    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "peer_ep_group_id")]
151    no_peer_ep_group_id: bool,
152
153    /// The peer router identity for authentication. A valid value is an IPv4
154    /// address, IPv6 address, e-mail address, key ID, or FQDN. Typically, this
155    /// value matches the `peer_address` value.
156    #[arg(help_heading = "Body parameters", long)]
157    peer_id: Option<String>,
158
159    /// The pre-shared key. A valid value is any string.
160    #[arg(help_heading = "Body parameters", long)]
161    psk: Option<String>,
162
163    /// The ID of the project.
164    #[arg(help_heading = "Body parameters", long)]
165    tenant_id: Option<String>,
166
167    /// The ID of the VPN service.
168    #[arg(help_heading = "Body parameters", long)]
169    vpnservice_id: Option<String>,
170}
171
172impl IpsecSiteConnectionCommand {
173    /// Perform command action
174    pub async fn take_action<C: CliArgs>(
175        &self,
176        parsed_args: &C,
177        client: &mut AsyncOpenStack,
178    ) -> Result<(), OpenStackCliError> {
179        info!("Create IpsecSiteConnection");
180
181        let op = OutputProcessor::from_args(
182            parsed_args,
183            Some("network.vpn/ipsec_site_connection"),
184            Some("create"),
185        );
186        op.validate_args(parsed_args)?;
187
188        let mut ep_builder = create::Request::builder();
189
190        // Set body parameters
191        // Set Request.ipsec_site_connection data
192        let args = &self.ipsec_site_connection;
193        let mut ipsec_site_connection_builder = create::IpsecSiteConnectionBuilder::default();
194        if let Some(val) = &args.admin_state_up {
195            ipsec_site_connection_builder.admin_state_up(*val);
196        }
197
198        if let Some(val) = &args.description {
199            ipsec_site_connection_builder.description(val);
200        }
201
202        if let Some(val) = &args.dpd {
203            ipsec_site_connection_builder.dpd(val);
204        }
205
206        if let Some(val) = &args.ikepolicy_id {
207            ipsec_site_connection_builder.ikepolicy_id(val);
208        }
209
210        if let Some(val) = &args.initiator {
211            let tmp = match val {
212                Initiator::BiDirectional => create::Initiator::BiDirectional,
213                Initiator::ResponseOnly => create::Initiator::ResponseOnly,
214            };
215            ipsec_site_connection_builder.initiator(tmp);
216        }
217
218        if let Some(val) = &args.ipsecpolicy_id {
219            ipsec_site_connection_builder.ipsecpolicy_id(val);
220        }
221
222        if let Some(val) = &args.local_ep_group_id {
223            ipsec_site_connection_builder.local_ep_group_id(Some(val.into()));
224        } else if args.no_local_ep_group_id {
225            ipsec_site_connection_builder.local_ep_group_id(None);
226        }
227
228        if let Some(val) = &args.local_id {
229            ipsec_site_connection_builder.local_id(val);
230        }
231
232        if let Some(val) = &args.mtu {
233            ipsec_site_connection_builder.mtu(*val);
234        }
235
236        if let Some(val) = &args.name {
237            ipsec_site_connection_builder.name(val);
238        }
239
240        if let Some(val) = &args.peer_address {
241            ipsec_site_connection_builder.peer_address(val);
242        }
243
244        if let Some(val) = &args.peer_cidrs {
245            ipsec_site_connection_builder
246                .peer_cidrs(val.iter().map(Into::into).collect::<Vec<_>>());
247        }
248
249        if let Some(val) = &args.peer_ep_group_id {
250            ipsec_site_connection_builder.peer_ep_group_id(Some(val.into()));
251        } else if args.no_peer_ep_group_id {
252            ipsec_site_connection_builder.peer_ep_group_id(None);
253        }
254
255        if let Some(val) = &args.peer_id {
256            ipsec_site_connection_builder.peer_id(val);
257        }
258
259        if let Some(val) = &args.psk {
260            ipsec_site_connection_builder.psk(val);
261        }
262
263        if let Some(val) = &args.tenant_id {
264            ipsec_site_connection_builder.tenant_id(val);
265        }
266
267        if let Some(val) = &args.vpnservice_id {
268            ipsec_site_connection_builder.vpnservice_id(val);
269        }
270
271        ep_builder.ipsec_site_connection(
272            ipsec_site_connection_builder
273                .build()
274                .wrap_err("error preparing the request data")?,
275        );
276
277        let ep = ep_builder
278            .build()
279            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
280
281        let data: serde_json::Value = ep.query_async(client).await?;
282
283        op.output_single::<response::create::IpsecSiteConnectionResponse>(data.clone())?;
284        // Show command specific hints
285        op.show_command_hint()?;
286        Ok(())
287    }
288}