[pve-devel] [PATCH v3 qemu 6/7] fix #1291: add option purge for vm_destroy api call
Christian Ebner
c.ebner at proxmox.com
Mon Jul 1 15:43:52 CEST 2019
When destroying a VM, we intentionally did not remove all related configs such as
backup or replication jobs.
The intention of this flag is to allow the removal of such configs on destroy.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
PVE/API2/Qemu.pm | 19 +++++++++++++++----
1 file changed, 15 insertions(+), 4 deletions(-)
diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 5bdd052..2f2a47b 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -28,6 +28,7 @@ use PVE::Network;
use PVE::Firewall;
use PVE::API2::Firewall::VM;
use PVE::API2::Qemu::Agent;
+use PVE::VZDump::Plugin;
BEGIN {
if (!$ENV{PVE_GENERATING_DOCS}) {
@@ -1452,6 +1453,11 @@ __PACKAGE__->register_method({
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid', { completion => \&PVE::QemuServer::complete_vmid_stopped }),
skiplock => get_standard_option('skiplock'),
+ purge => {
+ type => 'boolean',
+ description => "Remove vmid from backup cron jobs.",
+ optional => 1,
+ },
},
},
returns => {
@@ -1475,9 +1481,13 @@ __PACKAGE__->register_method({
die "unable to remove VM $vmid - used in HA resources\n"
if PVE::HA::Config::vm_is_ha_managed($vmid);
- # do not allow destroy if there are replication jobs
- my $repl_conf = PVE::ReplicationConfig->new();
- $repl_conf->check_for_existing_jobs($vmid);
+ if ($param->{purge}) {
+ PVE::ReplicationConfig::remove_vmid_jobs($vmid);
+ } else {
+ # do not allow destroy if there are replication jobs
+ my $repl_conf = PVE::ReplicationConfig->new();
+ $repl_conf->check_for_existing_jobs($vmid);
+ }
# early tests (repeat after locking)
die "VM $vmid is running - destroy failed\n"
@@ -1489,7 +1499,8 @@ __PACKAGE__->register_method({
syslog('info', "destroy VM $vmid: $upid\n");
PVE::QemuServer::vm_destroy($storecfg, $vmid, $skiplock);
PVE::AccessControl::remove_vm_access($vmid);
- PVE::Firewall::remove_vmfw_conf($vmid);
+ PVE::Firewall::remove_vmfw_conf($vmid);
+ PVE::VZDump::Plugin::remove_vmid_from_backup_jobs($vmid) if ($param->{purge});
};
return $rpcenv->fork_worker('qmdestroy', $vmid, $authuser, $realcmd);
--
2.20.1
More information about the pve-devel
mailing list