openstack_cli 0.13.5

OpenStack client rewritten in Rust
Documentation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
//
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.

//! Create ServiceProfile command
//!
//! Wraps invoking of the `v2.0/flavors/{flavor_id}/service_profiles` with `POST` method

use clap::Args;
use eyre::{OptionExt, WrapErr};
use tracing::info;

use openstack_sdk::AsyncOpenStack;

use crate::Cli;
use crate::OpenStackCliError;
use crate::output::OutputProcessor;

use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::network::v2::flavor::service_profile::create;
use openstack_types::network::v2::flavor::service_profile::response::create::ServiceProfileResponse;

/// Associate a flavor with a service profile.
///
/// A flavor can be associated with more than one profile.
///
/// Will return `409 Conflict` if association already exists.
///
/// Normal response codes: 201
///
/// Error response codes: 400, 401, 403, 404, 409
#[derive(Args)]
#[command(about = "Associate flavor with a service profile")]
pub struct ServiceProfileCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

    /// Path parameters
    #[command(flatten)]
    path: PathParameters,

    /// A `service_profile` object.
    #[command(flatten)]
    service_profile: ServiceProfile,
}

/// Query parameters
#[derive(Args)]
struct QueryParameters {}

/// Path parameters
#[derive(Args)]
struct PathParameters {
    /// flavor_id parameter for /v2.0/flavors/{flavor_id}/service_profiles/{id}
    /// API
    #[arg(
        help_heading = "Path parameters",
        id = "path_param_flavor_id",
        value_name = "FLAVOR_ID"
    )]
    flavor_id: String,
}
/// ServiceProfile Body data
#[derive(Args, Clone)]
struct ServiceProfile {
    /// The UUID of the service profile.
    #[arg(help_heading = "Body parameters", long)]
    id: Option<String>,
}

impl ServiceProfileCommand {
    /// Perform command action
    pub async fn take_action(
        &self,
        parsed_args: &Cli,
        client: &mut AsyncOpenStack,
    ) -> Result<(), OpenStackCliError> {
        info!("Create ServiceProfile");

        let op = OutputProcessor::from_args(
            parsed_args,
            Some("network.flavor/service_profile"),
            Some("create"),
        );
        op.validate_args(parsed_args)?;

        let mut ep_builder = create::Request::builder();

        ep_builder.flavor_id(&self.path.flavor_id);

        // Set body parameters
        // Set Request.service_profile data
        let args = &self.service_profile;
        let mut service_profile_builder = create::ServiceProfileBuilder::default();
        if let Some(val) = &args.id {
            service_profile_builder.id(val);
        }

        ep_builder.service_profile(
            service_profile_builder
                .build()
                .wrap_err("error preparing the request data")?,
        );

        let ep = ep_builder
            .build()
            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;

        let data = ep.query_async(client).await?;
        op.output_single::<ServiceProfileResponse>(data)?;
        // Show command specific hints
        op.show_command_hint()?;
        Ok(())
    }
}