From f337626155a1ee71a086c7122ee742148de75980 Mon Sep 17 00:00:00 2001 From: Tim Marx Date: Wed, 19 Jun 2019 12:08:37 +0200 Subject: [PATCH] fix #1278 api: add pool backup option Signed-off-by: Tim Marx --- PVE/API2/Backup.pm | 7 ++++++- PVE/API2/VZDump.pm | 9 +++++++-- PVE/API2Tools.pm | 23 +++++++++++++++++++++++ PVE/VZDump.pm | 12 ++++++++++-- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/PVE/API2/Backup.pm b/PVE/API2/Backup.pm index e8463e67..9a2171cc 100644 --- a/PVE/API2/Backup.pm +++ b/PVE/API2/Backup.pm @@ -453,13 +453,18 @@ __PACKAGE__->register_method({ $job->{$k} = $param->{$k}; } - $job->{all} = 1 if defined($job->{exclude}); + $job->{all} = 1 if (defined($job->{exclude}) && !defined($job->{pool})); if (defined($param->{vmid})) { delete $job->{all}; delete $job->{exclude}; + delete $job->{pool}; } elsif ($param->{all}) { delete $job->{vmid}; + delete $job->{pool}; + } elsif ($job->{pool}) { + delete $job->{vmid}; + delete $job->{all}; } PVE::VZDump::verify_vzdump_parameters($job, 1); diff --git a/PVE/API2/VZDump.pm b/PVE/API2/VZDump.pm index 4e5aec85..8e409674 100644 --- a/PVE/API2/VZDump.pm +++ b/PVE/API2/VZDump.pm @@ -11,6 +11,7 @@ use PVE::AccessControl; use PVE::JSONSchema qw(get_standard_option); use PVE::Storage; use PVE::VZDump; +use PVE::API2Tools; use Data::Dumper; # fixme: remove @@ -70,9 +71,13 @@ __PACKAGE__->register_method ({ return 'OK' if $param->{node} && $param->{node} ne $nodename; my $cmdline = PVE::VZDump::command_line($param); - + my @vmids; # convert string lists to arrays - my @vmids = PVE::Tools::split_list(extract_param($param, 'vmid')); + if ($param->{pool}) { + @vmids = @{PVE::API2Tools::get_resource_pool_guest_members($param->{pool})}; + } else { + @vmids = PVE::Tools::split_list(extract_param($param, 'vmid')); + } if($param->{stop}){ PVE::VZDump::stop_running_backups(); diff --git a/PVE/API2Tools.pm b/PVE/API2Tools.pm index 5ab202b4..e79ac9b2 100644 --- a/PVE/API2Tools.pm +++ b/PVE/API2Tools.pm @@ -231,4 +231,27 @@ sub resolve_proxyto { return $node; } +sub get_resource_pool_guest_members { + my ($pool) = @_; + + my $usercfg = PVE::Cluster::cfs_read_file("user.cfg"); + + my $vmlist = PVE::Cluster::get_vmlist() || {}; + my $idlist = $vmlist->{ids} || {}; + + my $data = $usercfg->{pools}->{$pool}; + + die "pool '$pool' does not exist\n" + if !$data; + + my $members = []; + + foreach my $vmid (keys %{$data->{vms}}) { + my $vmdata = $idlist->{$vmid}; + next if !$vmdata; + push @$members, $vmid; + } + return $members; +} + 1; diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm index 7740da0f..272f40b8 100644 --- a/PVE/VZDump.pm +++ b/PVE/VZDump.pm @@ -175,6 +175,11 @@ my $confdesc = { optional => 1, default => 1, }, + pool => { + type => 'string', + description => 'Backup all known guest systems included in the specified pool.', + optional => 1, + } }; # Load available plugins @@ -1176,7 +1181,10 @@ sub verify_vzdump_parameters { raise_param_exc({ exclude => "option conflicts with option 'vmid'"}) if $param->{exclude} && $param->{vmid}; - $param->{all} = 1 if defined($param->{exclude}); + raise_param_exc({ pool => "option conflicts with option 'vmid'"}) + if $param->{pool} && $param->{vmid}; + + $param->{all} = 1 if (defined($param->{exclude}) && !$param->{pool}); warn "option 'size' is deprecated and will be removed in a future " . "release, please update your script/configuration!\n" @@ -1185,7 +1193,7 @@ sub verify_vzdump_parameters { return if !$check_missing; raise_param_exc({ vmid => "property is missing"}) - if !($param->{all} || $param->{stop}) && !$param->{vmid}; + if !($param->{all} || $param->{stop} || $param->{pool}) && !$param->{vmid}; } -- 2.39.2