openstack-cli-block-storage 0.13.7

OpenStack CLI Block Storage commands
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 Cleanup command [microversion = 3.24]
//!
//! Wraps invoking of the `v3/workers/cleanup` with `POST` method

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

use openstack_cli_core::cli::CliArgs;
use openstack_cli_core::error::OpenStackCliError;
use openstack_cli_core::output::OutputProcessor;
use openstack_sdk::AsyncOpenStack;

use clap::ValueEnum;
use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::block_storage::v3::worker::cleanup::create_324;

/// Do the cleanup on resources from a specific service/host/node.
#[derive(Args)]
pub struct CleanupCommand {
    /// Request Query parameters
    #[command(flatten)]
    query: QueryParameters,

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

    #[arg(help_heading = "Body parameters", long)]
    binary: Option<Binary>,

    #[arg(help_heading = "Body parameters", long)]
    cluster_name: Option<String>,

    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
    disabled: Option<bool>,

    #[arg(help_heading = "Body parameters", long)]
    host: Option<String>,

    #[arg(action=clap::ArgAction::Set, help_heading = "Body parameters", long)]
    is_up: Option<bool>,

    #[arg(help_heading = "Body parameters", long)]
    resource_id: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    resource_type: Option<String>,

    #[arg(help_heading = "Body parameters", long)]
    service_id: Option<String>,
}

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

/// Path parameters
#[derive(Args)]
struct PathParameters {}

#[derive(Clone, Eq, Ord, PartialEq, PartialOrd, ValueEnum)]
enum Binary {
    CinderScheduler,
    CinderVolume,
}

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

        let op = OutputProcessor::from_args(
            parsed_args,
            Some("block-storage.worker/cleanup"),
            Some("create"),
        );
        op.validate_args(parsed_args)?;

        let mut ep_builder = create_324::Request::builder();
        ep_builder.header(
            http::header::HeaderName::from_static("openstack-api-version"),
            http::header::HeaderValue::from_static("volume 3.24"),
        );

        // Set body parameters
        // Set Request.binary data
        if let Some(arg) = &self.binary {
            let tmp = match arg {
                Binary::CinderScheduler => create_324::Binary::CinderScheduler,
                Binary::CinderVolume => create_324::Binary::CinderVolume,
            };
            ep_builder.binary(tmp);
        }

        // Set Request.cluster_name data
        if let Some(arg) = &self.cluster_name {
            ep_builder.cluster_name(Some(arg.into()));
        }

        // Set Request.disabled data
        if let Some(arg) = &self.disabled {
            ep_builder.disabled(*arg);
        }

        // Set Request.host data
        if let Some(arg) = &self.host {
            ep_builder.host(Some(arg.into()));
        }

        // Set Request.is_up data
        if let Some(arg) = &self.is_up {
            ep_builder.is_up(*arg);
        }

        // Set Request.resource_id data
        if let Some(arg) = &self.resource_id {
            ep_builder.resource_id(Some(arg.into()));
        }

        // Set Request.resource_type data
        if let Some(arg) = &self.resource_type {
            ep_builder.resource_type(Some(arg.into()));
        }

        // Set Request.service_id data
        if let Some(arg) = &self.service_id {
            ep_builder.service_id(Some(arg.into()));
        }

        let ep = ep_builder
            .build()
            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
        openstack_sdk::api::ignore(ep).query_async(client).await?;
        // Show command specific hints
        op.show_command_hint()?;
        Ok(())
    }
}