Skip to main content

openstack_cli_block_storage/v3/group/
failover_replication_338.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//! Action Group command [microversion = 3.38]
19//!
20//! Wraps invoking of the `v3/groups/action` 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::failover_replication_338;
33
34/// Command without description in OpenAPI
35#[derive(Args)]
36pub struct GroupCommand {
37    /// Request Query parameters
38    #[command(flatten)]
39    query: QueryParameters,
40
41    /// Path parameters
42    #[command(flatten)]
43    path: PathParameters,
44
45    #[command(flatten)]
46    failover_replication: FailoverReplication,
47}
48
49/// Query parameters
50#[derive(Args)]
51struct QueryParameters {}
52
53/// Path parameters
54#[derive(Args)]
55struct PathParameters {}
56/// FailoverReplication Body data
57#[derive(Args, Clone)]
58struct FailoverReplication {
59    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
60    allow_attached_volume: Option<bool>,
61
62    #[arg(help_heading = "Body parameters", long)]
63    secondary_backend_id: Option<String>,
64
65    /// Set explicit NULL for the secondary_backend_id
66    #[arg(help_heading = "Body parameters", long, action = clap::ArgAction::SetTrue, conflicts_with = "secondary_backend_id")]
67    no_secondary_backend_id: bool,
68}
69
70impl GroupCommand {
71    /// Perform command action
72    pub async fn take_action<C: CliArgs>(
73        &self,
74        parsed_args: &C,
75        client: &mut AsyncOpenStack,
76    ) -> Result<(), OpenStackCliError> {
77        info!("Action Group");
78
79        let op = OutputProcessor::from_args(
80            parsed_args,
81            Some("block-storage.group"),
82            Some("failover_replication"),
83        );
84        op.validate_args(parsed_args)?;
85
86        let mut ep_builder = failover_replication_338::Request::builder();
87        ep_builder.header(
88            http::header::HeaderName::from_static("openstack-api-version"),
89            http::header::HeaderValue::from_static("volume 3.38"),
90        );
91
92        // Set body parameters
93        // Set Request.failover_replication data
94        let args = &self.failover_replication;
95        let mut failover_replication_builder =
96            failover_replication_338::FailoverReplicationBuilder::default();
97        if let Some(val) = &args.allow_attached_volume {
98            failover_replication_builder.allow_attached_volume(*val);
99        }
100
101        if let Some(val) = &args.secondary_backend_id {
102            failover_replication_builder.secondary_backend_id(Some(val.into()));
103        } else if args.no_secondary_backend_id {
104            failover_replication_builder.secondary_backend_id(None);
105        }
106
107        ep_builder.failover_replication(
108            failover_replication_builder
109                .build()
110                .wrap_err("error preparing the request data")?,
111        );
112
113        let ep = ep_builder
114            .build()
115            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
116        openstack_sdk::api::ignore(ep).query_async(client).await?;
117        // Show command specific hints
118        op.show_command_hint()?;
119        Ok(())
120    }
121}