openstack_cli_placement/v1/reshaper/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 Reshaper command [microversion = 1.38]
19//!
20//! Wraps invoking of the `reshaper` 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::reshaper::create_138;
33use serde_json::Value;
34
35/// Atomically migrate resource provider inventories and associated
36/// allocations. This is used when some of the inventory needs to move from one
37/// resource provider to another, such as when a class of inventory moves from
38/// a parent provider to a new child provider.
39///
40/// Normal Response Codes: 204
41///
42/// Error Response Codes: badRequest(400), conflict(409)
43#[derive(Args)]
44#[command(about = "Reshaper (microversion = 1.38)")]
45pub struct ReshaperCommand {
46 /// Request Query parameters
47 #[command(flatten)]
48 query: QueryParameters,
49
50 /// Path parameters
51 #[command(flatten)]
52 path: PathParameters,
53
54 /// A dictionary of multiple allocations, keyed by consumer uuid. Each
55 /// collection of allocations describes the full set of allocations for
56 /// each consumer. Each consumer allocations dict is itself a dictionary of
57 /// resource allocations keyed by resource provider uuid. An empty
58 /// dictionary indicates no change in existing allocations, whereas an
59 /// empty `allocations` dictionary **within** a consumer dictionary
60 /// indicates that all allocations for that consumer should be deleted.
61 #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, Value>)]
62 allocations: Vec<(String, Value)>,
63
64 /// A dictionary of multiple inventories, keyed by resource provider uuid.
65 /// Each inventory describes the desired full inventory for each resource
66 /// provider. An empty dictionary causes the inventory for that provider to
67 /// be deleted.
68 #[arg(help_heading = "Body parameters", long, value_name="key=value", value_parser=parse_key_val::<String, Value>)]
69 inventories: Vec<(String, Value)>,
70}
71
72/// Query parameters
73#[derive(Args)]
74struct QueryParameters {}
75
76/// Path parameters
77#[derive(Args)]
78struct PathParameters {}
79
80impl ReshaperCommand {
81 /// Perform command action
82 pub async fn take_action<C: CliArgs>(
83 &self,
84 parsed_args: &C,
85 client: &mut AsyncOpenStack,
86 ) -> Result<(), OpenStackCliError> {
87 info!("Create Reshaper");
88
89 let op =
90 OutputProcessor::from_args(parsed_args, Some("placement.reshaper"), Some("create"));
91 op.validate_args(parsed_args)?;
92
93 let mut ep_builder = create_138::Request::builder();
94 ep_builder.header(
95 http::header::HeaderName::from_static("openstack-api-version"),
96 http::header::HeaderValue::from_static("placement 1.38"),
97 );
98
99 // Set body parameters
100 // Set Request.allocations data
101
102 ep_builder.allocations(
103 self.allocations
104 .iter()
105 .map(|(k, v)| {
106 serde_json::from_value(v.to_owned())
107 .map(|v: create_138::AllocationsItemStruct| (k, v))
108 })
109 .collect::<Result<Vec<_>, _>>()?
110 .into_iter(),
111 );
112
113 // Set Request.inventories data
114
115 ep_builder.inventories(
116 self.inventories
117 .iter()
118 .map(|(k, v)| {
119 serde_json::from_value(v.to_owned())
120 .map(|v: create_138::InventoriesItemStruct| (k, v))
121 })
122 .collect::<Result<Vec<_>, _>>()?
123 .into_iter(),
124 );
125
126 let ep = ep_builder
127 .build()
128 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
129 openstack_sdk::api::ignore(ep).query_async(client).await?;
130 // Show command specific hints
131 op.show_command_hint()?;
132 Ok(())
133 }
134}