Skip to main content

openstack_cli_block_storage/v3/group_snapshot/
create_314.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 GroupSnapshot command [microversion = 3.14]
19//!
20//! Wraps invoking of the `v3/group_snapshots` 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_snapshot::create_314;
33use openstack_types::block_storage::v3::group_snapshot::response;
34
35/// Create a new group_snapshot.
36#[derive(Args)]
37pub struct GroupSnapshotCommand {
38    /// Request Query parameters
39    #[command(flatten)]
40    query: QueryParameters,
41
42    /// Path parameters
43    #[command(flatten)]
44    path: PathParameters,
45
46    /// The group snapshot.
47    #[command(flatten)]
48    group_snapshot: GroupSnapshot,
49}
50
51/// Query parameters
52#[derive(Args)]
53struct QueryParameters {}
54
55/// Path parameters
56#[derive(Args)]
57struct PathParameters {}
58/// GroupSnapshot Body data
59#[derive(Args, Clone)]
60struct GroupSnapshot {
61    /// The group snapshot description.
62    #[arg(help_heading = "Body parameters", long)]
63    description: Option<String>,
64
65    /// Set explicit NULL for the description
66    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "description")]
67    no_description: bool,
68
69    /// The ID of the group.
70    #[arg(help_heading = "Body parameters", long)]
71    group_id: String,
72
73    /// The group snapshot name.
74    #[arg(help_heading = "Body parameters", long)]
75    name: Option<String>,
76
77    /// Set explicit NULL for the name
78    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "name")]
79    no_name: bool,
80}
81
82impl GroupSnapshotCommand {
83    /// Perform command action
84    pub async fn take_action<C: CliArgs>(
85        &self,
86        parsed_args: &C,
87        client: &mut AsyncOpenStack,
88    ) -> Result<(), OpenStackCliError> {
89        info!("Create GroupSnapshot");
90
91        let op = OutputProcessor::from_args(
92            parsed_args,
93            Some("block-storage.group_snapshot"),
94            Some("create"),
95        );
96        op.validate_args(parsed_args)?;
97
98        let mut ep_builder = create_314::Request::builder();
99        ep_builder.header(
100            http::header::HeaderName::from_static("openstack-api-version"),
101            http::header::HeaderValue::from_static("volume 3.14"),
102        );
103
104        // Set body parameters
105        // Set Request.group_snapshot data
106        let args = &self.group_snapshot;
107        let mut group_snapshot_builder = create_314::GroupSnapshotBuilder::default();
108        if let Some(val) = &args.description {
109            group_snapshot_builder.description(Some(val.into()));
110        } else if args.no_description {
111            group_snapshot_builder.description(None);
112        }
113
114        group_snapshot_builder.group_id(&args.group_id);
115
116        if let Some(val) = &args.name {
117            group_snapshot_builder.name(Some(val.into()));
118        } else if args.no_name {
119            group_snapshot_builder.name(None);
120        }
121
122        ep_builder.group_snapshot(
123            group_snapshot_builder
124                .build()
125                .wrap_err("error preparing the request data")?,
126        );
127
128        let ep = ep_builder
129            .build()
130            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
131
132        let data: serde_json::Value = ep.query_async(client).await?;
133
134        op.output_single::<response::create::GroupSnapshotResponse>(data.clone())?;
135        // Show command specific hints
136        op.show_command_hint()?;
137        Ok(())
138    }
139}