[pve-devel] [PATCH manager v4 1/2] fix #474: api: allow transfer from container/vms
Philipp Hufnagl
p.hufnagl at proxmox.com
Thu Aug 10 12:09:01 CEST 2023
When the newly introduced optional parameter "transfer" is set, the user
add a vm/container to a pool even if it is already in one. If so it will
be removed from the old pool
Signed-off-by: Philipp Hufnagl <p.hufnagl at proxmox.com>
---
PVE/API2/Pool.pm | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/PVE/API2/Pool.pm b/PVE/API2/Pool.pm
index 007fc815..3c0ae2a0 100644
--- a/PVE/API2/Pool.pm
+++ b/PVE/API2/Pool.pm
@@ -131,6 +131,11 @@ __PACKAGE__->register_method ({
type => 'string', format => 'pve-storage-id-list',
optional => 1,
},
+ transfer => {
+ description => "Allow transferring VMs to another pool.",
+ type => 'boolean',
+ optional => 1,
+ },
delete => {
description => "Remove vms/storage (instead of adding it).",
type => 'boolean',
@@ -165,8 +170,15 @@ __PACKAGE__->register_method ({
} else {
die "VM $vmid is already a pool member\n" if $pool_config->{vms}->{$vmid};
my $existing_pool = $usercfg->{vms}->{$vmid};
- die "VM $vmid belongs already to pool '$existing_pool'\n" if defined($existing_pool);
-
+ 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";
+ }
+ }
$pool_config->{vms}->{$vmid} = 1;
$usercfg->{vms}->{$vmid} = $pool;
}
--
2.39.2
More information about the pve-devel
mailing list