* [pmg-devel] applied: [PATCH api 1/2] api: node status: return structured info about current kernel
@ 2024-02-26 15:15 Thomas Lamprecht
2024-02-26 15:15 ` [pmg-devel] applied: [PATCH api 2/2] api: node status: return info about current boot mode Thomas Lamprecht
0 siblings, 1 reply; 2+ messages in thread
From: Thomas Lamprecht @ 2024-02-26 15:15 UTC (permalink / raw)
To: pmg-devel
Makes it easier to show selectively what's important, as the whole
string got quite a bit unwieldy lately.
Mirrors commit 20ad4e0e ("api: nodes: add full info about current
kernel from uname call") from pve-manager.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
src/PMG/API2/Nodes.pm | 41 ++++++++++++++++++++++++++++++++++++++---
1 file changed, 38 insertions(+), 3 deletions(-)
diff --git a/src/PMG/API2/Nodes.pm b/src/PMG/API2/Nodes.pm
index 873434b..c1a39e1 100644
--- a/src/PMG/API2/Nodes.pm
+++ b/src/PMG/API2/Nodes.pm
@@ -679,6 +679,19 @@ __PACKAGE__->register_method({
return undef;
}});
+my sub get_current_kernel_info {
+ my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
+
+ my $kernel_version_string = "$sysname $release $version"; # for legacy compat
+ my $current_kernel = {
+ sysname => $sysname,
+ release => $release,
+ version => $version,
+ machine => $machine,
+ };
+ return ($current_kernel, $kernel_version_string);
+}
+
__PACKAGE__->register_method({
name => 'status',
path => 'status',
@@ -711,6 +724,28 @@ __PACKAGE__->register_method({
description => "Database is synced with other nodes.",
type => 'boolean',
},
+ 'current-kernel' => {
+ description => "Meta-information about the currently booted kernel.",
+ type => 'object',
+ properties => {
+ sysname => {
+ description => 'OS kernel name (e.g., "Linux")',
+ type => 'string',
+ },
+ release => {
+ description => 'OS kernel release (e.g., "6.8.0")',
+ type => 'string',
+ },
+ version => {
+ description => 'OS kernel version with build info',
+ type => 'string',
+ },
+ machine => {
+ description => 'Hardware (architecture) type',
+ type => 'string',
+ },
+ },
+ },
},
},
code => sub {
@@ -737,9 +772,9 @@ __PACKAGE__->register_method({
my ($avg1, $avg5, $avg15) = PVE::ProcFSTools::read_loadavg();
$res->{loadavg} = [ $avg1, $avg5, $avg15];
- my ($sysname, $nodename, $release, $version, $machine) = POSIX::uname();
-
- $res->{kversion} = "$sysname $release $version";
+ my ($current_kernel_info, $kversion_string) = get_current_kernel_info();
+ $res->{kversion} = $kversion_string;
+ $res->{'current-kernel'} = $current_kernel_info;
$res->{cpuinfo} = PVE::ProcFSTools::read_cpuinfo();
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
* [pmg-devel] applied: [PATCH api 2/2] api: node status: return info about current boot mode
2024-02-26 15:15 [pmg-devel] applied: [PATCH api 1/2] api: node status: return structured info about current kernel Thomas Lamprecht
@ 2024-02-26 15:15 ` Thomas Lamprecht
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Lamprecht @ 2024-02-26 15:15 UTC (permalink / raw)
To: pmg-devel
report if the node is booted in EFI or Legacy BIOS mode, for the
former also pass along the secure boot state.
Mirrors commit 81fd95cf ("api: nodes: add info about current boot
mode") from pve-manager.
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
---
src/PMG/API2/Nodes.pm | 42 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 42 insertions(+)
diff --git a/src/PMG/API2/Nodes.pm b/src/PMG/API2/Nodes.pm
index c1a39e1..304c2cf 100644
--- a/src/PMG/API2/Nodes.pm
+++ b/src/PMG/API2/Nodes.pm
@@ -692,6 +692,30 @@ my sub get_current_kernel_info {
return ($current_kernel, $kernel_version_string);
}
+my $boot_mode_info_cache;
+my sub get_boot_mode_info {
+ return $boot_mode_info_cache if defined($boot_mode_info_cache);
+
+ my $is_efi_booted = -d "/sys/firmware/efi";
+
+ $boot_mode_info_cache = {
+ mode => $is_efi_booted ? 'efi' : 'legacy-bios',
+ };
+
+ my $efi_var = "/sys/firmware/efi/efivars/SecureBoot-8be4df61-93ca-11d2-aa0d-00e098032b8c";
+
+ if ($is_efi_booted && -e $efi_var) {
+ my $efi_var_sec_boot_entry = eval { file_get_contents($efi_var) };
+ if ($@) {
+ warn "Failed to read secure boot state: $@\n";
+ } else {
+ my @secureboot = unpack("CCCCC", $efi_var_sec_boot_entry);
+ $boot_mode_info_cache->{secureboot} = $secureboot[4] == 1 ? 1 : 0;
+ }
+ }
+ return $boot_mode_info_cache;
+}
+
__PACKAGE__->register_method({
name => 'status',
path => 'status',
@@ -724,6 +748,22 @@ __PACKAGE__->register_method({
description => "Database is synced with other nodes.",
type => 'boolean',
},
+ 'boot-info' => {
+ description => "Meta-information about the boot mode.",
+ type => 'object',
+ properties => {
+ mode => {
+ description => 'Through which firmware the system got booted.',
+ type => 'string',
+ enum => [qw(efi legacy-bios)],
+ },
+ secureboot => {
+ description => 'System is booted in secure mode, only applicable for the "efi" mode.',
+ type => 'boolean',
+ optional => 1,
+ },
+ },
+ },
'current-kernel' => {
description => "Meta-information about the currently booted kernel.",
type => 'object',
@@ -776,6 +816,8 @@ __PACKAGE__->register_method({
$res->{kversion} = $kversion_string;
$res->{'current-kernel'} = $current_kernel_info;
+ $res->{'boot-info'} = get_boot_mode_info();
+
$res->{cpuinfo} = PVE::ProcFSTools::read_cpuinfo();
my $stat = PVE::ProcFSTools::read_proc_stat();
--
2.39.2
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-02-26 17:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-26 15:15 [pmg-devel] applied: [PATCH api 1/2] api: node status: return structured info about current kernel Thomas Lamprecht
2024-02-26 15:15 ` [pmg-devel] applied: [PATCH api 2/2] api: node status: return info about current boot mode Thomas Lamprecht
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox