From: Dietmar Maurer Date: Wed, 7 Jan 2015 10:09:30 +0000 (+0100) Subject: update_vm api : add optionnal revert option X-Git-Url: https://git.proxmox.com/?p=qemu-server.git;a=commitdiff_plain;h=d3df8cf3508232a8682bb8beb28ffa9b261270b2 update_vm api : add optionnal revert option Signed-off-by: Alexandre Derumier Signed-off-by: Dietmar Maurer --- diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 7919576..efd836a 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -824,9 +824,11 @@ my $update_vm_api = sub { my $delete_str = extract_param($param, 'delete'); + my $revert_str = extract_param($param, 'revert'); + my $force = extract_param($param, 'force'); - die "no options specified\n" if !$delete_str && !scalar(keys %$param); + die "no options specified\n" if !$delete_str && !$revert_str && !scalar(keys %$param); my $storecfg = PVE::Storage::config(); @@ -836,13 +838,31 @@ my $update_vm_api = sub { # now try to verify all parameters + my $revert = {}; + foreach my $opt (PVE::Tools::split_list($revert_str)) { + if (!PVE::QemuServer::option_exists($opt)) { + raise_param_exc({ revert => "unknown option '$opt'" }); + } + + raise_param_exc({ delete => "you can't use '-$opt' and " . + "-revert $opt' at the same time" }) + if defined($param->{$opt}); + + $revert->{$opt} = 1; + } + my @delete = (); foreach my $opt (PVE::Tools::split_list($delete_str)) { $opt = 'ide2' if $opt eq 'cdrom'; + raise_param_exc({ delete => "you can't use '-$opt' and " . "-delete $opt' at the same time" }) if defined($param->{$opt}); + raise_param_exc({ revert => "you can't use '-delete $opt' and " . + "-revert $opt' at the same time" }) + if $revert->{$opt}; + if (!PVE::QemuServer::option_exists($opt)) { raise_param_exc({ delete => "unknown option '$opt'" }); } @@ -878,6 +898,14 @@ my $update_vm_api = sub { PVE::QemuServer::check_lock($conf) if !$skiplock; + foreach my $opt (keys %$revert) { + if (defined($conf->{$opt})) { + $param->{$opt} = $conf->{$opt}; + } elsif (defined($conf->{pending}->{$opt})) { + push @delete, $opt; + } + } + if ($param->{memory} || defined($param->{balloon})) { my $maxmem = $param->{memory} || $conf->{pending}->{memory} || $conf->{memory} || $defaults->{memory}; my $balloon = defined($param->{balloon}) ? $param->{balloon} : $conf->{pending}->{balloon} || $conf->{balloon};