diff --git a/doc/src/osc.md b/doc/src/osc.md index 228fb6b27..35490fee8 100644 --- a/doc/src/osc.md +++ b/doc/src/osc.md @@ -18,6 +18,8 @@ This document contains the help content for the `osc` command-line program. * [`osc block-storage attachment list`↴](#osc-block-storage-attachment-list) * [`osc block-storage attachment set327`↴](#osc-block-storage-attachment-set327) * [`osc block-storage attachment show`↴](#osc-block-storage-attachment-show) +* [`osc block-storage availability-zone`↴](#osc-block-storage-availability-zone) +* [`osc block-storage availability-zone list`↴](#osc-block-storage-availability-zone-list) * [`osc block-storage backup`↴](#osc-block-storage-backup) * [`osc block-storage backup create351`↴](#osc-block-storage-backup-create351) * [`osc block-storage backup create343`↴](#osc-block-storage-backup-create343) @@ -840,6 +842,7 @@ Block Storage (Volume) service (Cinder) commands ###### **Subcommands:** * `attachment` — Attachments (attachments) +* `availability-zone` — Availability zones * `backup` — Backups * `cluster` — Clusters (clusters) * `default-type` — Default Volume Types (default-types) @@ -1066,6 +1069,28 @@ Return data about the given attachment +## `osc block-storage availability-zone` + +Availability zones + +Lists and gets detailed availability zone information. + +**Usage:** `osc block-storage availability-zone ` + +###### **Subcommands:** + +* `list` — Describe all known availability zones + + + +## `osc block-storage availability-zone list` + +Describe all known availability zones + +**Usage:** `osc block-storage availability-zone list` + + + ## `osc block-storage backup` Backups diff --git a/openstack_cli/src/block_storage/v3.rs b/openstack_cli/src/block_storage/v3.rs index 74b9f7012..27d46981b 100644 --- a/openstack_cli/src/block_storage/v3.rs +++ b/openstack_cli/src/block_storage/v3.rs @@ -20,6 +20,7 @@ use openstack_sdk::{types::ServiceType, AsyncOpenStack}; use crate::{Cli, OpenStackCliError}; mod attachment; +mod availability_zone; mod backup; mod cluster; mod default_type; @@ -52,6 +53,7 @@ pub struct BlockStorageCommand { #[derive(Subcommand)] pub enum BlockStorageCommands { Attachment(attachment::AttachmentCommand), + AvailabilityZone(availability_zone::AvailabilityZoneCommand), Backup(backup::BackupCommand), Cluster(cluster::ClusterCommand), DefaultType(default_type::DefaultTypeCommand), @@ -85,6 +87,9 @@ impl BlockStorageCommand { match &self.command { BlockStorageCommands::Attachment(cmd) => cmd.take_action(parsed_args, session).await, + BlockStorageCommands::AvailabilityZone(cmd) => { + cmd.take_action(parsed_args, session).await + } BlockStorageCommands::Backup(cmd) => cmd.take_action(parsed_args, session).await, BlockStorageCommands::Cluster(cmd) => cmd.take_action(parsed_args, session).await, BlockStorageCommands::DefaultType(cmd) => cmd.take_action(parsed_args, session).await, diff --git a/openstack_cli/src/block_storage/v3/availability_zone.rs b/openstack_cli/src/block_storage/v3/availability_zone.rs new file mode 100644 index 000000000..30087952f --- /dev/null +++ b/openstack_cli/src/block_storage/v3/availability_zone.rs @@ -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 + +//! Availability zone management + +use clap::{Parser, Subcommand}; + +use openstack_sdk::AsyncOpenStack; + +use crate::{Cli, OpenStackCliError}; + +mod list; + +/// Availability zones +/// +/// Lists and gets detailed availability zone information. +#[derive(Parser)] +pub struct AvailabilityZoneCommand { + /// subcommand + #[command(subcommand)] + command: AvailabilityZoneCommands, +} + +/// Supported subcommands +#[allow(missing_docs)] +#[derive(Subcommand)] +pub enum AvailabilityZoneCommands { + List(list::AvailabilityZonesCommand), +} + +impl AvailabilityZoneCommand { + /// Perform command action + pub async fn take_action( + &self, + parsed_args: &Cli, + session: &mut AsyncOpenStack, + ) -> Result<(), OpenStackCliError> { + match &self.command { + AvailabilityZoneCommands::List(cmd) => cmd.take_action(parsed_args, session).await, + } + } +} diff --git a/openstack_cli/src/block_storage/v3/availability_zone/list.rs b/openstack_cli/src/block_storage/v3/availability_zone/list.rs new file mode 100644 index 000000000..56fce2427 --- /dev/null +++ b/openstack_cli/src/block_storage/v3/availability_zone/list.rs @@ -0,0 +1,102 @@ +// 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`. + +//! List AvailabilityZones command +//! +//! Wraps invoking of the `v3/os-availability-zone` with `GET` method + +use clap::Args; +use serde::{Deserialize, Serialize}; +use tracing::info; + +use anyhow::Result; + +use openstack_sdk::AsyncOpenStack; + +use crate::output::OutputProcessor; +use crate::Cli; +use crate::OpenStackCliError; +use crate::OutputConfig; +use crate::StructTable; + +use openstack_sdk::api::block_storage::v3::availability_zone::list; +use openstack_sdk::api::QueryAsync; +use serde_json::Value; +use structable_derive::StructTable; + +/// Describe all known availability zones. +/// +#[derive(Args)] +pub struct AvailabilityZonesCommand { + /// Request Query parameters + #[command(flatten)] + query: QueryParameters, + + /// Path parameters + #[command(flatten)] + path: PathParameters, +} + +/// Query parameters +#[derive(Args)] +struct QueryParameters {} + +/// Path parameters +#[derive(Args)] +struct PathParameters {} +/// AvailabilityZones response representation +#[derive(Deserialize, Serialize, Clone, StructTable)] +struct ResponseData { + /// The availability zone name. + /// + #[serde(rename = "zoneName")] + #[structable(optional, title = "zoneName")] + zone_name: Option, + + #[serde(rename = "zoneState")] + #[structable(optional, pretty, title = "zoneState")] + zone_state: Option, +} + +impl AvailabilityZonesCommand { + /// Perform command action + pub async fn take_action( + &self, + parsed_args: &Cli, + client: &mut AsyncOpenStack, + ) -> Result<(), OpenStackCliError> { + info!("List AvailabilityZones"); + + let op = OutputProcessor::from_args(parsed_args); + op.validate_args(parsed_args)?; + + let ep_builder = list::Request::builder(); + + // Set path parameters + // Set query parameters + // Set body parameters + + let ep = ep_builder + .build() + .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?; + + let data: Vec = ep.query_async(client).await?; + + op.output_list::(data)?; + Ok(()) + } +} diff --git a/openstack_cli/src/compute/v2/availability_zone/list.rs b/openstack_cli/src/compute/v2/availability_zone/list.rs index dcf9e21d5..fbc74ddfc 100644 --- a/openstack_cli/src/compute/v2/availability_zone/list.rs +++ b/openstack_cli/src/compute/v2/availability_zone/list.rs @@ -75,13 +75,13 @@ struct ResponseData { /// The availability zone name. /// #[serde(rename = "zoneName")] - #[structable(optional, title = "zoneName", wide)] + #[structable(optional, title = "zoneName")] zone_name: Option, /// The current state of the availability zone. /// #[serde(rename = "zoneState")] - #[structable(optional, pretty, title = "zoneState", wide)] + #[structable(optional, pretty, title = "zoneState")] zone_state: Option, } diff --git a/openstack_cli/src/compute/v2/availability_zone/list_detail.rs b/openstack_cli/src/compute/v2/availability_zone/list_detail.rs index 648d32847..99b43c34d 100644 --- a/openstack_cli/src/compute/v2/availability_zone/list_detail.rs +++ b/openstack_cli/src/compute/v2/availability_zone/list_detail.rs @@ -80,13 +80,13 @@ struct ResponseData { /// The availability zone name. /// #[serde(rename = "zoneName")] - #[structable(optional, title = "zoneName", wide)] + #[structable(optional, title = "zoneName")] zone_name: Option, /// The current state of the availability zone. /// #[serde(rename = "zoneState")] - #[structable(optional, pretty, title = "zoneState", wide)] + #[structable(optional, pretty, title = "zoneState")] zone_state: Option, } diff --git a/openstack_cli/tests/block_storage/v3/availability_zone/list_autogen.rs b/openstack_cli/tests/block_storage/v3/availability_zone/list_autogen.rs new file mode 100644 index 000000000..0fa512ce1 --- /dev/null +++ b/openstack_cli/tests/block_storage/v3/availability_zone/list_autogen.rs @@ -0,0 +1,32 @@ +// 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`. + +use assert_cmd::prelude::*; +use std::process::Command; + +#[test] +fn help() -> Result<(), Box> { + let mut cmd = Command::cargo_bin("osc")?; + + cmd.arg("block-storage") + .arg("availability-zone") + .arg("list") + .arg("--help"); + cmd.assert().success(); + + Ok(()) +} diff --git a/openstack_cli/tests/block_storage/v3/availability_zone/mod.rs b/openstack_cli/tests/block_storage/v3/availability_zone/mod.rs new file mode 100644 index 000000000..363610cec --- /dev/null +++ b/openstack_cli/tests/block_storage/v3/availability_zone/mod.rs @@ -0,0 +1,30 @@ +// 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> { + let mut cmd = Command::cargo_bin("osc")?; + + cmd.arg("block-storage") + .arg("availability-zone") + .arg("--help"); + cmd.assert().success(); + + Ok(()) +} diff --git a/openstack_sdk/src/api/block_storage/v3.rs b/openstack_sdk/src/api/block_storage/v3.rs index 4b0205914..01307e612 100644 --- a/openstack_sdk/src/api/block_storage/v3.rs +++ b/openstack_sdk/src/api/block_storage/v3.rs @@ -14,6 +14,7 @@ //! `Block_storage` Service bindings pub mod attachment; +pub mod availability_zone; pub mod backup; pub mod cluster; pub mod default_type; diff --git a/openstack_sdk/src/api/block_storage/v3/availability_zone.rs b/openstack_sdk/src/api/block_storage/v3/availability_zone.rs new file mode 100644 index 000000000..f3e3fa8e7 --- /dev/null +++ b/openstack_sdk/src/api/block_storage/v3/availability_zone.rs @@ -0,0 +1,19 @@ +// 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`. + +//! `/v3/os-availability-zone` REST operations of block_storage +pub mod list; diff --git a/openstack_sdk/src/api/block_storage/v3/availability_zone/list.rs b/openstack_sdk/src/api/block_storage/v3/availability_zone/list.rs new file mode 100644 index 000000000..e55f344f2 --- /dev/null +++ b/openstack_sdk/src/api/block_storage/v3/availability_zone/list.rs @@ -0,0 +1,160 @@ +// 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`. + +//! Describe all known availability zones. +//! +use derive_builder::Builder; +use http::{HeaderMap, HeaderName, HeaderValue}; + +use crate::api::rest_endpoint_prelude::*; + +#[derive(Builder, Debug, Clone)] +#[builder(setter(strip_option))] +pub struct Request { + #[builder(setter(name = "_headers"), default, private)] + _headers: Option, +} +impl Request { + /// Create a builder for the endpoint. + pub fn builder() -> RequestBuilder { + RequestBuilder::default() + } +} + +impl RequestBuilder { + /// Add a single header to the Availability_Zone. + pub fn header(&mut self, header_name: &'static str, header_value: &'static str) -> &mut Self +where { + self._headers + .get_or_insert(None) + .get_or_insert_with(HeaderMap::new) + .insert(header_name, HeaderValue::from_static(header_value)); + self + } + + /// Add multiple headers. + pub fn headers(&mut self, iter: I) -> &mut Self + where + I: Iterator, + T: Into<(Option, HeaderValue)>, + { + self._headers + .get_or_insert(None) + .get_or_insert_with(HeaderMap::new) + .extend(iter.map(Into::into)); + self + } +} + +impl RestEndpoint for Request { + fn method(&self) -> http::Method { + http::Method::GET + } + + fn endpoint(&self) -> Cow<'static, str> { + "v3/os-availability-zone".to_string().into() + } + + fn parameters(&self) -> QueryParams { + QueryParams::default() + } + + fn service_type(&self) -> ServiceType { + ServiceType::BlockStorage + } + + fn response_key(&self) -> Option> { + Some("availabilityZoneInfo".into()) + } + + /// Returns headers to be set into the request + fn request_headers(&self) -> Option<&HeaderMap> { + self._headers.as_ref() + } +} + +#[cfg(test)] +mod tests { + #![allow(unused_imports)] + use super::*; + use crate::api::Query; + use crate::test::client::MockServerClient; + use crate::types::ServiceType; + use http::{HeaderName, HeaderValue}; + use serde_json::json; + + #[test] + fn test_service_type() { + assert_eq!( + Request::builder().build().unwrap().service_type(), + ServiceType::BlockStorage + ); + } + + #[test] + fn test_response_key() { + assert_eq!( + Request::builder().build().unwrap().response_key().unwrap(), + "availabilityZoneInfo" + ); + } + + #[test] + fn endpoint() { + let client = MockServerClient::new(); + let mock = client.server.mock(|when, then| { + when.method(httpmock::Method::GET) + .path("/v3/os-availability-zone".to_string()); + + then.status(200) + .header("content-type", "application/json") + .json_body(json!({ "availabilityZoneInfo": {} })); + }); + + let endpoint = Request::builder().build().unwrap(); + let _: serde_json::Value = endpoint.query(&client).unwrap(); + mock.assert(); + } + + #[test] + fn endpoint_headers() { + let client = MockServerClient::new(); + let mock = client.server.mock(|when, then| { + when.method(httpmock::Method::GET) + .path("/v3/os-availability-zone".to_string()) + .header("foo", "bar") + .header("not_foo", "not_bar"); + then.status(200) + .header("content-type", "application/json") + .json_body(json!({ "availabilityZoneInfo": {} })); + }); + + let endpoint = Request::builder() + .headers( + [( + Some(HeaderName::from_static("foo")), + HeaderValue::from_static("bar"), + )] + .into_iter(), + ) + .header("not_foo", "not_bar") + .build() + .unwrap(); + let _: serde_json::Value = endpoint.query(&client).unwrap(); + mock.assert(); + } +}