Skip to main content

openstack_cli_placement/v1/allocation/
create_138.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 Allocation command [microversion = 1.38]
19//!
20//! Wraps invoking of the `allocations` with `POST` method
21
22use clap::Args;
23use tracing::info;
24
25use openstack_cli_core::cli::CliArgs;
26use openstack_cli_core::error::OpenStackCliError;
27use openstack_cli_core::output::OutputProcessor;
28use openstack_sdk::AsyncOpenStack;
29
30use openstack_cli_core::common::parse_key_val;
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::placement::v1::allocation::create_138;
33use serde_json::Value;
34
35/// Create, update or delete allocations for multiple consumers in a single
36/// request. This allows a client to atomically set or swap allocations for
37/// multiple consumers as may be required during a migration or move type
38/// operation.
39///
40/// The allocations for an individual consumer uuid mentioned in the request
41/// can be removed by setting the allocations to an empty object (see the
42/// example below).
43///
44/// **Available as of microversion 1.13.**
45///
46/// Normal response codes: 204
47///
48/// Error response codes: badRequest(400), conflict(409)
49#[derive(Args)]
50#[command(about = "Manage allocations (microversion = 1.38)")]
51pub struct AllocationCommand {
52    /// Request Query parameters
53    #[command(flatten)]
54    query: QueryParameters,
55
56    /// Path parameters
57    #[command(flatten)]
58    path: PathParameters,
59
60    #[arg(long="property", value_name="key=value", value_parser=parse_key_val::<String, Value>)]
61    #[arg(help_heading = "Body parameters")]
62    properties: Option<Vec<(String, Value)>>,
63}
64
65/// Query parameters
66#[derive(Args)]
67struct QueryParameters {}
68
69/// Path parameters
70#[derive(Args)]
71struct PathParameters {}
72
73impl AllocationCommand {
74    /// Perform command action
75    pub async fn take_action<C: CliArgs>(
76        &self,
77        parsed_args: &C,
78        client: &mut AsyncOpenStack,
79    ) -> Result<(), OpenStackCliError> {
80        info!("Create Allocation");
81
82        let op =
83            OutputProcessor::from_args(parsed_args, Some("placement.allocation"), Some("create"));
84        op.validate_args(parsed_args)?;
85
86        let mut ep_builder = create_138::Request::builder();
87        ep_builder.header(
88            http::header::HeaderName::from_static("openstack-api-version"),
89            http::header::HeaderValue::from_static("placement 1.38"),
90        );
91
92        // Set body parameters
93        if let Some(properties) = &self.properties {
94            ep_builder.properties(
95                properties
96                    .iter()
97                    .map(|(k, v)| {
98                        serde_json::from_value(v.to_owned()).map(|v: create_138::Item| (k, v))
99                    })
100                    .collect::<Result<Vec<_>, _>>()?
101                    .into_iter(),
102            );
103        }
104
105        let ep = ep_builder
106            .build()
107            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
108        openstack_sdk::api::ignore(ep).query_async(client).await?;
109        // Show command specific hints
110        op.show_command_hint()?;
111        Ok(())
112    }
113}