openstack_cli_placement/v1/resource_provider/set_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//! Set ResourceProvider command [microversion = 1.14]
19//!
20//! Wraps invoking of the `resource_providers/{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::resource_provider::set_114;
32
33/// Update the name of the resource provider identified by {uuid}.
34///
35/// Normal Response Codes: 200
36///
37/// Error response codes: badRequest(400), itemNotFound(404), conflict(409)
38///
39/// A 409 Conflict response code will be returned if another resource provider
40/// exists with the provided name.
41#[derive(Args)]
42#[command(about = "Update resource provider (microversion = 1.14)")]
43pub struct ResourceProviderCommand {
44 /// Request Query parameters
45 #[command(flatten)]
46 query: QueryParameters,
47
48 /// Path parameters
49 #[command(flatten)]
50 path: PathParameters,
51
52 /// The name of one resource provider.
53 #[arg(help_heading = "Body parameters", long)]
54 name: String,
55
56 /// The UUID of the immediate parent of the resource provider.
57 ///
58 /// - Before version `1.37`, once set, the parent of a resource provider
59 /// cannot be changed.
60 /// - Since version `1.37`, it can be set to any existing provider UUID
61 /// excepts to providers that would cause a loop. Also it can be set to
62 /// null to transform the provider to a new root provider. This operation
63 /// needs to be used carefully. Moving providers can mean that the
64 /// original rules used to create the existing resource allocations may
65 /// be invalidated by that move.
66 ///
67 /// **New in version 1.14**
68 #[arg(help_heading = "Body parameters", long)]
69 parent_provider_uuid: Option<String>,
70}
71
72/// Query parameters
73#[derive(Args)]
74struct QueryParameters {}
75
76/// Path parameters
77#[derive(Args)]
78struct PathParameters {
79 /// uuid parameter for /resource_providers/{uuid} API
80 #[arg(
81 help_heading = "Path parameters",
82 id = "path_param_uuid",
83 value_name = "UUID"
84 )]
85 uuid: String,
86}
87
88impl ResourceProviderCommand {
89 /// Perform command action
90 pub async fn take_action<C: CliArgs>(
91 &self,
92 parsed_args: &C,
93 client: &mut AsyncOpenStack,
94 ) -> Result<(), OpenStackCliError> {
95 info!("Set ResourceProvider");
96
97 let op = OutputProcessor::from_args(
98 parsed_args,
99 Some("placement.resource_provider"),
100 Some("set"),
101 );
102 op.validate_args(parsed_args)?;
103
104 let mut ep_builder = set_114::Request::builder();
105 ep_builder.header(
106 http::header::HeaderName::from_static("openstack-api-version"),
107 http::header::HeaderValue::from_static("placement 1.14"),
108 );
109
110 ep_builder.uuid(&self.path.uuid);
111
112 // Set body parameters
113 // Set Request.name data
114 ep_builder.name(&self.name);
115
116 // Set Request.parent_provider_uuid data
117 if let Some(arg) = &self.parent_provider_uuid {
118 ep_builder.parent_provider_uuid(Some(arg.into()));
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}