[pbs-devel] [PATCH proxmox-backup 2/2] node: status: declutter kernel-version

Gabriel Goller g.goller at proxmox.com
Thu Nov 23 14:09:35 CET 2023


Return a struct with all the components of the kernel version like it
has been done in pve. Extract and display the build version and kernel
release nicely.

Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
---
 pbs-api-types/src/node.rs | 16 +++++++++++++++-
 src/api2/node/status.rs   | 17 ++++++++---------
 www/panel/NodeInfo.js     |  4 ++++
 3 files changed, 27 insertions(+), 10 deletions(-)

diff --git a/pbs-api-types/src/node.rs b/pbs-api-types/src/node.rs
index 6d1fa7f0..5963658a 100644
--- a/pbs-api-types/src/node.rs
+++ b/pbs-api-types/src/node.rs
@@ -38,6 +38,20 @@ pub struct NodeInformation {
     pub fingerprint: String,
 }
 
+#[api]
+#[derive(Serialize, Deserialize, Default)]
+#[serde(rename_all = "lowercase")]
+/// The current kernel version (output of `uname`)
+pub struct KernelVersionInformation {
+    /// The systemname/nodename
+    pub sysname: String,
+    /// The kernel release number
+    pub release: String,
+    /// The kernel version
+    pub version: String,
+    /// The machine architecture
+    pub machine: String,
+}
 
 #[api]
 #[derive(Serialize, Deserialize, Default)]
@@ -104,7 +118,7 @@ pub struct NodeStatus {
     /// Load for 1, 5 and 15 minutes.
     pub loadavg: [f64; 3],
     /// The current kernel version.
-    pub kversion: String,
+    pub kversion: KernelVersionInformation,
     /// Total CPU usage since last query.
     pub cpu: f64,
     /// Total IO wait since last query.
diff --git a/src/api2/node/status.rs b/src/api2/node/status.rs
index 1b3b9e33..fae2b49b 100644
--- a/src/api2/node/status.rs
+++ b/src/api2/node/status.rs
@@ -1,6 +1,5 @@
 use std::fs::File;
 use std::io::Read;
-use std::os::unix::prelude::OsStrExt;
 use std::path::Path;
 use std::process::Command;
 
@@ -13,8 +12,8 @@ use proxmox_router::{ApiMethod, Permission, Router, RpcEnvironment};
 use proxmox_schema::api;
 
 use pbs_api_types::{
-    BootModeInformation, NodePowerCommand, StorageStatus, NODE_SCHEMA, PRIV_SYS_AUDIT,
-    PRIV_SYS_POWER_MANAGEMENT,
+    BootModeInformation, KernelVersionInformation, NodePowerCommand, StorageStatus, NODE_SCHEMA,
+    PRIV_SYS_AUDIT, PRIV_SYS_POWER_MANAGEMENT,
 };
 
 use pbs_api_types::{
@@ -74,12 +73,12 @@ async fn get_status(
     let cpuinfo = procfs_to_node_cpu_info(cpuinfo);
 
     let uname = nix::sys::utsname::uname()?;
-    let kversion = format!(
-        "{} {} {}",
-        std::str::from_utf8(uname.sysname().as_bytes())?,
-        std::str::from_utf8(uname.release().as_bytes())?,
-        std::str::from_utf8(uname.version().as_bytes())?
-    );
+    let kversion = KernelVersionInformation {
+        sysname: uname.sysname().to_os_string().into_string().unwrap(),
+        release: uname.release().to_os_string().into_string().unwrap(),
+        version: uname.version().to_os_string().into_string().unwrap(),
+        machine: uname.machine().to_os_string().into_string().unwrap(),
+    };
 
     let disk = crate::tools::fs::fs_info_static(proxmox_lang::c_str!("/")).await?;
 
diff --git a/www/panel/NodeInfo.js b/www/panel/NodeInfo.js
index 14f84a2e..25927ebc 100644
--- a/www/panel/NodeInfo.js
+++ b/www/panel/NodeInfo.js
@@ -145,6 +145,10 @@ Ext.define('PBS.NodeInfoPanel', {
 	    title: gettext('Kernel Version'),
 	    printBar: false,
 	    textField: 'kversion',
+	    renderer: (kernel) => {
+	        let buildDate = kernel.version.match(/\((.+)\)\s*$/)[1] ?? 'unknown';
+	        return `${kernel.sysname} ${kernel.release} (${buildDate})`;
+	    },
 	    value: '',
 	},
 	{
-- 
2.39.2






More information about the pbs-devel mailing list