Skip to main content

openstack_cli_block_storage/v3/attachment/
set_327.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 Attachment command [microversion = 3.27]
19//!
20//! Wraps invoking of the `v3/attachments/{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_cli_core::common::parse_key_val;
32use openstack_sdk::api::QueryAsync;
33use openstack_sdk::api::block_storage::v3::attachment::set_327;
34use openstack_types::block_storage::v3::attachment::response;
35use serde_json::Value;
36
37/// Update an attachment record.
38///
39/// Update a reserved attachment record with connector information and set up
40/// the appropriate connection_info from the driver.
41///
42/// Expected format of the input parameter 'body':
43///
44/// ```text
45/// {
46///     "attachment":
47///     {
48///         "connector":
49///         {
50///             "initiator": "iqn.1993-08.org.debian:01:cad181614cec",
51///             "ip": "192.168.1.20",
52///             "platform": "x86_64",
53///             "host": "tempest-1",
54///             "os_type": "linux2",
55///             "multipath": false,
56///             "mountpoint": "/dev/vdb",
57///             "mode": "None|rw|ro"
58///         }
59///     }
60/// }
61/// ```
62#[derive(Args)]
63pub struct AttachmentCommand {
64    /// Request Query parameters
65    #[command(flatten)]
66    query: QueryParameters,
67
68    /// Path parameters
69    #[command(flatten)]
70    path: PathParameters,
71
72    #[command(flatten)]
73    attachment: Attachment,
74}
75
76/// Query parameters
77#[derive(Args)]
78struct QueryParameters {}
79
80/// Path parameters
81#[derive(Args)]
82struct PathParameters {
83    /// id parameter for /v3/attachments/{id} API
84    #[arg(
85        help_heading = "Path parameters",
86        id = "path_param_id",
87        value_name = "ID"
88    )]
89    id: String,
90}
91/// Attachment Body data
92#[derive(Args, Clone)]
93struct Attachment {
94    #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, Value>)]
95    connector: Vec<(String, Value)>,
96}
97
98impl AttachmentCommand {
99    /// Perform command action
100    pub async fn take_action<C: CliArgs>(
101        &self,
102        parsed_args: &C,
103        client: &mut AsyncOpenStack,
104    ) -> Result<(), OpenStackCliError> {
105        info!("Set Attachment");
106
107        let op =
108            OutputProcessor::from_args(parsed_args, Some("block-storage.attachment"), Some("set"));
109        op.validate_args(parsed_args)?;
110
111        let mut ep_builder = set_327::Request::builder();
112        ep_builder.header(
113            http::header::HeaderName::from_static("openstack-api-version"),
114            http::header::HeaderValue::from_static("volume 3.27"),
115        );
116
117        ep_builder.id(&self.path.id);
118
119        // Set body parameters
120        // Set Request.attachment data
121        let args = &self.attachment;
122        let mut attachment_builder = set_327::AttachmentBuilder::default();
123
124        attachment_builder.connector(args.connector.iter().cloned());
125
126        ep_builder.attachment(
127            attachment_builder
128                .build()
129                .wrap_err("error preparing the request data")?,
130        );
131
132        let ep = ep_builder
133            .build()
134            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
135
136        let data: serde_json::Value = ep.query_async(client).await?;
137
138        op.output_single::<response::set::AttachmentResponse>(data.clone())?;
139        // Show command specific hints
140        op.show_command_hint()?;
141        Ok(())
142    }
143}