From: Leo Nunner <l.nunner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH v2 manager 1/2] fix #4235: vzdump: add cluster-wide configuration
Date: Tue, 7 Mar 2023 13:11:04 +0100 [thread overview]
Message-ID: <20230307121106.56820-3-l.nunner@proxmox.com> (raw)
In-Reply-To: <20230307121106.56820-1-l.nunner@proxmox.com>
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>
---
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
next prev parent reply other threads:[~2023-03-07 12:11 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-07 12:11 [pve-devel] [PATCH v2 cluster manager docs] Introduce cluster-wide vzdump configuration Leo Nunner
2023-03-07 12:11 ` [pve-devel] [PATCH v2 cluster] fix #4234: vzdump: add cluster-wide configuration Leo Nunner
2023-03-11 17:12 ` [pve-devel] applied: " Thomas Lamprecht
2023-03-07 12:11 ` Leo Nunner [this message]
2023-03-07 12:11 ` [pve-devel] [PATCH v2 manager 2/2] test: allow access to the cluster-wide 'vzdump.conf' Leo Nunner
2023-03-07 12:11 ` [pve-devel] [PATCH v2 docs] vzdump: document the new cluster-wide config file Leo Nunner
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=20230307121106.56820-3-l.nunner@proxmox.com \
--to=l.nunner@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