Skip to main content

openstack_cli_block_storage/v3/group/
set_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//! Set Group command [microversion = 3.13]
19//!
20//! Wraps invoking of the `v3/groups/{id}` with `PUT` 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::find;
33use openstack_sdk::api::block_storage::v3::group::set_313;
34use openstack_sdk::api::find;
35
36/// Update the group.
37///
38/// Expected format of the input parameter 'body':
39///
40/// ```text
41/// {
42///     "group":
43///     {
44///         "name": "my_group",
45///         "description": "My group",
46///         "add_volumes": "volume-uuid-1,volume-uuid-2,...",
47///         "remove_volumes": "volume-uuid-8,volume-uuid-9,..."
48///     }
49/// }
50/// ```
51#[derive(Args)]
52pub struct GroupCommand {
53    /// Request Query parameters
54    #[command(flatten)]
55    query: QueryParameters,
56
57    /// Path parameters
58    #[command(flatten)]
59    path: PathParameters,
60
61    #[command(flatten)]
62    group: Group,
63}
64
65/// Query parameters
66#[derive(Args)]
67struct QueryParameters {}
68
69/// Path parameters
70#[derive(Args)]
71struct PathParameters {
72    /// id parameter for /v3/groups/{id} API
73    #[arg(
74        help_heading = "Path parameters",
75        id = "path_param_id",
76        value_name = "ID"
77    )]
78    id: String,
79}
80/// Group Body data
81#[derive(Args, Clone)]
82struct Group {
83    #[arg(help_heading = "Body parameters", long)]
84    add_volumes: Option<String>,
85
86    /// Set explicit NULL for the add_volumes
87    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "add_volumes")]
88    no_add_volumes: bool,
89
90    #[arg(help_heading = "Body parameters", long)]
91    description: Option<String>,
92
93    /// Set explicit NULL for the description
94    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "description")]
95    no_description: bool,
96
97    #[arg(help_heading = "Body parameters", long)]
98    name: Option<String>,
99
100    /// Set explicit NULL for the name
101    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "name")]
102    no_name: bool,
103
104    #[arg(help_heading = "Body parameters", long)]
105    remove_volumes: Option<String>,
106
107    /// Set explicit NULL for the remove_volumes
108    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "remove_volumes")]
109    no_remove_volumes: bool,
110}
111
112impl GroupCommand {
113    /// Perform command action
114    pub async fn take_action<C: CliArgs>(
115        &self,
116        parsed_args: &C,
117        client: &mut AsyncOpenStack,
118    ) -> Result<(), OpenStackCliError> {
119        info!("Set Group");
120
121        let op = OutputProcessor::from_args(parsed_args, Some("block-storage.group"), Some("set"));
122        op.validate_args(parsed_args)?;
123
124        let mut find_builder = find::Request::builder();
125
126        find_builder.id(&self.path.id);
127        find_builder.header(
128            http::header::HeaderName::from_static("openstack-api-version"),
129            http::header::HeaderValue::from_static("volume 3.13"),
130        );
131
132        let find_ep = find_builder
133            .build()
134            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
135        let find_data: serde_json::Value = find(find_ep).query_async(client).await?;
136
137        let mut ep_builder = set_313::Request::builder();
138        ep_builder.header(
139            http::header::HeaderName::from_static("openstack-api-version"),
140            http::header::HeaderValue::from_static("volume 3.13"),
141        );
142
143        let resource_id = find_data["id"]
144            .as_str()
145            .ok_or_else(|| eyre::eyre!("resource ID must be a string"))?
146            .to_string();
147        ep_builder.id(resource_id.clone());
148
149        // Set body parameters
150        // Set Request.group data
151        let args = &self.group;
152        let mut group_builder = set_313::GroupBuilder::default();
153        if let Some(val) = &args.add_volumes {
154            group_builder.add_volumes(Some(val.into()));
155        } else if args.no_add_volumes {
156            group_builder.add_volumes(None);
157        }
158
159        if let Some(val) = &args.description {
160            group_builder.description(Some(val.into()));
161        } else if args.no_description {
162            group_builder.description(None);
163        }
164
165        if let Some(val) = &args.name {
166            group_builder.name(Some(val.into()));
167        } else if args.no_name {
168            group_builder.name(None);
169        }
170
171        if let Some(val) = &args.remove_volumes {
172            group_builder.remove_volumes(Some(val.into()));
173        } else if args.no_remove_volumes {
174            group_builder.remove_volumes(None);
175        }
176
177        ep_builder.group(
178            group_builder
179                .build()
180                .wrap_err("error preparing the request data")?,
181        );
182
183        let ep = ep_builder
184            .build()
185            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
186        openstack_sdk::api::ignore(ep).query_async(client).await?;
187        // Show command specific hints
188        op.show_command_hint()?;
189        Ok(())
190    }
191}