From: Leo Nunner <l.nunner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH manager] fix #4235: vzdump: add cluster-wide configuration
Date: Thu, 9 Feb 2023 10:27:03 +0100 [thread overview]
Message-ID: <20230209092705.29496-2-l.nunner@proxmox.com> (raw)
In-Reply-To: <20230209092705.29496-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>
---
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
next prev parent reply other threads:[~2023-02-09 9:27 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-09 9:27 [pve-devel] [PATCH manager cluster docs] Introduce cluster-wide vzdump configuration Leo Nunner
2023-02-09 9:27 ` Leo Nunner [this message]
2023-02-09 9:27 ` [pve-devel] [PATCH cluster] fix #4234: vzdump: add cluster-wide configuration Leo Nunner
2023-03-03 15:33 ` Thomas Lamprecht
2023-02-09 9:27 ` [pve-devel] [PATCH docs] vzdump: document the new cluster-wide config file Leo Nunner
2023-02-14 10:06 ` 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=20230209092705.29496-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal