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
488
489
490
491
// 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 Clustertemplate command
//!
//! Wraps invoking of the `v1/clustertemplates` 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::clustertemplate::create;
use openstack_types::container_infrastructure_management::v1::clustertemplate::response::create::ClustertemplateResponse;
use serde_json::Value;

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

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

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

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

    /// Specify the Container Orchestration Engine to use. Supported COEs
    /// include `kubernetes`. If your environment has additional cluster
    /// drivers installed, refer to the cluster driver documentation for the
    /// new COE names.
    #[arg(help_heading = "Body parameters", long)]
    coe: Option<Coe>,

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

    /// The DNS nameserver for the servers and containers in the cluster to
    /// use. This is configured in the private Neutron network for the cluster.
    /// The default is `8.8.8.8`.
    #[arg(help_heading = "Body parameters", long)]
    dns_nameserver: Option<String>,

    /// The name of a driver to manage the storage for the images and the
    /// container’s writable layer. The default is `devicemapper`.
    #[arg(help_heading = "Body parameters", long)]
    docker_storage_driver: Option<String>,

    /// The size in GB for the local storage on each server for the Docker
    /// daemon to cache the images and host the containers. Cinder volumes
    /// provide the storage. The default is 25 GB. For the `devicemapper`
    /// storage driver, the minimum value is 3GB. For the `overlay` storage
    /// driver, the minimum value is 1GB.
    #[arg(help_heading = "Body parameters", long)]
    docker_volume_size: Option<i32>,

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

    /// The name or network ID of a Neutron network to provide connectivity to
    /// the external internet for the cluster. This network must be an external
    /// network, i.e. its attribute `router:external` must be `True`. The
    /// servers in the cluster will be connected to a private network and
    /// Magnum will create a router between this private network and the
    /// external network. This will allow the servers to download images,
    /// access discovery service, etc, and the containers to install packages,
    /// etc. In the opposite direction, floating IPs will be allocated from the
    /// external network to provide access from the external internet to
    /// servers and the container services hosted in the cluster.
    #[arg(help_heading = "Body parameters", long)]
    external_network_id: Option<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.
    #[arg(help_heading = "Body parameters", long)]
    floating_ip_enabled: Option<String>,

    /// Indicates whether the ClusterTemplate is hidden or not, the default
    /// value is false.
    #[arg(help_heading = "Body parameters", long)]
    hidden: Option<String>,

    /// The IP address for a proxy to use when direct http access from the
    /// servers to sites on the external internet is blocked. This may happen
    /// in certain countries or enterprises, and the proxy allows the servers
    /// and containers to access these sites. The format is a URL including a
    /// port number. The default is `None`.
    #[arg(help_heading = "Body parameters", long)]
    http_proxy: Option<String>,

    /// The IP address for a proxy to use when direct https access from the
    /// servers to sites on the external internet is blocked. This may happen
    /// in certain countries or enterprises, and the proxy allows the servers
    /// and containers to access these sites. The format is a URL including a
    /// port number. The default is `None`.
    #[arg(help_heading = "Body parameters", long)]
    https_proxy: Option<String>,

    /// The name or UUID of the base image in Glance to boot the servers for
    /// the cluster. The image must have the attribute `os_distro` defined as
    /// appropriate for the cluster driver.
    #[arg(help_heading = "Body parameters", long)]
    image_id: String,

    /// The URL pointing to users’s own private insecure docker registry to
    /// deploy and run docker containers.
    #[arg(help_heading = "Body parameters", long)]
    insecure_registry: Option<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_id: 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)>>,

    /// 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>>,

    /// 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>,

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

    /// The name of a network driver for providing the networks for the
    /// containers. Note that this is different and separate from the Neutron
    /// network for the cluster. The operation and networking model are
    /// specific to the particular driver.
    #[arg(help_heading = "Body parameters", long)]
    network_driver: Option<String>,

    /// When a proxy server is used, some sites should not go through the proxy
    /// and should be accessed normally. In this case, users can specify these
    /// sites as a comma separated list of IPs. The default is `None`.
    #[arg(help_heading = "Body parameters", long)]
    no_proxy: Option<String>,

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

    /// Access to a cluster template is normally limited to the admin, owner or
    /// users within the same tenant as the owners. Setting this flag makes the
    /// cluster template public and accessible by other users. The default is
    /// not public.
    #[arg(help_heading = "Body parameters", long)]
    public: Option<String>,

    /// Docker images by default are pulled from the public Docker registry,
    /// but in some cases, users may want to use a private registry. This
    /// option provides an alternative registry based on the Registry V2:
    /// Magnum will create a local registry in the cluster backed by swift to
    /// host the images. The default is to use the public registry.
    #[arg(help_heading = "Body parameters", long)]
    registry_enabled: Option<String>,

    /// The servers in the cluster can be `vm` or `baremetal`. This parameter
    /// selects the type of server to create for the cluster. The default is
    /// `vm`.
    #[arg(help_heading = "Body parameters", long)]
    server_type: Option<ServerType>,

    /// Administrator tags for the cluster template.
    #[arg(help_heading = "Body parameters", long)]
    tags: Option<String>,

    /// Transport Layer Security (TLS) is normally enabled to secure the
    /// cluster. In some cases, users may want to disable TLS in the cluster,
    /// for instance during development or to troubleshoot certain problems.
    /// Specifying this parameter will disable TLS so that users can access the
    /// COE endpoints without a certificate. The default is TLS enabled.
    #[arg(help_heading = "Body parameters", long)]
    tls_disabled: 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>,

    /// The name of a volume driver for managing the persistent storage for the
    /// containers. The functionality supported are specific to the driver.
    #[arg(help_heading = "Body parameters", long)]
    volume_driver: Option<String>,
}

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

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

#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
enum Coe {
    Kubernetes,
}

#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
enum ServerType {
    Bm,
    Vm,
}

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

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

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

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

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

        // Set Request.coe data
        if let Some(arg) = &self.coe {
            let tmp = match arg {
                Coe::Kubernetes => create::Coe::Kubernetes,
            };
            ep_builder.coe(tmp);
        }

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

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

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

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

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

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

        // 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.hidden data
        if let Some(arg) = &self.hidden {
            ep_builder.hidden(arg);
        }

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

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

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

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

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

        // Set Request.labels data
        if let Some(arg) = &self.labels {
            ep_builder.labels(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_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.name data
        if let Some(arg) = &self.name {
            ep_builder.name(arg);
        }

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

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

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

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

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

        // Set Request.server_type data
        if let Some(arg) = &self.server_type {
            let tmp = match arg {
                ServerType::Bm => create::ServerType::Bm,
                ServerType::Vm => create::ServerType::Vm,
            };
            ep_builder.server_type(tmp);
        }

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

        // Set Request.tls_disabled data
        if let Some(arg) = &self.tls_disabled {
            ep_builder.tls_disabled(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);
        }

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

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

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