Skip to content

Commit 8f4d6f7

Browse files
committed
Add version returning grpc call to host-service
Signed-off-by: Guvenc Gulce <guevenc.guelce@sap.com>
1 parent a8f8491 commit 8f4d6f7

File tree

7 files changed

+97
-16
lines changed

7 files changed

+97
-16
lines changed

cli/src/host_commands.rs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use anyhow::{Context, Result};
22
use clap::{Args, Subcommand};
33
use feos_proto::host_service::{
44
host_service_client::HostServiceClient, GetCpuInfoRequest, GetNetworkInfoRequest,
5-
HostnameRequest, MemoryRequest, RebootRequest, ShutdownRequest, StreamFeosLogsRequest,
6-
StreamKernelLogsRequest, UpgradeFeosBinaryRequest,
5+
GetVersionInfoRequest, HostnameRequest, MemoryRequest, RebootRequest, ShutdownRequest,
6+
StreamFeosLogsRequest, StreamKernelLogsRequest, UpgradeFeosBinaryRequest,
77
};
88
use tokio_stream::StreamExt;
99
use tonic::transport::Channel;
@@ -47,6 +47,8 @@ pub enum HostCommand {
4747
Shutdown,
4848
/// Reboot the host machine
4949
Reboot,
50+
/// Get kernel and FeOS version information
51+
VersionInfo,
5052
}
5153

5254
pub async fn handle_host_command(args: HostArgs) -> Result<()> {
@@ -66,6 +68,7 @@ pub async fn handle_host_command(args: HostArgs) -> Result<()> {
6668
HostCommand::Flogs => stream_flogs(&mut client).await?,
6769
HostCommand::Shutdown => shutdown_host(&mut client).await?,
6870
HostCommand::Reboot => reboot_host(&mut client).await?,
71+
HostCommand::VersionInfo => get_version_info(&mut client).await?,
6972
}
7073

7174
Ok(())
@@ -286,6 +289,15 @@ async fn upgrade_feos(
286289
Ok(())
287290
}
288291

292+
async fn get_version_info(client: &mut HostServiceClient<Channel>) -> Result<()> {
293+
println!("Requesting version information...");
294+
let request = GetVersionInfoRequest {};
295+
let response = client.get_version_info(request).await?.into_inner();
296+
println!("FeOS Version: {}", response.feos_version);
297+
println!("Kernel Version: {}", response.kernel_version);
298+
Ok(())
299+
}
300+
289301
async fn shutdown_host(client: &mut HostServiceClient<Channel>) -> Result<()> {
290302
println!("Requesting host shutdown...");
291303
let request = ShutdownRequest {};

feos/services/host-service/src/api.rs

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
use crate::Command;
22
use feos_proto::host_service::{
33
host_service_server::HostService, FeosLogEntry, GetCpuInfoRequest, GetCpuInfoResponse,
4-
GetNetworkInfoRequest, GetNetworkInfoResponse, HostnameRequest, HostnameResponse,
5-
KernelLogEntry, MemoryRequest, MemoryResponse, RebootRequest, RebootResponse, ShutdownRequest,
6-
ShutdownResponse, StreamFeosLogsRequest, StreamKernelLogsRequest, UpgradeFeosBinaryRequest,
7-
UpgradeFeosBinaryResponse,
4+
GetNetworkInfoRequest, GetNetworkInfoResponse, GetVersionInfoRequest, GetVersionInfoResponse,
5+
HostnameRequest, HostnameResponse, KernelLogEntry, MemoryRequest, MemoryResponse,
6+
RebootRequest, RebootResponse, ShutdownRequest, ShutdownResponse, StreamFeosLogsRequest,
7+
StreamKernelLogsRequest, UpgradeFeosBinaryRequest, UpgradeFeosBinaryResponse,
88
};
99
use log::info;
1010
use std::pin::Pin;
@@ -204,4 +204,25 @@ impl HostService for HostApiHandler {
204204
let output_stream = ReceiverStream::new(stream_rx);
205205
Ok(Response::new(Box::pin(output_stream)))
206206
}
207+
208+
async fn get_version_info(
209+
&self,
210+
_request: Request<GetVersionInfoRequest>,
211+
) -> Result<Response<GetVersionInfoResponse>, Status> {
212+
info!("HOST_API_HANDLER: Received GetVersionInfo request.");
213+
let (resp_tx, resp_rx) = oneshot::channel();
214+
let cmd = Command::GetVersionInfo(resp_tx);
215+
self.dispatcher_tx
216+
.send(cmd)
217+
.await
218+
.map_err(|e| Status::internal(format!("Failed to send command to dispatcher: {e}")))?;
219+
220+
match resp_rx.await {
221+
Ok(Ok(result)) => Ok(Response::new(result)),
222+
Ok(Err(status)) => Err(status),
223+
Err(_) => Err(Status::internal(
224+
"Dispatcher task dropped response channel.",
225+
)),
226+
}
227+
}
207228
}

feos/services/host-service/src/dispatcher.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ impl HostServiceDispatcher {
3838
Command::GetNetworkInfo(responder) => {
3939
tokio::spawn(worker::handle_get_network_info(responder));
4040
}
41+
Command::GetVersionInfo(responder) => {
42+
tokio::spawn(worker::handle_get_version_info(responder));
43+
}
4144
Command::UpgradeFeosBinary(req, responder) => {
4245
let restart_tx = self.restart_tx.clone();
4346
tokio::spawn(worker::handle_upgrade(restart_tx, req, responder));

feos/services/host-service/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use feos_proto::host_service::{
2-
FeosLogEntry, GetCpuInfoResponse, GetNetworkInfoResponse, HostnameResponse, KernelLogEntry,
3-
MemoryResponse, RebootRequest, RebootResponse, ShutdownRequest, ShutdownResponse,
4-
UpgradeFeosBinaryRequest, UpgradeFeosBinaryResponse,
2+
FeosLogEntry, GetCpuInfoResponse, GetNetworkInfoResponse, GetVersionInfoResponse,
3+
HostnameResponse, KernelLogEntry, MemoryResponse, RebootRequest, RebootResponse,
4+
ShutdownRequest, ShutdownResponse, UpgradeFeosBinaryRequest, UpgradeFeosBinaryResponse,
55
};
66
use std::path::PathBuf;
77
use tokio::sync::{mpsc, oneshot};
@@ -17,6 +17,7 @@ pub enum Command {
1717
GetMemory(oneshot::Sender<Result<MemoryResponse, Status>>),
1818
GetCPUInfo(oneshot::Sender<Result<GetCpuInfoResponse, Status>>),
1919
GetNetworkInfo(oneshot::Sender<Result<GetNetworkInfoResponse, Status>>),
20+
GetVersionInfo(oneshot::Sender<Result<GetVersionInfoResponse, Status>>),
2021
UpgradeFeosBinary(
2122
UpgradeFeosBinaryRequest,
2223
oneshot::Sender<Result<UpgradeFeosBinaryResponse, Status>>,

feos/services/host-service/src/worker/info.rs

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use feos_proto::host_service::{
2-
CpuInfo, GetCpuInfoResponse, GetNetworkInfoResponse, HostnameResponse, MemInfo, MemoryResponse,
3-
NetDev,
2+
CpuInfo, GetCpuInfoResponse, GetNetworkInfoResponse, GetVersionInfoResponse, HostnameResponse,
3+
MemInfo, MemoryResponse, NetDev,
44
};
55
use log::{error, info, warn};
66
use nix::unistd;
@@ -22,7 +22,7 @@ pub async fn handle_hostname(responder: oneshot::Sender<Result<HostnameResponse,
2222
}
2323
Err(e) => {
2424
let msg = format!("Failed to get system hostname: {e}");
25-
error!("HOST_WORKER: ERROR - {msg}");
25+
error!("HOST_WORKER: {msg}");
2626
Err(Status::internal(msg))
2727
}
2828
};
@@ -117,7 +117,7 @@ pub async fn handle_get_memory(responder: oneshot::Sender<Result<MemoryResponse,
117117
mem_info: Some(mem_info),
118118
}),
119119
Err(e) => {
120-
error!("HOST_WORKER: ERROR - Failed to get memory info: {e}");
120+
error!("HOST_WORKER: Failed to get memory info: {e}");
121121
Err(Status::internal(format!("Failed to get memory info: {e}")))
122122
}
123123
};
@@ -208,7 +208,7 @@ pub async fn handle_get_cpu_info(responder: oneshot::Sender<Result<GetCpuInfoRes
208208
let result = match read_and_parse_cpuinfo().await {
209209
Ok(cpu_info) => Ok(GetCpuInfoResponse { cpu_info }),
210210
Err(e) => {
211-
error!("HOST_WORKER: ERROR - Failed to get CPU info: {e}");
211+
error!("HOST_WORKER: Failed to get CPU info: {e}");
212212
Err(Status::internal(format!("Failed to get CPU info: {e}")))
213213
}
214214
};
@@ -281,7 +281,7 @@ pub async fn handle_get_network_info(
281281
let result = match read_all_net_stats().await {
282282
Ok(devices) => Ok(GetNetworkInfoResponse { devices }),
283283
Err(e) => {
284-
error!("HOST_WORKER: ERROR - Failed to get network info: {e}");
284+
error!("HOST_WORKER: Failed to get network info: {e}");
285285
Err(Status::internal(format!(
286286
"Failed to get network info from sysfs: {e}"
287287
)))
@@ -294,3 +294,32 @@ pub async fn handle_get_network_info(
294294
);
295295
}
296296
}
297+
298+
pub async fn handle_get_version_info(
299+
responder: oneshot::Sender<Result<GetVersionInfoResponse, Status>>,
300+
) {
301+
info!("HOST_WORKER: Processing GetVersionInfo request.");
302+
303+
let kernel_version_res = fs::read_to_string("/proc/version").await;
304+
305+
let result = match kernel_version_res {
306+
Ok(kernel_version) => {
307+
let feos_version = env!("CARGO_PKG_VERSION").to_string();
308+
Ok(GetVersionInfoResponse {
309+
kernel_version: kernel_version.trim().to_string(),
310+
feos_version,
311+
})
312+
}
313+
Err(e) => {
314+
let msg = format!("Failed to read kernel version from /proc/version: {e}");
315+
error!("HOST_WORKER: {msg}");
316+
Err(Status::internal(msg))
317+
}
318+
};
319+
320+
if responder.send(result).is_err() {
321+
error!(
322+
"HOST_WORKER: Failed to send response for GetVersionInfo. API handler may have timed out."
323+
);
324+
}
325+
}

feos/services/host-service/src/worker/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ pub mod info;
22
pub mod ops;
33
pub mod power;
44

5-
pub use info::{handle_get_cpu_info, handle_get_memory, handle_get_network_info, handle_hostname};
5+
pub use info::{
6+
handle_get_cpu_info, handle_get_memory, handle_get_network_info, handle_get_version_info,
7+
handle_hostname,
8+
};
69
pub use ops::{handle_stream_feos_logs, handle_stream_kernel_logs, handle_upgrade};
710
pub use power::{handle_reboot, handle_shutdown};

proto/v1/host.proto

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ service HostService {
2323

2424
// Streams logs from the internal FeOS logger.
2525
rpc StreamFeOSLogs(StreamFeosLogsRequest) returns (stream FeosLogEntry);
26+
27+
// Retrieves version information about the host system.
28+
rpc GetVersionInfo(GetVersionInfoRequest) returns (GetVersionInfoResponse);
2629
}
2730

2831
message HostnameRequest {}
@@ -181,4 +184,13 @@ message FeosLogEntry {
181184
string level = 3;
182185
string target = 4;
183186
string message = 5;
187+
}
188+
189+
message GetVersionInfoRequest {}
190+
191+
message GetVersionInfoResponse {
192+
// The version of the Linux kernel (e.g., from /proc/version).
193+
string kernel_version = 1;
194+
// The version of the running FeOS binary.
195+
string feos_version = 2;
184196
}

0 commit comments

Comments
 (0)