if (!($same_container_exists && $restore && $force)) {
PVE::Cluster::check_vmid_unused($vmid);
+ } else {
+ my $conf = PVE::LXC::load_config($vmid);
+ PVE::LXC::check_protection($conf, "unable to restore CT $vmid");
}
my $password = extract_param($param, 'password');
my $storage_cfg = cfs_read_file("storage.cfg");
- die "can't remove CT $vmid - protection mode enabled\n"
- if $conf->{protection};
+ PVE::LXC::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);
protection => {
optional => 1,
type => 'boolean',
- description => "Sets the protection flag of the container. This will prevent the remove operation.",
+ description => "Sets the protection flag of the container. This will prevent the remove operation. This will prevent the CT or CT's disk remove/update operation.",
default => 0,
},
};
die "VM is locked ($conf->{'lock'})\n" if $conf->{'lock'};
}
+sub check_protection {
+ my ($vm_conf, $err_msg) = @_;
+
+ if ($vm_conf->{protection}) {
+ die "$err_msg - protection mode enabled\n";
+ }
+}
+
sub update_lxc_config {
my ($storage_cfg, $vmid, $conf) = @_;
} elsif ($opt eq 'protection') {
delete $conf->{$opt};
} elsif ($opt =~ m/^mp(\d+)$/) {
+ check_protection($conf, "can't remove CT $vmid drive '$opt'");
delete $conf->{$opt};
push @nohotplug, $opt;
next if $running;
- } elsif ($opt eq 'rootfs') {
- die "implement me"
} else {
die "implement me"
}
} elsif ($opt eq 'protection') {
$conf->{$opt} = $value ? 1 : 0;
} elsif ($opt =~ m/^mp(\d+)$/) {
+ check_protection($conf, "can't update CT $vmid drive '$opt'");
$conf->{$opt} = $value;
$new_disks = 1;
push @nohotplug, $opt;
next;
} elsif ($opt eq 'rootfs') {
+ check_protection($conf, "can't update CT $vmid drive '$opt'");
die "implement me: $opt";
} else {
die "implement me: $opt";