[pve-devel] [RFC pve-container] CT protection mode added

Alen Grizonic a.grizonic at proxmox.com
Thu Sep 3 16:59:29 CEST 2015


---
 src/PVE/API2/LXC.pm |  3 +++
 src/PVE/LXC.pm      | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index d5acace..fbc2eda 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -535,6 +535,9 @@ __PACKAGE__->register_method({
 
 	my $storage_cfg = cfs_read_file("storage.cfg");
 
+	die  "can't remove CT $vmid - protection mode enabled\n"
+	    if ($conf->{protection} == 1);
+
 	die "unable to remove CT $vmid - used in HA resources\n"
 	    if PVE::HA::Config::vm_is_ha_managed($vmid);
 
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index e296047..74d6ce8 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -175,6 +175,12 @@ my $confdesc = {
 	enum => ['shell', 'console', 'tty'],
 	default => 'tty',
     },
+    protection => {
+	optional => 1,
+	type => 'boolean',
+	description => "Sets the protection flag of the container. This will prevent the remove operation.",
+	default => 0,
+    },
 };
 
 my $valid_lxc_conf_keys = {
@@ -1097,6 +1103,8 @@ sub update_pct_config {
 		next if !$running;
 		my $netid = $1;
 		PVE::Network::veth_delete("veth${vmid}i$netid");
+	    } elsif ($opt eq 'protection') {
+		delete $conf->{$opt};
 	    } elsif ($opt eq 'rootfs' || $opt =~ m/^mp(\d+)$/) {
 		die "implement me"
 	    } else {
@@ -1165,6 +1173,8 @@ sub update_pct_config {
 	    } else {
 		update_net($vmid, $conf, $opt, $net, $netid, $rootdir);
 	    }
+	} elsif ($opt eq 'protection') {
+	    $conf->{$opt} = $value ? 1 : 0;
         } elsif ($opt eq 'rootfs' || $opt =~ m/^mp(\d+)$/) {
 	    die "implement me: $opt";
 	} else {
-- 
2.1.4





More information about the pve-devel mailing list