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

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


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

diff --git a/debian/control b/debian/control
index ee44483..056174c 100644
--- a/debian/control
+++ b/debian/control
@@ -25,7 +25,7 @@ Depends: file,
          libpve-storage-perl (>= 5.0-31),
          lxc-pve,
          pve-cluster (>= 4.0-8),
-         pve-ha-manager (>= 3.0-3),
+         pve-ha-manager (>= 3.0-9),
          pve-lxc-syscalld,
          xz-utils,
          ${misc:Depends},
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index a48cf95..a5aa5fc 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -662,10 +662,12 @@ __PACKAGE__->register_method({
 	my $storage_cfg = cfs_read_file("storage.cfg");
 	PVE::LXC::Config->check_protection($conf, "can't remove CT $vmid");
 
-	die "unable to remove CT $vmid - used in HA resources\n"
-	    if PVE::HA::Config::vm_is_ha_managed($vmid);
+	my $ha_managed = PVE::HA::Config::service_is_configured("ct:$vmid");
 
 	if (!$param->{purge}) {
+	    die "unable to remove CT $vmid - used in HA resources and purge parameter not set.\n"
+		if $ha_managed;
+
 	    # do not allow destroy if there are replication jobs without purge
 	    my $repl_conf = PVE::ReplicationConfig->new();
 	    $repl_conf->check_for_existing_jobs($vmid);
@@ -687,8 +689,14 @@ __PACKAGE__->register_method({
 	    PVE::AccessControl::remove_vm_access($vmid);
 	    PVE::Firewall::remove_vmfw_conf($vmid);
 	    if ($param->{purge}) {
+	        print "purging CT $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("ct:$vmid");
+		    print "NOTE: removed CT $vmid from HA resource configuration.\n";
+		}
 	    }
 
 	    # only now remove the zombie config, else we can have reuse race
-- 
2.20.1





More information about the pve-devel mailing list