Skip to main content

openstack_cli_placement/v1/resource_provider/
create_114.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.14]
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_114;
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.14)")]
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 the immediate parent of the resource provider.
58    ///
59    /// - Before version `1.37`, once set, the parent of a resource provider
60    ///   cannot be changed.
61    /// - Since version `1.37`, it can be set to any existing provider UUID
62    ///   excepts to providers that would cause a loop. Also it can be set to
63    ///   null to transform the provider to a new root provider. This operation
64    ///   needs to be used carefully. Moving providers can mean that the
65    ///   original rules used to create the existing resource allocations may
66    ///   be invalidated by that move.
67    ///
68    /// **New in version 1.14**
69    #[arg(help_heading = "Body parameters", long)]
70    parent_provider_uuid: Option<String>,
71
72    /// The uuid of a resource provider.
73    #[arg(help_heading = "Body parameters", long)]
74    uuid: Option<String>,
75}
76
77/// Query parameters
78#[derive(Args)]
79struct QueryParameters {}
80
81/// Path parameters
82#[derive(Args)]
83struct PathParameters {}
84
85impl ResourceProviderCommand {
86    /// Perform command action
87    pub async fn take_action<C: CliArgs>(
88        &self,
89        parsed_args: &C,
90        client: &mut AsyncOpenStack,
91    ) -> Result<(), OpenStackCliError> {
92        info!("Create ResourceProvider");
93
94        let op = OutputProcessor::from_args(
95            parsed_args,
96            Some("placement.resource_provider"),
97            Some("create"),
98        );
99        op.validate_args(parsed_args)?;
100
101        let mut ep_builder = create_114::Request::builder();
102        ep_builder.header(
103            http::header::HeaderName::from_static("openstack-api-version"),
104            http::header::HeaderValue::from_static("placement 1.14"),
105        );
106
107        // Set body parameters
108        // Set Request.name data
109        ep_builder.name(&self.name);
110
111        // Set Request.parent_provider_uuid data
112        if let Some(arg) = &self.parent_provider_uuid {
113            ep_builder.parent_provider_uuid(Some(arg.into()));
114        }
115
116        // Set Request.uuid data
117        if let Some(arg) = &self.uuid {
118            ep_builder.uuid(arg);
119        }
120
121        let ep = ep_builder
122            .build()
123            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
124        openstack_sdk::api::ignore(ep).query_async(client).await?;
125        // Show command specific hints
126        op.show_command_hint()?;
127        Ok(())
128    }
129}