[pve-devel] [patch v4 qemu 1/1] fix #1291: add option purge for vm_destroy api call
Christian Ebner
c.ebner at proxmox.com
Tue Oct 15 13:00:25 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>
---
version 4:
* no changes since v3
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 267a08e..dcb2d52 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}) {
@@ -1457,6 +1458,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 => {
@@ -1480,9 +1486,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"
@@ -1494,7 +1504,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