[pve-devel] [patch v4 container 1/1] fix #1291: add option purge for destroy_vm api call
Christian Ebner
c.ebner at proxmox.com
Tue Oct 15 13:00:24 CEST 2019
When destroying a CT, 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
src/PVE/API2/LXC.pm | 17 ++++++++++++++---
1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 28c9047..5c22060 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -18,6 +18,7 @@ use PVE::LXC;
use PVE::LXC::Create;
use PVE::LXC::Migrate;
use PVE::GuestHelpers;
+use PVE::VZDump::Plugin;
use PVE::API2::LXC::Config;
use PVE::API2::LXC::Status;
use PVE::API2::LXC::Snapshot;
@@ -636,6 +637,11 @@ __PACKAGE__->register_method({
properties => {
node => get_standard_option('pve-node'),
vmid => get_standard_option('pve-vmid', { completion => \&PVE::LXC::complete_ctid_stopped }),
+ purge => {
+ type => 'boolean',
+ description => "Remove vmid from backup cron jobs.",
+ optional => 1,
+ },
},
},
returns => {
@@ -656,9 +662,13 @@ __PACKAGE__->register_method({
die "unable to remove CT $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);
+ }
my $running_error_msg = "unable to destroy CT $vmid - container is running\n";
@@ -674,6 +684,7 @@ __PACKAGE__->register_method({
PVE::LXC::destroy_lxc_container($storage_cfg, $vmid, $conf);
PVE::AccessControl::remove_vm_access($vmid);
PVE::Firewall::remove_vmfw_conf($vmid);
+ PVE::VZDump::Plugin::remove_vmid_from_backup_jobs($vmid) if ($param->{purge});
};
my $realcmd = sub { PVE::LXC::Config->lock_config($vmid, $code); };
--
2.20.1
More information about the pve-devel
mailing list