Skip to main content

openstack_cli_compute/v2/hypervisor/
show.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//! Show Hypervisor command
19//!
20//! Wraps invoking of the `v2.1/os-hypervisors/{id}` with `GET` 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::compute::v2::hypervisor::get;
32use openstack_types::compute::v2::hypervisor::response;
33
34/// Shows details for a given hypervisor.
35///
36/// Policy defaults enable only users with the administrative role to perform
37/// this operation. Cloud providers can change these permissions through the
38/// `policy.yaml` file.
39///
40/// Normal response codes: 200
41///
42/// Error response codes: badRequest(400), unauthorized(401), forbidden(403),
43/// itemNotFound(404)
44#[derive(Args)]
45#[command(about = "Show Hypervisor Details")]
46pub struct HypervisorCommand {
47    /// Request Query parameters
48    #[command(flatten)]
49    query: QueryParameters,
50
51    /// Path parameters
52    #[command(flatten)]
53    path: PathParameters,
54}
55
56/// Query parameters
57#[derive(Args)]
58struct QueryParameters {
59    #[arg(action=clap::ArgAction::Set, help_heading = "Query parameters", long)]
60    with_servers: Option<bool>,
61}
62
63/// Path parameters
64#[derive(Args)]
65struct PathParameters {
66    /// id parameter for /v2.1/os-hypervisors/{id} API
67    #[arg(
68        help_heading = "Path parameters",
69        id = "path_param_id",
70        value_name = "ID"
71    )]
72    id: String,
73}
74
75impl HypervisorCommand {
76    /// Perform command action
77    pub async fn take_action<C: CliArgs>(
78        &self,
79        parsed_args: &C,
80        client: &mut AsyncOpenStack,
81    ) -> Result<(), OpenStackCliError> {
82        info!("Show Hypervisor");
83
84        let op = OutputProcessor::from_args(parsed_args, Some("compute.hypervisor"), Some("show"));
85        op.validate_args(parsed_args)?;
86
87        let mut ep_builder = get::Request::builder();
88
89        ep_builder.id(&self.path.id);
90        // Set query parameters
91        if let Some(val) = &self.query.with_servers {
92            ep_builder.with_servers(*val);
93        }
94
95        let ep = ep_builder
96            .build()
97            .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
98
99        let data: serde_json::Value = ep.query_async(client).await?;
100
101        op.output_single::<response::get_21::HypervisorResponse>(data.clone())
102            .or_else(|_| op.output_single::<response::get_228::HypervisorResponse>(data.clone()))
103            .or_else(|_| op.output_single::<response::get_253::HypervisorResponse>(data.clone()))
104            .or_else(|_| op.output_single::<response::get_288::HypervisorResponse>(data.clone()))?;
105        // Show command specific hints
106        op.show_command_hint()?;
107        Ok(())
108    }
109}