[pve-devel] [PATCH v2 cluster] fix #2270: allow custom lxc options to be restored as root

Stefan Reiter s.reiter at proxmox.com
Tue Jul 9 17:20:57 CEST 2019


Seems to be a regression introduced with
f360d7f16b094fa258cf82d2557d06f3284435e4 (related to #2028).
$conf->{'lxc'} would always be defined, hence we never replaced it with
the restored options.

Co-developed-by: Oguz Bektas <o.bektas at proxmox.com>
Signed-off-by: Stefan Reiter <s.reiter at proxmox.com>
---

Nevermind v1, perl arrays and hashes are confusing. This time it works with
multiple custom options as well ;)

 src/PVE/LXC/Create.pm | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/PVE/LXC/Create.pm b/src/PVE/LXC/Create.pm
index 029c940..ee83052 100644
--- a/src/PVE/LXC/Create.pm
+++ b/src/PVE/LXC/Create.pm
@@ -175,16 +175,22 @@ sub restore_configuration {
 	    # we know if it was a template in the restore API call and check if the target
 	    # storage supports creating a template there
 	    next if $key =~ /^template$/;
-	    if ($restricted && $key eq 'lxc') {
-		warn "skipping custom lxc options, restore manually as root:\n";
-		warn "--------------------------------\n";
+
+	    if ($key eq 'lxc') {
 		my $lxc_list = $oldconf->{'lxc'};
-		foreach my $lxc_opt (@$lxc_list) {
-		    warn "$lxc_opt->[0]: $lxc_opt->[1]\n"
+		if ($restricted) {
+		    warn "skipping custom lxc options, restore manually as root:\n";
+		    warn "--------------------------------\n";
+		    foreach my $lxc_opt (@$lxc_list) {
+			warn "$lxc_opt->[0]: $lxc_opt->[1]\n"
+		    }
+		    warn "--------------------------------\n";
+		} else {
+		    @{$conf->{$key}} = (@$lxc_list, @{$conf->{$key}});
 		}
-		warn "--------------------------------\n";
 		next;
 	    }
+
 	    if ($unique && $key =~ /^net\d+$/) {
 		my $net = PVE::LXC::Config->parse_lxc_network($oldconf->{$key});
 		my $dc = PVE::Cluster::cfs_read_file('datacenter.cfg');
-- 
2.20.1





More information about the pve-devel mailing list