Skip to main content

openstack_cli_placement/v1/allocation/
set_10.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 Allocation command [microversion = 1.0]
19//!
20//! Wraps invoking of the `allocations/{consumer_uuid}` with `PUT` 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_sdk::api::QueryAsync;
31use openstack_sdk::api::placement::v1::allocation::set_10;
32use serde_json::Value;
33
34/// Create or update one or more allocation records representing the
35/// consumption of one or more classes of resources from one or more resource
36/// providers by the consumer identified by {consumer_uuid}. If allocations
37/// already exist for this consumer, they are replaced.
38///
39/// Normal Response Codes: 204
40///
41/// Error response codes: badRequest(400), itemNotFound(404), conflict(409)
42#[derive(Args)]
43#[command(about = "Update allocations (microversion = 1.0)")]
44pub struct AllocationCommand {
45    /// Request Query parameters
46    #[command(flatten)]
47    query: QueryParameters,
48
49    /// Path parameters
50    #[command(flatten)]
51    path: PathParameters,
52
53    /// Parameter is an array, may be provided multiple times.
54    #[arg(action=clap::ArgAction::Append, help_heading = "Body parameters", long, value_name="JSON", value_parser=openstack_cli_core::common::parse_json)]
55    allocations: Vec<Value>,
56}
57
58/// Query parameters
59#[derive(Args)]
60struct QueryParameters {}
61
62/// Path parameters
63#[derive(Args)]
64struct PathParameters {
65    /// consumer_uuid parameter for /allocations/{consumer_uuid} API
66    #[arg(
67        help_heading = "Path parameters",
68        id = "path_param_consumer_uuid",
69        value_name = "CONSUMER_UUID"
70    )]
71    consumer_uuid: String,
72}
73
74impl AllocationCommand {
75    /// Perform command action
76    pub async fn take_action<C: CliArgs>(
77        &self,
78        parsed_args: &C,
79        client: &mut AsyncOpenStack,
80    ) -> Result<(), OpenStackCliError> {
81        info!("Set Allocation");
82
83        let op = OutputProcessor::from_args(parsed_args, Some("placement.allocation"), Some("set"));
84        op.validate_args(parsed_args)?;
85
86        let mut ep_builder = set_10::Request::builder();
87        ep_builder.header(
88            http::header::HeaderName::from_static("openstack-api-version"),
89            http::header::HeaderValue::from_static("placement 1.0"),
90        );
91
92        ep_builder.consumer_uuid(&self.path.consumer_uuid);
93
94        // Set body parameters
95        // Set Request.allocations data
96
97        let allocations_builder: Vec<set_10::Allocations> = self
98            .allocations
99            .iter()
100            .flat_map(|v| serde_json::from_value::<set_10::Allocations>(v.to_owned()))
101            .collect::<Vec<set_10::Allocations>>();
102        ep_builder.allocations(allocations_builder);
103
104        let ep = ep_builder
105            .build()
106            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
107        openstack_sdk::api::ignore(ep).query_async(client).await?;
108        // Show command specific hints
109        op.show_command_hint()?;
110        Ok(())
111    }
112}