[pve-devel] [PATCH pve-cluster v2 1/1] notify: add common_template_data
Lukas Wagner
l.wagner at proxmox.com
Fri Mar 28 11:19:10 CET 2025
This commit add the `common_template_data` sub to PVE::Notify,
providing a convenient way to get a hash with properties that
should be accessible from all templates, namely hostname, fqdn
and cluster-name.
Signed-off-by: Lukas Wagner <l.wagner at proxmox.com>
---
Notes:
Changes since v1:
- use PVE::Tools::get_fqdn instead of using `hostname -f` subprocess
to get the fqdn (thx @Thomas!)
src/PVE/Notify.pm | 27 +++++++++++++++++++++++++++
1 file changed, 27 insertions(+)
diff --git a/src/PVE/Notify.pm b/src/PVE/Notify.pm
index c514111..604679f 100644
--- a/src/PVE/Notify.pm
+++ b/src/PVE/Notify.pm
@@ -4,6 +4,9 @@ use strict;
use warnings;
use PVE::Cluster qw(cfs_register_file cfs_read_file cfs_lock_file cfs_write_file);
+use PVE::INotify;
+use PVE::Tools;
+
use Proxmox::RS::Notify;
cfs_register_file(
@@ -130,4 +133,28 @@ sub check_may_use_target {
}
}
+my $cached_fqdn;
+sub common_template_data {
+ # The hostname is already cached by PVE::INotify::nodename,
+ # no need to cache it here as well.
+ my $hostname = PVE::INotify::nodename();
+
+ if (!$cached_fqdn) {
+ $cached_fqdn = PVE::Tools::get_fqdn($hostname);
+ }
+
+ my $data = {
+ hostname => $hostname,
+ fqdn => $cached_fqdn,
+ };
+
+ my $cluster_info = PVE::Cluster::get_clinfo();
+
+ if (my $d = $cluster_info->{cluster}) {
+ $data->{"cluster-name"} = $d->{name};
+ }
+
+ return $data;
+}
+
1;
--
2.39.5
More information about the pve-devel
mailing list