all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Gabriel Goller <g.goller@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox-backup 2/2] node: status: declutter kernel-version
Date: Thu, 23 Nov 2023 14:09:35 +0100	[thread overview]
Message-ID: <20231123130935.207013-3-g.goller@proxmox.com> (raw)
In-Reply-To: <20231123130935.207013-1-g.goller@proxmox.com>

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@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





  parent reply	other threads:[~2023-11-23 13:10 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-23 13:09 [pbs-devel] [PATCH proxmox-backup 0/2] Add bootmode, improve kernel version Gabriel Goller
2023-11-23 13:09 ` [pbs-devel] [PATCH proxmox-backup 1/2] node: status: added bootmode Gabriel Goller
2023-11-23 16:32   ` Thomas Lamprecht
2023-11-24  9:04     ` Gabriel Goller
2023-11-24  9:11       ` Thomas Lamprecht
2023-11-23 13:09 ` Gabriel Goller [this message]
2023-11-23 16:15   ` [pbs-devel] [PATCH proxmox-backup 2/2] node: status: declutter kernel-version Dietmar Maurer
2023-11-23 16:29     ` Thomas Lamprecht
2023-11-23 16:35       ` Thomas Lamprecht
2023-11-24  9:13       ` Gabriel Goller
2023-11-23 16:28   ` Thomas Lamprecht
2023-11-24 12:02 ` [pbs-devel] [PATCH proxmox-backup 0/2] Add bootmode, improve kernel version Gabriel Goller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231123130935.207013-3-g.goller@proxmox.com \
    --to=g.goller@proxmox.com \
    --cc=pbs-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal