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

2019-07-10 Thread Thomas Lamprecht
On 7/9/19 5:20 PM, Stefan Reiter wrote:
> 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 
> Signed-off-by: Stefan Reiter 
> ---
> 
> Nevermind v1, perl arrays and hashes are confusing. This time it works with
> multiple custom options as well ;)

Oh, and FYI: your repo tag is wrong here.
And perl hashes and arrays itself aren't to bad, but yes, the mix of
both needs some syntactic bending, though.. ;-)

___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


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

2019-07-09 Thread Stefan Reiter
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 
Signed-off-by: Stefan Reiter 
---

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


___
pve-devel mailing list
pve-devel@pve.proxmox.com
https://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel