From mboxrd@z Thu Jan 1 00:00:00 1970
Return-Path: <l.nunner@proxmox.com>
Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits))
(No client certificate requested)
by lists.proxmox.com (Postfix) with ESMTPS id 1FF21919F6
for <pve-devel@lists.proxmox.com>; Thu, 9 Feb 2023 10:27:43 +0100 (CET)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
by firstgate.proxmox.com (Proxmox) with ESMTP id EDABD219B2
for <pve-devel@lists.proxmox.com>; Thu, 9 Feb 2023 10:27:12 +0100 (CET)
Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com
[94.136.29.106])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (2048 bits))
(No client certificate requested)
by firstgate.proxmox.com (Proxmox) with ESMTPS
for <pve-devel@lists.proxmox.com>; Thu, 9 Feb 2023 10:27:12 +0100 (CET)
Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1])
by proxmox-new.maurer-it.com (Proxmox) with ESMTP id D53A9461FB
for <pve-devel@lists.proxmox.com>; Thu, 9 Feb 2023 10:27:11 +0100 (CET)
From: Leo Nunner <l.nunner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Thu, 9 Feb 2023 10:27:03 +0100
Message-Id: <20230209092705.29496-2-l.nunner@proxmox.com>
X-Mailer: git-send-email 2.30.2
In-Reply-To: <20230209092705.29496-1-l.nunner@proxmox.com>
References: <20230209092705.29496-1-l.nunner@proxmox.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
X-SPAM-LEVEL: Spam detection results: 0
AWL -0.143 Adjusted score from AWL reputation of From: address
BAYES_00 -1.9 Bayes spam probability is 0 to 1%
KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment
SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record
SPF_PASS -0.001 SPF: sender matches SPF record
URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
information. [vzdump.pm]
Subject: [pve-devel] [PATCH manager] fix #4235: vzdump: add cluster-wide
configuration
X-BeenThere: pve-devel@lists.proxmox.com
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com>
List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe>
List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/>
List-Post: <mailto:pve-devel@lists.proxmox.com>
List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help>
List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>,
<mailto:pve-devel-request@lists.proxmox.com?subject=subscribe>
X-List-Received-Date: Thu, 09 Feb 2023 09:27:43 -0000
The different config files get merged in the following order:
/etc/vzdump.conf <- /etc/pve/vzdump.conf <- default values
So the local configuration takes the highest precedence, then the
cluster-wide config, and finally the default values.
Signed-off-by: Leo Nunner <l.nunner@proxmox.com>
---
RFC: I'm not really sure where the cfs_register_file call should go. I
saw that there is one for vzdump.cron in pve-guest-common/src/PVE/VZDump/Common.pm,
but I felt like it was more fitting here, since I was passing the parsing function.
PVE/VZDump.pm | 50 ++++++++++++++++++++++++++++++++++++--------------
1 file changed, 36 insertions(+), 14 deletions(-)
diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
index a04837e7..d0ab03ac 100644
--- a/PVE/VZDump.pm
+++ b/PVE/VZDump.pm
@@ -13,7 +13,7 @@ use IPC::Open3;
use POSIX qw(strftime);
use Time::Local;
-use PVE::Cluster qw(cfs_read_file);
+use PVE::Cluster qw(cfs_register_file cfs_read_file);
use PVE::DataCenterConfig;
use PVE::Exception qw(raise_param_exc);
use PVE::HA::Config;
@@ -258,6 +258,32 @@ sub check_vmids {
return $res;
}
+sub parse_vzdump_conf {
+ my ($fn, $content) = @_;
+
+ return {} if !defined($content);
+
+ my $conf_schema = { type => 'object', properties => $confdesc_for_defaults };
+ my $res = PVE::JSONSchema::parse_config($conf_schema, $fn, $content);
+ if (my $excludes = $res->{'exclude-path'}) {
+ $res->{'exclude-path'} = PVE::Tools::split_args($excludes);
+ }
+ if (defined($res->{mailto})) {
+ my @mailto = split_list($res->{mailto});
+ $res->{mailto} = [ @mailto ];
+ }
+ $parse_prune_backups_maxfiles->($res, "options in '$fn'");
+ parse_performance($res);
+
+ if (defined($res->{storage} && defined($res->{dumpdir}))) {
+ debugmsg('warn', "both 'storage' and 'dumpdir' defined in $fn - ignoring 'dumpdir'");
+ delete $res->{dumpdir};
+ }
+
+ return $res;
+}
+
+cfs_register_file("vzdump.conf", \&parse_vzdump_conf);
sub read_vzdump_defaults {
@@ -266,7 +292,7 @@ sub read_vzdump_defaults {
my $defaults = {
map {
my $default = $confdesc->{$_}->{default};
- defined($default) ? ($_ => $default) : ()
+ defined($default) ? ($_ => $default) : ()
} keys %$confdesc_for_defaults
};
$parse_prune_backups_maxfiles->($defaults, "defaults in VZDump schema");
@@ -274,26 +300,22 @@ sub read_vzdump_defaults {
my $raw;
eval { $raw = PVE::Tools::file_get_contents($fn); };
- return $defaults if $@;
- my $conf_schema = { type => 'object', properties => $confdesc_for_defaults };
- my $res = PVE::JSONSchema::parse_config($conf_schema, $fn, $raw);
- if (my $excludes = $res->{'exclude-path'}) {
- $res->{'exclude-path'} = PVE::Tools::split_args($excludes);
- }
- if (defined($res->{mailto})) {
- my @mailto = split_list($res->{mailto});
- $res->{mailto} = [ @mailto ];
+ my $res = parse_vzdump_conf($fn, $raw);
+
+ # Merge in cluster-wide config
+ my $cluster_conf = cfs_read_file("vzdump.conf");
+ foreach my $key (keys %$cluster_conf) {
+ $res->{$key} = $cluster_conf->{$key} if !defined($res->{$key});
}
- $parse_prune_backups_maxfiles->($res, "options in '$fn'");
- parse_performance($res);
+ # Merge in defaults
foreach my $key (keys %$defaults) {
$res->{$key} = $defaults->{$key} if !defined($res->{$key});
}
if (defined($res->{storage}) && defined($res->{dumpdir})) {
- debugmsg('warn', "both 'storage' and 'dumpdir' defined in '$fn' - ignoring 'dumpdir'");
+ debugmsg('warn', "both 'storage' and 'dumpdir' defined in config - ignoring 'dumpdir'");
delete $res->{dumpdir};
}
--
2.30.2