openstack_cli_placement/v1/resource_provider/create_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//! Create ResourceProvider command [microversion = 1.0]
19//!
20//! Wraps invoking of the `resource_providers` 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_sdk::api::QueryAsync;
31use openstack_sdk::api::placement::v1::resource_provider::create_10;
32
33/// Create a new resource provider.
34///
35/// Normal Response Codes: 201 (microversions 1.0 - 1.19), 200 (microversions
36/// 1.20 - )
37///
38/// Error response codes: conflict(409)
39///
40/// A 409 Conflict response code will be returned if another resource provider
41/// exists with the provided name or uuid.
42#[derive(Args)]
43#[command(about = "Create resource provider (microversion = 1.0)")]
44pub struct ResourceProviderCommand {
45 /// Request Query parameters
46 #[command(flatten)]
47 query: QueryParameters,
48
49 /// Path parameters
50 #[command(flatten)]
51 path: PathParameters,
52
53 /// The name of one resource provider.
54 #[arg(help_heading = "Body parameters", long)]
55 name: String,
56
57 /// The uuid of a resource provider.
58 #[arg(help_heading = "Body parameters", long)]
59 uuid: Option<String>,
60}
61
62/// Query parameters
63#[derive(Args)]
64struct QueryParameters {}
65
66/// Path parameters
67#[derive(Args)]
68struct PathParameters {}
69
70impl ResourceProviderCommand {
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!("Create ResourceProvider");
78
79 let op = OutputProcessor::from_args(
80 parsed_args,
81 Some("placement.resource_provider"),
82 Some("create"),
83 );
84 op.validate_args(parsed_args)?;
85
86 let mut ep_builder = create_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 // Set body parameters
93 // Set Request.name data
94 ep_builder.name(&self.name);
95
96 // Set Request.uuid data
97 if let Some(arg) = &self.uuid {
98 ep_builder.uuid(arg);
99 }
100
101 let ep = ep_builder
102 .build()
103 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
104 openstack_sdk::api::ignore(ep).query_async(client).await?;
105 // Show command specific hints
106 op.show_command_hint()?;
107 Ok(())
108 }
109}