Skip to main content

openstack_cli_network/v2/vpn/vpnservice/
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 Vpnservice command
19//!
20//! Wraps invoking of the `v2.0/vpn/vpnservices/{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 openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::find;
33use openstack_sdk::api::network::v2::vpn::vpnservice::find;
34use openstack_sdk::api::network::v2::vpn::vpnservice::set;
35use openstack_types::network::v2::vpn::vpnservice::response;
36
37/// Updates a VPN service.
38///
39/// Updates the attributes of a VPN service. You cannot update a service with a
40/// `PENDING_*` status.
41///
42/// Normal response codes: 200
43///
44/// Error response codes: 400, 401, 404
45#[derive(Args)]
46#[command(about = "Update VPN service")]
47pub struct VpnserviceCommand {
48    /// Request Query parameters
49    #[command(flatten)]
50    query: QueryParameters,
51
52    /// Path parameters
53    #[command(flatten)]
54    path: PathParameters,
55
56    /// A `vpnservice` object.
57    #[command(flatten)]
58    vpnservice: Vpnservice,
59}
60
61/// Query parameters
62#[derive(Args)]
63struct QueryParameters {}
64
65/// Path parameters
66#[derive(Args)]
67struct PathParameters {
68    /// id parameter for /v2.0/vpn/vpnservices/{id} API
69    #[arg(
70        help_heading = "Path parameters",
71        id = "path_param_id",
72        value_name = "ID"
73    )]
74    id: String,
75}
76/// Vpnservice Body data
77#[derive(Args, Clone)]
78struct Vpnservice {
79    /// The administrative state of the resource, which is up (`true`) or down
80    /// (`false`).
81    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
82    admin_state_up: Option<bool>,
83
84    /// A human-readable description for the resource. Default is an empty
85    /// string.
86    #[arg(help_heading = "Body parameters", long)]
87    description: Option<String>,
88
89    /// Human-readable name of the resource. Default is an empty string.
90    #[arg(help_heading = "Body parameters", long)]
91    name: Option<String>,
92}
93
94impl VpnserviceCommand {
95    /// Perform command action
96    pub async fn take_action<C: CliArgs>(
97        &self,
98        parsed_args: &C,
99        client: &mut AsyncOpenStack,
100    ) -> Result<(), OpenStackCliError> {
101        info!("Set Vpnservice");
102
103        let op =
104            OutputProcessor::from_args(parsed_args, Some("network.vpn/vpnservice"), Some("set"));
105        op.validate_args(parsed_args)?;
106
107        let mut find_builder = find::Request::builder();
108
109        find_builder.id(&self.path.id);
110
111        let find_ep = find_builder
112            .build()
113            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
114        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
115
116        let mut ep_builder = set::Request::builder();
117
118        let resource_id = find_data["id"]
119            .as_str()
120            .ok_or_else(|| eyre::eyre!("resource ID must be a string"))?
121            .to_string();
122        ep_builder.id(resource_id.clone());
123
124        // Set body parameters
125        // Set Request.vpnservice data
126        let args = &self.vpnservice;
127        let mut vpnservice_builder = set::VpnserviceBuilder::default();
128        if let Some(val) = &args.admin_state_up {
129            vpnservice_builder.admin_state_up(*val);
130        }
131
132        if let Some(val) = &args.description {
133            vpnservice_builder.description(val);
134        }
135
136        if let Some(val) = &args.name {
137            vpnservice_builder.name(val);
138        }
139
140        ep_builder.vpnservice(
141            vpnservice_builder
142                .build()
143                .wrap_err("error preparing the request data")?,
144        );
145
146        let ep = ep_builder
147            .build()
148            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
149
150        let data: serde_json::Value = ep.query_async(client).await?;
151
152        op.output_single::<response::set::VpnserviceResponse>(data.clone())?;
153        // Show command specific hints
154        op.show_command_hint()?;
155        Ok(())
156    }
157}