Skip to main content

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