public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lukas Wagner <l.wagner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH pve-cluster v2 1/1] notify: add common_template_data
Date: Fri, 28 Mar 2025 11:19:10 +0100	[thread overview]
Message-ID: <20250328101915.73951-2-l.wagner@proxmox.com> (raw)
In-Reply-To: <20250328101915.73951-1-l.wagner@proxmox.com>

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



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  reply	other threads:[~2025-03-28 10:19 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-28 10:19 [pve-devel] [PATCH cluster/ha-manager/manager v2 0/6] preparation for #6143: notification template cleanup Lukas Wagner
2025-03-28 10:19 ` Lukas Wagner [this message]
2025-04-04 10:15   ` [pve-devel] applied: [PATCH pve-cluster v2 1/1] notify: add common_template_data Thomas Lamprecht
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 1/4] notification templates: vzdump: generate HTML table in template Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 2/4] notifications: apt: clean up notification template Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 3/4] notification: replication: add common properties to template data Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-manager v2 4/4] notifications: test: style fixup Lukas Wagner
2025-03-28 10:19 ` [pve-devel] [PATCH pve-ha-manager v2 1/1] notifications: overhaul fence notification Lukas Wagner
2025-04-04 18:25   ` [pve-devel] applied: " Thomas Lamprecht
2025-04-04 18:27 ` [pve-devel] applied-series: [PATCH cluster/ha-manager/manager v2 0/6] preparation for #6143: notification template cleanup Thomas Lamprecht

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=20250328101915.73951-2-l.wagner@proxmox.com \
    --to=l.wagner@proxmox.com \
    --cc=pve-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal