Skip to main content

openstack_cli_block_storage/v3/group/
create_313.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 Group command [microversion = 3.13]
19//!
20//! Wraps invoking of the `v3/groups` 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::block_storage::v3::group::create_313;
33use openstack_types::block_storage::v3::group::response;
34
35/// Create a new group.
36#[derive(Args)]
37pub struct GroupCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// A group object.
47    #[command(flatten)]
48    group: Group,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Path parameters
56#[derive(Args)]
57struct PathParameters {}
58/// Group Body data
59#[derive(Args, Clone)]
60struct Group {
61    /// The name of the availability zone.
62    #[arg(help_heading = "Body parameters", long)]
63    availability_zone: Option<String>,
64
65    /// Set explicit NULL for the availability_zone
66    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "availability_zone")]
67    no_availability_zone: bool,
68
69    /// The group description.
70    #[arg(help_heading = "Body parameters", long)]
71    description: Option<String>,
72
73    /// Set explicit NULL for the description
74    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "description")]
75    no_description: bool,
76
77    /// The group type ID.
78    #[arg(help_heading = "Body parameters", long)]
79    group_type: String,
80
81    /// The group name.
82    #[arg(help_heading = "Body parameters", long)]
83    name: Option<String>,
84
85    /// Set explicit NULL for the name
86    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "name")]
87    no_name: bool,
88
89    /// The list of volume types. In an environment with multiple-storage back
90    /// ends, the scheduler determines where to send the volume based on the
91    /// volume type. For information about how to use volume types to create
92    /// multiple- storage back ends, see
93    /// [Configure multiple-storage back ends](https://docs.openstack.org/cinder/latest/admin/blockstorage-multi-backend.html).
94    ///
95    /// Parameter is an array, may be provided multiple times.
96    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long)]
97    volume_types: Vec<String>,
98}
99
100impl GroupCommand {
101    /// Perform command action
102    pub async fn take_action<C: CliArgs>(
103        &self,
104        parsed_args: &C,
105        client: &mut AsyncOpenStack,
106    ) -> Result<(), OpenStackCliError> {
107        info!("Create Group");
108
109        let op =
110            OutputProcessor::from_args(parsed_args, Some("block-storage.group"), Some("create"));
111        op.validate_args(parsed_args)?;
112
113        let mut ep_builder = create_313::Request::builder();
114        ep_builder.header(
115            http::header::HeaderName::from_static("openstack-api-version"),
116            http::header::HeaderValue::from_static("volume 3.13"),
117        );
118
119        // Set body parameters
120        // Set Request.group data
121        let args = &self.group;
122        let mut group_builder = create_313::GroupBuilder::default();
123        if let Some(val) = &args.availability_zone {
124            group_builder.availability_zone(Some(val.into()));
125        } else if args.no_availability_zone {
126            group_builder.availability_zone(None);
127        }
128
129        if let Some(val) = &args.description {
130            group_builder.description(Some(val.into()));
131        } else if args.no_description {
132            group_builder.description(None);
133        }
134
135        group_builder.group_type(&args.group_type);
136
137        if let Some(val) = &args.name {
138            group_builder.name(Some(val.into()));
139        } else if args.no_name {
140            group_builder.name(None);
141        }
142
143        group_builder.volume_types(args.volume_types.iter().map(Into::into).collect::<Vec<_>>());
144
145        ep_builder.group(
146            group_builder
147                .build()
148                .wrap_err("error preparing the request data")?,
149        );
150
151        let ep = ep_builder
152            .build()
153            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
154
155        let data: serde_json::Value = ep.query_async(client).await?;
156
157        op.output_single::<response::create::GroupResponse>(data.clone())?;
158        // Show command specific hints
159        op.show_command_hint()?;
160        Ok(())
161    }
162}