openstack_cli_load_balancer/v2/pool/member/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 Member command
19//!
20//! Wraps invoking of the `v2/lbaas/pools/{pool_id}/members` 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 openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::load_balancer::v2::pool::member::create;
33use openstack_types::load_balancer::v2::pool::member::response;
34
35/// This operation provisions a member and adds it to a pool by using the
36/// configuration that you define in the request object. After the API
37/// validates the request and starts the provisioning process, it returns a
38/// response object, which contains a unique ID.
39///
40/// In the response, the member [provisioning status](#prov-status) is
41/// `ACTIVE`, `PENDING_CREATE`, or `ERROR`.
42///
43/// If the status is `PENDING_CREATE`, issue GET
44/// `/v2/lbaas/pools/{pool_id}/members/{member_id}` to view the progress of the
45/// provisioning operation. When the member status changes to `ACTIVE`, the
46/// member is successfully provisioned and is ready for further configuration.
47///
48/// If the API cannot fulfill the request due to insufficient data or data that
49/// is not valid, the service returns the HTTP `Bad Request (400)` response
50/// code with information about the failure in the response body. Validation
51/// errors require that you correct the error and submit the request again.
52///
53/// At a minimum, you must specify these member attributes:
54///
55/// Some attributes receive default values if you omit them from the request:
56///
57/// If you omit the `subnet_id` parameter, the `vip_subnet_id` for the parent
58/// load balancer will be used for the member subnet UUID.
59///
60/// The member `address` does not necessarily need to be a member of the
61/// `subnet_id` subnet. Members can be routable from the subnet specified
62/// either via the default route or by using `host_routes` defined on the
63/// subnet.
64///
65/// Administrative users can specify a project ID that is different than their
66/// own to create members for other projects.
67///
68/// `monitor_address` and/or `monitor_port` can be used to have the health
69/// monitor, if one is configured for the pool, connect to an alternate IP
70/// address and port when executing a health check on the member.
71///
72/// To create a member, the load balancer must have an `ACTIVE` provisioning
73/// status.
74#[derive(Args)]
75#[command(about = "Create Member")]
76pub struct MemberCommand {
77 /// Request Query parameters
78 #[command(flatten)]
79 query: QueryParameters,
80
81 /// Path parameters
82 #[command(flatten)]
83 path: PathParameters,
84
85 /// Defines mandatory and optional attributes of a POST request.
86 #[command(flatten)]
87 member: Member,
88}
89
90/// Query parameters
91#[derive(Args)]
92struct QueryParameters {}
93
94/// Path parameters
95#[derive(Args)]
96struct PathParameters {
97 /// pool_id parameter for /v2/lbaas/pools/{pool_id}/members/{member_id} API
98 #[arg(
99 help_heading = "Path parameters",
100 id = "path_param_pool_id",
101 value_name = "POOL_ID"
102 )]
103 pool_id: String,
104}
105/// Member Body data
106#[derive(Args, Clone)]
107struct Member {
108 /// The IP address of the resource.
109 #[arg(help_heading = "Body parameters", long)]
110 address: String,
111
112 /// The administrative state of the resource, which is up (`true`) or down
113 /// (`false`). Default is `true`.
114 #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
115 admin_state_up: Option<bool>,
116
117 /// Is the member a backup? Backup members only receive traffic when all
118 /// non-backup members are down.
119 ///
120 /// **New in version 2.1**
121 #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
122 backup: Option<bool>,
123
124 /// An alternate IP address used for health monitoring a backend member.
125 /// Default is `null` which monitors the member `address`.
126 #[arg(help_heading = "Body parameters", long)]
127 monitor_address: Option<String>,
128
129 /// An alternate protocol port used for health monitoring a backend member.
130 /// Default is `null` which monitors the member `protocol_port`.
131 #[arg(help_heading = "Body parameters", long)]
132 monitor_port: Option<i32>,
133
134 /// Human-readable name of the resource.
135 #[arg(help_heading = "Body parameters", long)]
136 name: Option<String>,
137
138 /// The ID of the project owning this resource. (deprecated)
139 #[arg(help_heading = "Body parameters", long)]
140 project_id: Option<String>,
141
142 /// The protocol port number for the resource.
143 #[arg(help_heading = "Body parameters", long)]
144 protocol_port: i32,
145
146 /// Request that an SR-IOV VF be used for the member network port. Defaults
147 /// to `false`.
148 ///
149 /// **New in version 2.29**
150 #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
151 request_sriov: Option<bool>,
152
153 /// The subnet ID the member service is accessible from.
154 #[arg(help_heading = "Body parameters", long)]
155 subnet_id: Option<String>,
156
157 /// A list of simple strings assigned to the resource.
158 ///
159 /// **New in version 2.5**
160 ///
161 /// Parameter is an array, may be provided multiple times.
162 #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
163 tags: Option<Vec<String>>,
164
165 #[arg(help_heading = "Body parameters", long)]
166 tenant_id: Option<String>,
167
168 /// The weight of a member determines the portion of requests or
169 /// connections it services compared to the other members of the pool. For
170 /// example, a member with a weight of 10 receives five times as many
171 /// requests as a member with a weight of 2. A value of 0 means the member
172 /// does not receive new connections but continues to service existing
173 /// connections. A valid value is from `0` to `256`. Default is `1`.
174 #[arg(help_heading = "Body parameters", long)]
175 weight: Option<i32>,
176}
177
178impl MemberCommand {
179 /// Perform command action
180 pub async fn take_action<C: CliArgs>(
181 &self,
182 parsed_args: &C,
183 client: &mut AsyncOpenStack,
184 ) -> Result<(), OpenStackCliError> {
185 info!("Create Member");
186
187 let op = OutputProcessor::from_args(
188 parsed_args,
189 Some("load-balancer.pool/member"),
190 Some("create"),
191 );
192 op.validate_args(parsed_args)?;
193
194 let mut ep_builder = create::Request::builder();
195
196 ep_builder.pool_id(&self.path.pool_id);
197
198 // Set body parameters
199 // Set Request.member data
200 let args = &self.member;
201 let mut member_builder = create::MemberBuilder::default();
202
203 member_builder.address(&args.address);
204
205 if let Some(val) = &args.admin_state_up {
206 member_builder.admin_state_up(*val);
207 }
208
209 if let Some(val) = &args.backup {
210 member_builder.backup(*val);
211 }
212
213 if let Some(val) = &args.monitor_address {
214 member_builder.monitor_address(val);
215 }
216
217 if let Some(val) = &args.monitor_port {
218 member_builder.monitor_port(*val);
219 }
220
221 if let Some(val) = &args.name {
222 member_builder.name(val);
223 }
224
225 if let Some(val) = &args.project_id {
226 member_builder.project_id(val);
227 }
228
229 member_builder.protocol_port(args.protocol_port);
230
231 if let Some(val) = &args.request_sriov {
232 member_builder.request_sriov(*val);
233 }
234
235 if let Some(val) = &args.subnet_id {
236 member_builder.subnet_id(val);
237 }
238
239 if let Some(val) = &args.tags {
240 member_builder.tags(val.iter().map(Into::into).collect::<Vec<_>>());
241 }
242
243 if let Some(val) = &args.tenant_id {
244 member_builder.tenant_id(val);
245 }
246
247 if let Some(val) = &args.weight {
248 member_builder.weight(*val);
249 }
250
251 ep_builder.member(
252 member_builder
253 .build()
254 .wrap_err("error preparing the request data")?,
255 );
256
257 let ep = ep_builder
258 .build()
259 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
260
261 let data: serde_json::Value = ep.query_async(client).await?;
262
263 op.output_single::<response::create::MemberResponse>(data.clone())?;
264 // Show command specific hints
265 op.show_command_hint()?;
266 Ok(())
267 }
268}