openstack_cli_compute/v2/server/os_get_console_output.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//! Action Server command
19//!
20//! Wraps invoking of the `v2.1/servers/{id}/action` with `POST` method
21
22use clap::Args;
23use eyre::WrapErr;
24use tracing::info;
25
26use openstack_cli_core::cli::CliArgs;
27use openstack_cli_core::error::OpenStackCliError;
28use openstack_cli_core::output::OutputProcessor;
29use openstack_sdk::AsyncOpenStack;
30
31use openstack_sdk::api::QueryAsync;
32use openstack_sdk::api::compute::v2::server::os_get_console_output;
33use openstack_types::compute::v2::server::response;
34
35/// Shows console output for a server.
36///
37/// This API returns the text of the console since boot. The content returned
38/// may be large. Limit the lines of console text, beginning at the tail of the
39/// content, by setting the optional `length` parameter in the request body.
40///
41/// The server to get console log from should set `export LC_ALL=en_US.UTF-8`
42/// in order to avoid incorrect unicode error.
43///
44/// Normal response codes: 200
45///
46/// Error response codes: unauthorized(401), forbidden(403), notFound(404),
47/// conflict(409), methodNotImplemented(501)
48#[derive(Args)]
49#[command(about = "Show Console Output (os-getConsoleOutput Action)")]
50pub struct ServerCommand {
51 /// Request Query parameters
52 #[command(flatten)]
53 query: QueryParameters,
54
55 /// Path parameters
56 #[command(flatten)]
57 path: PathParameters,
58
59 /// The action to get console output of the server.
60 #[command(flatten)]
61 os_get_console_output: OsGetConsoleOutput,
62}
63
64/// Query parameters
65#[derive(Args)]
66struct QueryParameters {}
67
68/// Path parameters
69#[derive(Args)]
70struct PathParameters {
71 /// id parameter for /v2.1/servers/{id}/action API
72 #[arg(
73 help_heading = "Path parameters",
74 id = "path_param_id",
75 value_name = "ID"
76 )]
77 id: String,
78}
79/// OsGetConsoleOutput Body data
80#[derive(Args, Clone)]
81struct OsGetConsoleOutput {
82 /// The number of lines to fetch from the end of console log. All lines
83 /// will be returned if this is not specified.
84 ///
85 /// Note
86 ///
87 /// This parameter can be specified as not only ‘integer’ but also
88 /// ‘string’.
89 #[arg(help_heading = "Body parameters", long)]
90 length: Option<Option<i32>>,
91}
92
93impl ServerCommand {
94 /// Perform command action
95 pub async fn take_action<C: CliArgs>(
96 &self,
97 parsed_args: &C,
98 client: &mut AsyncOpenStack,
99 ) -> Result<(), OpenStackCliError> {
100 info!("Action Server");
101
102 let op = OutputProcessor::from_args(
103 parsed_args,
104 Some("compute.server"),
105 Some("os_get_console_output"),
106 );
107 op.validate_args(parsed_args)?;
108
109 let mut ep_builder = os_get_console_output::Request::builder();
110
111 ep_builder.id(&self.path.id);
112
113 // Set body parameters
114 // Set Request.os_get_console_output data
115 let args = &self.os_get_console_output;
116 let mut os_get_console_output_builder =
117 os_get_console_output::OsGetConsoleOutputBuilder::default();
118 if let Some(val) = &args.length {
119 os_get_console_output_builder.length(*val);
120 }
121
122 ep_builder.os_get_console_output(
123 os_get_console_output_builder
124 .build()
125 .wrap_err("error preparing the request data")?,
126 );
127
128 let ep = ep_builder
129 .build()
130 .map_err(|x| OpenStackCliError::EndpointBuild(x.to_string()))?;
131
132 let data: serde_json::Value = ep.query_async(client).await?;
133
134 op.output_single::<response::os_get_console_output::ServerResponse>(data.clone())?;
135 // Show command specific hints
136 op.show_command_hint()?;
137 Ok(())
138 }
139}