]> git.proxmox.com Git - pve-manager.git/commitdiff
api: pool update: refactor/code-clean-up guest handling
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 8 Sep 2023 11:30:41 +0000 (13:30 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Fri, 8 Sep 2023 11:36:38 +0000 (13:36 +0200)
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
PVE/API2/Pool.pm

index 2463207e308d594894f7473fcaceaaf21681e5e8..ffcc3946ea1330c23db00449e793ab53fd1135fd 100644 (file)
@@ -172,15 +172,12 @@ __PACKAGE__->register_method ({
                        delete $usercfg->{vms}->{$vmid};
                    } else {
                        die "VM $vmid is already a pool member\n" if $pool_config->{vms}->{$vmid};
-                       my $existing_pool = $usercfg->{vms}->{$vmid};
-                       if (defined($existing_pool)) {
-                           if ($param->{transfer}) {
-                               $rpcenv->check($authuser, "/pool/$existing_pool", ['Pool.Allocate']);
-                               my $existing_pool_config = $usercfg->{pools}->{$existing_pool};
-                               delete $existing_pool_config->{vms}->{$vmid};
-                           } else {
-                               die "VM $vmid belongs already to pool '$existing_pool' and transfer is not set\n";
-                           }
+                       if (defined(my $existing_pool = $usercfg->{vms}->{$vmid})) {
+                           die "VM $vmid belongs already to pool '$existing_pool' and 'transfer' is not set\n"
+                            if !$param->{transfer};
+
+                           $rpcenv->check($authuser, "/pool/$existing_pool", ['Pool.Allocate']);
+                           delete $usercfg->{pools}->{$existing_pool}->{vms}->{$vmid};
                        }
                        $pool_config->{vms}->{$vmid} = 1;
                        $usercfg->{vms}->{$vmid} = $pool;