Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions openstack_cli/src/block_storage/v3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ pub mod qos_spec;
pub mod quota_class_set;
pub mod quota_set;
pub mod resource_filter;
pub mod scheduler_stat;
pub mod service;
pub mod snapshot;
pub mod snapshot_manage;
Expand Down Expand Up @@ -72,6 +73,7 @@ pub enum BlockStorageCommands {
QosSpec(Box<qos_spec::QosSpecCommand>),
QuotaClassSet(Box<quota_class_set::QuotaClassSetCommand>),
QuotaSet(Box<quota_set::QuotaSetCommand>),
SchedulerStat(Box<scheduler_stat::SchedulerStatCommand>),
Service(Box<service::ServiceCommand>),
Snapshot(Box<snapshot::SnapshotCommand>),
SnapshotManage(Box<snapshot_manage::SnapshotManageCommand>),
Expand Down Expand Up @@ -114,6 +116,7 @@ impl BlockStorageCommand {
BlockStorageCommands::QosSpec(cmd) => cmd.take_action(parsed_args, session).await,
BlockStorageCommands::QuotaClassSet(cmd) => cmd.take_action(parsed_args, session).await,
BlockStorageCommands::QuotaSet(cmd) => cmd.take_action(parsed_args, session).await,
BlockStorageCommands::SchedulerStat(cmd) => cmd.take_action(parsed_args, session).await,
BlockStorageCommands::Service(cmd) => cmd.take_action(parsed_args, session).await,
BlockStorageCommands::Snapshot(cmd) => cmd.take_action(parsed_args, session).await,
BlockStorageCommands::SnapshotManage(cmd) => {
Expand Down
53 changes: 53 additions & 0 deletions openstack_cli/src/block_storage/v3/scheduler_stat.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// 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

//! Block storage Scheduler stat
//!

use clap::{Parser, Subcommand};

use crate::{Cli, OpenStackCliError};

use openstack_sdk::AsyncOpenStack;

pub mod pool;

/// Back-end storage pools
/// Administrator only. Lists all back-end storage pools that are known to the scheduler service.
#[derive(Parser)]
pub struct SchedulerStatCommand {
/// subcommand
#[command(subcommand)]
command: SchedulerStatCommands,
}

/// Supported subcommands
#[allow(missing_docs)]
#[derive(Subcommand)]
pub enum SchedulerStatCommands {
Pool(Box<pool::PoolCommand>),
}

impl SchedulerStatCommand {
/// Perform command action
pub async fn take_action(
&self,
parsed_args: &Cli,
session: &mut AsyncOpenStack,
) -> Result<(), OpenStackCliError> {
match &self.command {
SchedulerStatCommands::Pool(cmd) => cmd.take_action(parsed_args, session).await,
}
}
}
54 changes: 54 additions & 0 deletions openstack_cli/src/block_storage/v3/scheduler_stat/pool.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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

//! Block storage Scheduler stat pools.
//!

use clap::{Parser, Subcommand};

use crate::{Cli, OpenStackCliError};

use openstack_sdk::AsyncOpenStack;

pub mod list;

/// Back-end storage pools
///
/// Administrator only. Lists all back-end storage pools that are known to the scheduler service.
#[derive(Parser)]
pub struct PoolCommand {
/// subcommand
#[command(subcommand)]
command: PoolCommands,
}

/// Supported subcommands
#[allow(missing_docs)]
#[derive(Subcommand)]
pub enum PoolCommands {
List(Box<list::PoolsCommand>),
}

impl PoolCommand {
/// Perform command action
pub async fn take_action(
&self,
parsed_args: &Cli,
session: &mut AsyncOpenStack,
) -> Result<(), OpenStackCliError> {
match &self.command {
PoolCommands::List(cmd) => cmd.take_action(parsed_args, session).await,
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@
// WARNING: This file is automatically generated from OpenAPI schema using
// `openstack-codegenerator`.

//! Get GetPool command
//! List Pools command
//!
//! Wraps invoking of the `v3/scheduler-stats/get_pools` with `GET` method

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

use openstack_sdk::AsyncOpenStack;
Expand All @@ -30,12 +29,12 @@ use crate::OpenStackCliError;
use crate::output::OutputProcessor;

use openstack_sdk::api::QueryAsync;
use openstack_sdk::api::block_storage::v3::scheduler_stat::get_pool::get;
use openstack_types::block_storage::v3::scheduler_stat::get_pool::response::get::GetPoolResponse;
use openstack_sdk::api::block_storage::v3::scheduler_stat::pool::list;
use openstack_types::block_storage::v3::scheduler_stat::pool::response::list::PoolResponse;

/// List all active pools in scheduler.
#[derive(Args)]
pub struct GetPoolCommand {
pub struct PoolsCommand {
/// Request Query parameters
#[command(flatten)]
query: QueryParameters,
Expand All @@ -47,36 +46,47 @@ pub struct GetPoolCommand {

/// Query parameters
#[derive(Args)]
struct QueryParameters {}
struct QueryParameters {
/// Indicates whether to show pool details or only pool names in the
/// response. Set to true to show pool details. Set to false to show only
/// pool names. Default is false.
#[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
detail: Option<bool>,
}

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

impl GetPoolCommand {
impl PoolsCommand {
/// Perform command action
pub async fn take_action(
&self,
parsed_args: &Cli,
client: &mut AsyncOpenStack,
) -> Result<(), OpenStackCliError> {
info!("Get GetPool");
info!("List Pools");

let op = OutputProcessor::from_args(
parsed_args,
Some("block-storage.scheduler_stat/get_pool"),
Some("get"),
Some("block-storage.scheduler_stats/pool"),
Some("list"),
);
op.validate_args(parsed_args)?;

let ep_builder = get::Request::builder();
let mut ep_builder = list::Request::builder();

// Set query parameters
if let Some(val) = &self.query.detail {
ep_builder.detail(*val);
}

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

let data = ep.query_async(client).await?;
op.output_single::<GetPoolResponse>(data)?;
let data: Vec<serde_json::Value> = ep.query_async(client).await?;
op.output_list::<PoolResponse>(data)?;
// Show command specific hints
op.show_command_hint()?;
Ok(())
Expand Down
1 change: 1 addition & 0 deletions openstack_cli/tests/block_storage/v3/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod qos_spec;
mod quota_class_set;
mod quota_set;
mod resource_filter;
mod scheduler_stat;
mod service;
mod snapshot;
mod snapshot_manage;
Expand Down
28 changes: 28 additions & 0 deletions openstack_cli/tests/block_storage/v3/scheduler_stat/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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

mod pool;

use assert_cmd::prelude::*;
use std::process::Command;

#[test]
fn help() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("osc")?;

cmd.args(["block-storage", "scheduler-stat", "--help"]);
cmd.assert().success();

Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fn help() -> Result<(), Box<dyn std::error::Error>> {

cmd.arg("block-storage")
.arg("scheduler-stat")
.arg("get-pool")
.arg("get")
.arg("pool")
.arg("list")
.arg("--help");
cmd.assert().success();

Expand Down
28 changes: 28 additions & 0 deletions openstack_cli/tests/block_storage/v3/scheduler_stat/pool/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// 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

mod list_autogen;

use assert_cmd::prelude::*;
use std::process::Command;

#[test]
fn help() -> Result<(), Box<dyn std::error::Error>> {
let mut cmd = Command::cargo_bin("osc")?;

cmd.args(["block-storage", "scheduler-stat", "pool", "--help"]);
cmd.assert().success();

Ok(())
}
2 changes: 1 addition & 1 deletion openstack_sdk/src/api/block_storage/v3/scheduler_stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
// `openstack-codegenerator`.

//! `/v3/workers/cleanup` REST operations of block_storage
pub mod get_pool;
pub mod pool;
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
// `openstack-codegenerator`.

//! `/v3/scheduler-stats/get_pools` REST operations of block_storage
pub mod get;
pub mod list;
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ use crate::api::rest_endpoint_prelude::*;
#[derive(Builder, Debug, Clone)]
#[builder(setter(strip_option))]
pub struct Request {
/// Indicates whether to show pool details or only pool names in the
/// response. Set to true to show pool details. Set to false to show only
/// pool names. Default is false.
#[builder(default)]
detail: Option<bool>,

#[builder(setter(name = "_headers"), default, private)]
_headers: Option<HeaderMap>,
}
Expand All @@ -36,7 +42,7 @@ impl Request {
}

impl RequestBuilder {
/// Add a single header to the Get_Pool.
/// Add a single header to the Pool.
pub fn header<K, V>(&mut self, header_name: K, header_value: V) -> &mut Self
where
K: Into<HeaderName>,
Expand Down Expand Up @@ -73,15 +79,18 @@ impl RestEndpoint for Request {
}

fn parameters(&self) -> QueryParams<'_> {
QueryParams::default()
let mut params = QueryParams::default();
params.push_opt("detail", self.detail);

params
}

fn service_type(&self) -> ServiceType {
ServiceType::BlockStorage
}

fn response_key(&self) -> Option<Cow<'static, str>> {
None
Some("pools".into())
}

/// Returns headers to be set into the request
Expand Down Expand Up @@ -116,7 +125,10 @@ mod tests {

#[test]
fn test_response_key() {
assert!(Request::builder().build().unwrap().response_key().is_none())
assert_eq!(
Request::builder().build().unwrap().response_key().unwrap(),
"pools"
);
}

#[cfg(feature = "sync")]
Expand All @@ -130,7 +142,7 @@ mod tests {

then.status(200)
.header("content-type", "application/json")
.json_body(json!({ "dummy": {} }));
.json_body(json!({ "pools": {} }));
});

let endpoint = Request::builder().build().unwrap();
Expand All @@ -150,7 +162,7 @@ mod tests {
.header("not_foo", "not_bar");
then.status(200)
.header("content-type", "application/json")
.json_body(json!({ "dummy": {} }));
.json_body(json!({ "pools": {} }));
});

let endpoint = Request::builder()
Expand Down
Loading