From: Thomas Lamprecht Date: Thu, 12 Mar 2020 12:31:41 +0000 (+0100) Subject: fix #2580: api/delete: drop VM from HA resources if purge is set X-Git-Url: https://git.proxmox.com/?p=qemu-server.git;a=commitdiff_plain;h=7c4351f7d4334dca942c2a1b489480cfc84c48ae fix #2580: api/delete: drop VM from HA resources if purge is set Signed-off-by: Thomas Lamprecht --- diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index 036d95d..d8d3f3e 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -1471,10 +1471,12 @@ __PACKAGE__->register_method({ my $conf = PVE::QemuConfig->load_config($vmid); my $storecfg = PVE::Storage::config(); PVE::QemuConfig->check_protection($conf, "can't remove VM $vmid"); - die "unable to remove VM $vmid - used in HA resources\n" - if PVE::HA::Config::vm_is_ha_managed($vmid); + + my $ha_managed = PVE::HA::Config::service_is_configured("vm:$vmid"); if (!$param->{purge}) { + die "unable to remove VM $vmid - used in HA resources and purge parameter not set.\n" + if $ha_managed; # don't allow destroy if with replication jobs but no purge param my $repl_conf = PVE::ReplicationConfig->new(); $repl_conf->check_for_existing_jobs($vmid); @@ -1497,8 +1499,14 @@ __PACKAGE__->register_method({ PVE::AccessControl::remove_vm_access($vmid); PVE::Firewall::remove_vmfw_conf($vmid); if ($param->{purge}) { + print "purging VM $vmid from related configurations..\n"; PVE::ReplicationConfig::remove_vmid_jobs($vmid); PVE::VZDump::Plugin::remove_vmid_from_backup_jobs($vmid); + + if ($ha_managed) { + PVE::HA::Config::delete_service_from_config("vm:$vmid"); + print "NOTE: removed VM $vmid from HA resource configuration.\n"; + } } # only now remove the zombie config, else we can have reuse race diff --git a/debian/control b/debian/control index 3473b9c..41762fc 100644 --- a/debian/control +++ b/debian/control @@ -43,7 +43,7 @@ Depends: dbus, pve-cluster, pve-edk2-firmware (>= 1.20181023-1), pve-firewall, - pve-ha-manager (>= 3.0-3), + pve-ha-manager (>= 3.0-9), pve-qemu-kvm (>= 3.0.1-62), socat, ${misc:Depends},