Skip to main content

openstack_cli_load_balancer/v2/pool/
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 Pool command
19//!
20//! Wraps invoking of the `v2/lbaas/pools/{pool_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::load_balancer::v2::pool::find;
35use openstack_sdk::api::load_balancer::v2::pool::set;
36use openstack_types::load_balancer::v2::pool::response;
37
38/// Update an existing pool.
39///
40/// If the request is valid, the service returns the `Accepted (202)` response
41/// code. To confirm the update, check that the pool provisioning status is
42/// `ACTIVE`. If the status is `PENDING_UPDATE`, use a GET operation to poll
43/// the pool object for changes.
44///
45/// This operation returns the updated pool object with the `ACTIVE`,
46/// `PENDING_UPDATE`, or `ERROR` provisioning status.
47#[derive(Args)]
48#[command(about = "Update a Pool")]
49pub struct PoolCommand {
50    /// Request Query parameters
51    #[command(flatten)]
52    query: QueryParameters,
53
54    /// Path parameters
55    #[command(flatten)]
56    path: PathParameters,
57
58    /// Defines attributes that are acceptable of a PUT request.
59    #[command(flatten)]
60    pool: Pool,
61}
62
63/// Query parameters
64#[derive(Args)]
65struct QueryParameters {}
66
67/// Path parameters
68#[derive(Args)]
69struct PathParameters {
70    /// pool_id parameter for /v2/lbaas/pools/{pool_id} API
71    #[arg(
72        help_heading = "Path parameters",
73        id = "path_param_id",
74        value_name = "ID"
75    )]
76    id: String,
77}
78
79#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
80enum LbAlgorithm {
81    LeastConnections,
82    RoundRobin,
83    SourceIp,
84    SourceIpPort,
85}
86
87#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
88enum Type {
89    AppCookie,
90    HttpCookie,
91    SourceIp,
92}
93
94/// SessionPersistence Body data
95#[derive(Args, Clone)]
96#[group(required = false, multiple = true)]
97struct SessionPersistence {
98    #[arg(help_heading = "Body parameters", long)]
99    cookie_name: Option<String>,
100
101    #[arg(help_heading = "Body parameters", long)]
102    persistence_granularity: Option<String>,
103
104    #[arg(help_heading = "Body parameters", long)]
105    persistence_timeout: Option<i32>,
106
107    #[arg(help_heading = "Body parameters", long)]
108    _type: Option<Type>,
109}
110
111/// Pool Body data
112#[derive(Args, Clone)]
113struct Pool {
114    /// The administrative state of the resource, which is up (`true`) or down
115    /// (`false`). Default is `true`.
116    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
117    admin_state_up: Option<bool>,
118
119    /// A list of ALPN protocols. Available protocols: http/1.0, http/1.1, h2
120    ///
121    /// **New in version 2.24**
122    ///
123    /// Parameter is an array, may be provided multiple times.
124    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
125    alpn_protocols: Option<Vec<String>>,
126
127    /// The reference of the
128    /// [key manager service](https://docs.openstack.org/castellan/latest/)
129    /// secret containing a PEM format CA certificate bundle for `tls_enabled`
130    /// pools.
131    ///
132    /// **New in version 2.8**
133    #[arg(help_heading = "Body parameters", long)]
134    ca_tls_container_ref: Option<String>,
135
136    /// The reference of the
137    /// [key manager service](https://docs.openstack.org/castellan/latest/)
138    /// secret containing a PEM format CA revocation list file for
139    /// `tls_enabled` pools.
140    #[arg(help_heading = "Body parameters", long)]
141    crl_container_ref: Option<String>,
142
143    /// A human-readable description for the resource.
144    #[arg(help_heading = "Body parameters", long)]
145    description: Option<String>,
146
147    /// The load balancing algorithm for the pool. One of `LEAST_CONNECTIONS`,
148    /// `ROUND_ROBIN`, or `SOURCE_IP`.
149    #[arg(help_heading = "Body parameters", long)]
150    lb_algorithm: Option<LbAlgorithm>,
151
152    /// Human-readable name of the resource.
153    #[arg(help_heading = "Body parameters", long)]
154    name: Option<String>,
155
156    /// A JSON object specifying the session persistence for the pool or `null`
157    /// for no session persistence. See
158    /// [Pool Session Persistence](#session-persistence). Default is `null`.
159    #[command(flatten)]
160    session_persistence: Option<SessionPersistence>,
161
162    /// A list of simple strings assigned to the resource.
163    ///
164    /// **New in version 2.5**
165    ///
166    /// Parameter is an array, may be provided multiple times.
167    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
168    tags: Option<Vec<String>>,
169
170    /// List of ciphers in OpenSSL format (colon-separated). See
171    /// <https://www.openssl.org/docs/man1.1.1/man1/ciphers.html>
172    ///
173    /// **New in version 2.15**
174    #[arg(help_heading = "Body parameters", long)]
175    tls_ciphers: Option<String>,
176
177    /// The reference to the
178    /// [key manager service](https://docs.openstack.org/castellan/latest/)
179    /// secret containing a PKCS12 format certificate/key bundle for
180    /// `tls_enabled` pools for TLS client authentication to the member
181    /// servers.
182    ///
183    /// **New in version 2.8**
184    #[arg(help_heading = "Body parameters", long)]
185    tls_container_ref: Option<String>,
186
187    /// When `true` connections to backend member servers will use TLS
188    /// encryption. Default is `false`.
189    ///
190    /// **New in version 2.8**
191    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
192    tls_enabled: Option<bool>,
193
194    /// A list of TLS protocol versions. Available versions: SSLv3, TLSv1,
195    /// TLSv1.1, TLSv1.2, TLSv1.3
196    ///
197    /// **New in version 2.17**
198    ///
199    /// Parameter is an array, may be provided multiple times.
200    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
201    tls_versions: Option<Vec<String>>,
202}
203
204impl PoolCommand {
205    /// Perform command action
206    pub async fn take_action<C: CliArgs>(
207        &self,
208        parsed_args: &C,
209        client: &mut AsyncOpenStack,
210    ) -> Result<(), OpenStackCliError> {
211        info!("Set Pool");
212
213        let op = OutputProcessor::from_args(parsed_args, Some("load-balancer.pool"), Some("set"));
214        op.validate_args(parsed_args)?;
215
216        let mut find_builder = find::Request::builder();
217
218        find_builder.id(&self.path.id);
219
220        let find_ep = find_builder
221            .build()
222            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
223        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
224
225        let mut ep_builder = set::Request::builder();
226
227        let resource_id = find_data["id"]
228            .as_str()
229            .ok_or_else(|| eyre::eyre!("resource ID must be a string"))?
230            .to_string();
231        ep_builder.id(resource_id.clone());
232
233        // Set body parameters
234        // Set Request.pool data
235        let args = &self.pool;
236        let mut pool_builder = set::PoolBuilder::default();
237        if let Some(val) = &args.admin_state_up {
238            pool_builder.admin_state_up(*val);
239        }
240
241        if let Some(val) = &args.alpn_protocols {
242            pool_builder.alpn_protocols(val.iter().map(Into::into).collect::<Vec<_>>());
243        }
244
245        if let Some(val) = &args.ca_tls_container_ref {
246            pool_builder.ca_tls_container_ref(val);
247        }
248
249        if let Some(val) = &args.crl_container_ref {
250            pool_builder.crl_container_ref(val);
251        }
252
253        if let Some(val) = &args.description {
254            pool_builder.description(val);
255        }
256
257        if let Some(val) = &args.lb_algorithm {
258            let tmp = match val {
259                LbAlgorithm::LeastConnections => set::LbAlgorithm::LeastConnections,
260                LbAlgorithm::RoundRobin => set::LbAlgorithm::RoundRobin,
261                LbAlgorithm::SourceIp => set::LbAlgorithm::SourceIp,
262                LbAlgorithm::SourceIpPort => set::LbAlgorithm::SourceIpPort,
263            };
264            pool_builder.lb_algorithm(tmp);
265        }
266
267        if let Some(val) = &args.name {
268            pool_builder.name(val);
269        }
270
271        if let Some(val) = &args.session_persistence {
272            let mut session_persistence_builder = set::SessionPersistenceBuilder::default();
273            if let Some(val) = &val.cookie_name {
274                session_persistence_builder.cookie_name(val);
275            }
276            if let Some(val) = &val.persistence_granularity {
277                session_persistence_builder.persistence_granularity(val);
278            }
279            if let Some(val) = &val.persistence_timeout {
280                session_persistence_builder.persistence_timeout(*val);
281            }
282            if let Some(val) = &val._type {
283                let tmp = match val {
284                    Type::AppCookie => set::Type::AppCookie,
285                    Type::HttpCookie => set::Type::HttpCookie,
286                    Type::SourceIp => set::Type::SourceIp,
287                };
288                session_persistence_builder._type(tmp);
289            }
290            pool_builder.session_persistence(
291                session_persistence_builder
292                    .build()
293                    .wrap_err("error preparing the request data")?,
294            );
295        }
296
297        if let Some(val) = &args.tags {
298            pool_builder.tags(val.iter().map(Into::into).collect::<Vec<_>>());
299        }
300
301        if let Some(val) = &args.tls_ciphers {
302            pool_builder.tls_ciphers(val);
303        }
304
305        if let Some(val) = &args.tls_container_ref {
306            pool_builder.tls_container_ref(val);
307        }
308
309        if let Some(val) = &args.tls_enabled {
310            pool_builder.tls_enabled(*val);
311        }
312
313        if let Some(val) = &args.tls_versions {
314            pool_builder.tls_versions(val.iter().map(Into::into).collect::<Vec<_>>());
315        }
316
317        ep_builder.pool(
318            pool_builder
319                .build()
320                .wrap_err("error preparing the request data")?,
321        );
322
323        let ep = ep_builder
324            .build()
325            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
326
327        let data: serde_json::Value = ep.query_async(client).await?;
328
329        op.output_single::<response::set::PoolResponse>(data.clone())?;
330        // Show command specific hints
331        op.show_command_hint()?;
332        Ok(())
333    }
334}