[pve-devel] [PATCH manager 2/3] fix #1278 api: add pool backup option
Tim Marx
t.marx at proxmox.com
Wed Jun 19 12:08:37 CEST 2019
Signed-off-by: Tim Marx <t.marx at proxmox.com>
---
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 2eeba8e5..2222d599 100644
--- a/PVE/API2/Backup.pm
+++ b/PVE/API2/Backup.pm
@@ -444,13 +444,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.11.0
More information about the pve-devel
mailing list