[pve-devel] applied: [PATCH qemu-server] fix #2580: api/delete: drop VM from HA resources if purge is set

Thomas Lamprecht t.lamprecht at proxmox.com
Thu Mar 12 13:40:09 CET 2020


Signed-off-by: Thomas Lamprecht <t.lamprecht at proxmox.com>
---
 PVE/API2/Qemu.pm | 12 ++++++++++--
 debian/control   |  2 +-
 2 files changed, 11 insertions(+), 3 deletions(-)

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},
-- 
2.20.1





More information about the pve-devel mailing list