openstack_cli 0.13.5

OpenStack client rewritten in Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.

//! Create Cluster command
//!
//! Wraps invoking of the `v1/clusters` with `POST` method

use clap::Args;
use tracing::info;

use openstack_sdk::AsyncOpenStack;

use crate::Cli;
use crate::OpenStackCliError;
use crate::output::OutputProcessor;

use crate::common::parse_key_val;
use clap::ValueEnum;
use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::container_infrastructure_management::v1::cluster::create;
use openstack_types::container_infrastructure_management::v1::cluster::response::create::ClusterResponse;
use serde_json::Value;

/// Create new cluster based on cluster template.
#[derive(Args)]
#[command(about = "Create new cluster")]
pub struct ClusterCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

    /// Path parameters
    #[command(flatten)]
    path: PathParameters,

    #[arg(help_heading = "Body parameters", long)]
    api_address: Option<String>,

    /// The UUID of the cluster template.
    #[arg(help_heading = "Body parameters", long)]
    cluster_template_id: String,

    #[arg(help_heading = "Body parameters", long)]
    coe_version: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    container_version: Option<String>,

    /// The timeout for cluster creation in minutes. The value expected is a
    /// positive integer and the default is 60 minutes. If the timeout is
    /// reached during cluster creation process, the operation will be aborted
    /// and the cluster status will be set to `CREATE_FAILED`.
    #[arg(help_heading = "Body parameters", long)]
    create_timeout: Option<i32>,

    #[arg(help_heading = "Body parameters", long)]
    created_at: Option<String>,

    /// The custom discovery url for node discovery. This is used by the COE to
    /// discover the servers that have been created to host the containers. The
    /// actual discovery mechanism varies with the COE. In some cases, Magnum
    /// fills in the server info in the discovery service. In other cases, if
    /// the `discovery_url` is not specified, Magnum will use the public
    /// discovery service at:
    ///
    /// ```text
    /// https://discovery.etcd.io
    /// ```
    ///
    /// In this case, Magnum will generate a unique url here for each uster and
    /// store the info for the servers.
    #[arg(help_heading = "Body parameters", long)]
    discovery_url: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    docker_volume_size: Option<i32>,

    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
    faults: Option<Vec<(String, String)>>,

    /// The name or network ID of a Neutron network to provide connectivity to
    /// the internal network for the cluster.
    #[arg(help_heading = "Body parameters", long)]
    fixed_network: Option<String>,

    /// Fixed subnet that are using to allocate network address for nodes in
    /// cluster.
    #[arg(help_heading = "Body parameters", long)]
    fixed_subnet: Option<String>,

    /// The nova flavor ID or name for booting the node servers. The default is
    /// `m1.small`.
    #[arg(help_heading = "Body parameters", long)]
    flavor_id: Option<String>,

    /// Whether enable or not using the floating IP of cloud provider. Some
    /// cloud providers used floating IP, some used public IP, thus Magnum
    /// provide this option for specifying the choice of using floating IP. If
    /// it’s not set, the value of floating_ip_enabled in template will be
    /// used.
    #[arg(help_heading = "Body parameters", long)]
    floating_ip_enabled: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    health_status: Option<HealthStatus>,

    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
    health_status_reason: Option<Vec<(String, String)>>,

    /// The name of the SSH keypair to configure in the cluster servers for ssh
    /// access. Users will need the key to be able to ssh to the servers in the
    /// cluster. The login name is specific to the cluster driver, for example
    /// with fedora-atomic image, default login name is `fedora`.
    #[arg(help_heading = "Body parameters", long)]
    keypair: Option<String>,

    /// Arbitrary labels in the form of `key=value` pairs. The accepted keys
    /// and valid values are defined in the cluster drivers. They are used as a
    /// way to pass additional parameters that are specific to a cluster
    /// driver.
    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
    labels: Option<Vec<(String, String)>>,

    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
    labels_added: Option<Vec<(String, String)>>,

    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
    labels_overridden: Option<Vec<(String, String)>>,

    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, String>)]
    labels_skipped: Option<Vec<(String, String)>>,

    /// Parameter is an array, may be provided multiple times.
    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long, value_name="JSON", value_parser=crate::common::parse_json)]
    links: Option<Vec<Value>>,

    /// Parameter is an array, may be provided multiple times.
    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
    master_addresses: Option<Vec<String>>,

    /// The number of servers that will serve as master for the cluster. The
    /// default is 1. Set to more than 1 master to enable High Availability. If
    /// the option `master-lb-enabled` is specified in the cluster template,
    /// the master servers will be placed in a load balancer pool.
    #[arg(help_heading = "Body parameters", long)]
    master_count: Option<i32>,

    /// The flavor of the master node for this cluster template.
    #[arg(help_heading = "Body parameters", long)]
    master_flavor_id: Option<String>,

    /// Since multiple masters may exist in a cluster, a Neutron load balancer
    /// is created to provide the API endpoint for the cluster and to direct
    /// requests to the masters. In some cases, such as when the LBaaS service
    /// is not available, this option can be set to `false` to create a cluster
    /// without the load balancer. In this case, one of the masters will serve
    /// as the API endpoint. The default is `true`, i.e. to create the load
    /// balancer for the cluster.
    #[arg(help_heading = "Body parameters", long)]
    master_lb_enabled: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    merge_labels: Option<String>,

    /// Name of the resource.
    #[arg(help_heading = "Body parameters", long)]
    name: Option<String>,

    /// Parameter is an array, may be provided multiple times.
    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
    node_addresses: Option<Vec<String>>,

    /// The number of servers that will serve as node in the cluster. The
    /// default is 1.
    #[arg(help_heading = "Body parameters", long)]
    node_count: Option<i32>,

    #[arg(help_heading = "Body parameters", long)]
    project_id: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    stack_id: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    status: Option<Status>,

    #[arg(help_heading = "Body parameters", long)]
    status_reason: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    updated_at: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    user_id: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    uuid: Option<String>,
}

/// Query parameters
#[derive(Args)]
struct QueryParameters {}

/// Path parameters
#[derive(Args)]
struct PathParameters {}

#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
enum HealthStatus {
    Healthy,
    Unhealthy,
    Unknown,
}

#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
enum Status {
    AdoptComplete,
    CheckComplete,
    CreateComplete,
    CreateFailed,
    CreateInProgress,
    DeleteComplete,
    DeleteFailed,
    DeleteInProgress,
    RestoreComplete,
    ResumeComplete,
    ResumeFailed,
    RollbackComplete,
    RollbackFailed,
    RollbackInProgress,
    SnapshotComplete,
    UpdateComplete,
    UpdateFailed,
    UpdateInProgress,
}

impl ClusterCommand {
    /// Perform command action
    pub async fn take_action(
        &self,
        parsed_args: &Cli,
        client: &mut AsyncOpenStack,
    ) -> Result<(), OpenStackCliError> {
        info!("Create Cluster");

        let op = OutputProcessor::from_args(
            parsed_args,
            Some("container-infrastructure-management.cluster"),
            Some("create"),
        );
        op.validate_args(parsed_args)?;

        let mut ep_builder = create::Request::builder();

        // Set body parameters
        // Set Request.api_address data
        if let Some(arg) = &self.api_address {
            ep_builder.api_address(arg);
        }

        // Set Request.cluster_template_id data
        ep_builder.cluster_template_id(&self.cluster_template_id);

        // Set Request.coe_version data
        if let Some(arg) = &self.coe_version {
            ep_builder.coe_version(arg);
        }

        // Set Request.container_version data
        if let Some(arg) = &self.container_version {
            ep_builder.container_version(arg);
        }

        // Set Request.create_timeout data
        if let Some(arg) = &self.create_timeout {
            ep_builder.create_timeout(*arg);
        }

        // Set Request.created_at data
        if let Some(arg) = &self.created_at {
            ep_builder.created_at(arg);
        }

        // Set Request.discovery_url data
        if let Some(arg) = &self.discovery_url {
            ep_builder.discovery_url(arg);
        }

        // Set Request.docker_volume_size data
        if let Some(arg) = &self.docker_volume_size {
            ep_builder.docker_volume_size(*arg);
        }

        // Set Request.faults data
        if let Some(arg) = &self.faults {
            ep_builder.faults(arg.iter().cloned());
        }

        // Set Request.fixed_network data
        if let Some(arg) = &self.fixed_network {
            ep_builder.fixed_network(arg);
        }

        // Set Request.fixed_subnet data
        if let Some(arg) = &self.fixed_subnet {
            ep_builder.fixed_subnet(arg);
        }

        // Set Request.flavor_id data
        if let Some(arg) = &self.flavor_id {
            ep_builder.flavor_id(arg);
        }

        // Set Request.floating_ip_enabled data
        if let Some(arg) = &self.floating_ip_enabled {
            ep_builder.floating_ip_enabled(arg);
        }

        // Set Request.health_status data
        if let Some(arg) = &self.health_status {
            let tmp = match arg {
                HealthStatus::Healthy => create::HealthStatus::Healthy,
                HealthStatus::Unhealthy => create::HealthStatus::Unhealthy,
                HealthStatus::Unknown => create::HealthStatus::Unknown,
            };
            ep_builder.health_status(tmp);
        }

        // Set Request.health_status_reason data
        if let Some(arg) = &self.health_status_reason {
            ep_builder.health_status_reason(arg.iter().cloned());
        }

        // Set Request.keypair data
        if let Some(arg) = &self.keypair {
            ep_builder.keypair(arg);
        }

        // Set Request.labels data
        if let Some(arg) = &self.labels {
            ep_builder.labels(arg.iter().cloned());
        }

        // Set Request.labels_added data
        if let Some(arg) = &self.labels_added {
            ep_builder.labels_added(arg.iter().cloned());
        }

        // Set Request.labels_overridden data
        if let Some(arg) = &self.labels_overridden {
            ep_builder.labels_overridden(arg.iter().cloned());
        }

        // Set Request.labels_skipped data
        if let Some(arg) = &self.labels_skipped {
            ep_builder.labels_skipped(arg.iter().cloned());
        }

        // Set Request.links data
        if let Some(arg) = &self.links {
            let links_builder: Vec<create::Links> = arg
                .iter()
                .flat_map(|v| serde_json::from_value::<create::Links>(v.to_owned()))
                .collect::<Vec<create::Links>>();
            ep_builder.links(links_builder);
        }

        // Set Request.master_addresses data
        if let Some(arg) = &self.master_addresses {
            ep_builder.master_addresses(arg.iter().map(Into::into).collect::<Vec<_>>());
        }

        // Set Request.master_count data
        if let Some(arg) = &self.master_count {
            ep_builder.master_count(*arg);
        }

        // Set Request.master_flavor_id data
        if let Some(arg) = &self.master_flavor_id {
            ep_builder.master_flavor_id(arg);
        }

        // Set Request.master_lb_enabled data
        if let Some(arg) = &self.master_lb_enabled {
            ep_builder.master_lb_enabled(arg);
        }

        // Set Request.merge_labels data
        if let Some(arg) = &self.merge_labels {
            ep_builder.merge_labels(arg);
        }

        // Set Request.name data
        if let Some(arg) = &self.name {
            ep_builder.name(arg);
        }

        // Set Request.node_addresses data
        if let Some(arg) = &self.node_addresses {
            ep_builder.node_addresses(arg.iter().map(Into::into).collect::<Vec<_>>());
        }

        // Set Request.node_count data
        if let Some(arg) = &self.node_count {
            ep_builder.node_count(*arg);
        }

        // Set Request.project_id data
        if let Some(arg) = &self.project_id {
            ep_builder.project_id(arg);
        }

        // Set Request.stack_id data
        if let Some(arg) = &self.stack_id {
            ep_builder.stack_id(arg);
        }

        // Set Request.status data
        if let Some(arg) = &self.status {
            let tmp = match arg {
                Status::AdoptComplete => create::Status::AdoptComplete,
                Status::CheckComplete => create::Status::CheckComplete,
                Status::CreateComplete => create::Status::CreateComplete,
                Status::CreateFailed => create::Status::CreateFailed,
                Status::CreateInProgress => create::Status::CreateInProgress,
                Status::DeleteComplete => create::Status::DeleteComplete,
                Status::DeleteFailed => create::Status::DeleteFailed,
                Status::DeleteInProgress => create::Status::DeleteInProgress,
                Status::RestoreComplete => create::Status::RestoreComplete,
                Status::ResumeComplete => create::Status::ResumeComplete,
                Status::ResumeFailed => create::Status::ResumeFailed,
                Status::RollbackComplete => create::Status::RollbackComplete,
                Status::RollbackFailed => create::Status::RollbackFailed,
                Status::RollbackInProgress => create::Status::RollbackInProgress,
                Status::SnapshotComplete => create::Status::SnapshotComplete,
                Status::UpdateComplete => create::Status::UpdateComplete,
                Status::UpdateFailed => create::Status::UpdateFailed,
                Status::UpdateInProgress => create::Status::UpdateInProgress,
            };
            ep_builder.status(tmp);
        }

        // Set Request.status_reason data
        if let Some(arg) = &self.status_reason {
            ep_builder.status_reason(arg);
        }

        // Set Request.updated_at data
        if let Some(arg) = &self.updated_at {
            ep_builder.updated_at(arg);
        }

        // Set Request.user_id data
        if let Some(arg) = &self.user_id {
            ep_builder.user_id(arg);
        }

        // Set Request.uuid data
        if let Some(arg) = &self.uuid {
            ep_builder.uuid(arg);
        }

        let ep = ep_builder
            .build()
            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;

        let data = ep.query_async(client).await?;
        op.output_single::<ClusterResponse>(data)?;
        // Show command specific hints
        op.show_command_hint()?;
        Ok(())
    }
}