From 8cfe577b171ceef59c500c353a6d0b18d1be6ced Mon Sep 17 00:00:00 2001 From: Virgil Dupras Date: Mon, 30 Apr 2018 20:45:25 -0400 Subject: [PATCH] Fix LXC 3.0 compatibility with old boxes Creating a new vagrant machine with a box created with an old LXC config format would fail with LXC 3.0. We now update the LXC config of the box itself before calling `lxc-create`. --- lib/vagrant-lxc/action/create.rb | 6 +++++- lib/vagrant-lxc/action/handle_box_metadata.rb | 2 ++ lib/vagrant-lxc/driver.rb | 5 +++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb index 25a7513..569cf28 100644 --- a/lib/vagrant-lxc/action/create.rb +++ b/lib/vagrant-lxc/action/create.rb @@ -25,7 +25,11 @@ module Vagrant end driver = env[:machine].provider.driver template_options = env[:lxc_template_opts] - if ! driver.supports_new_config_format + if driver.supports_new_config_format + if env[:lxc_box_config] + driver.update_config_keys(env[:lxc_box_config]) + end + else template_options['--oldconfig'] = '' end driver.create( diff --git a/lib/vagrant-lxc/action/handle_box_metadata.rb b/lib/vagrant-lxc/action/handle_box_metadata.rb index 6d78800..10581b7 100644 --- a/lib/vagrant-lxc/action/handle_box_metadata.rb +++ b/lib/vagrant-lxc/action/handle_box_metadata.rb @@ -33,8 +33,10 @@ module Vagrant end if template_config_file.exist? + @env[:lxc_box_config] = template_config_file.to_s @env[:lxc_template_opts].merge!('--config' => template_config_file.to_s) elsif old_template_config_file.exist? + @env[:lxc_box_config] = old_template_config_file.to_s @env[:lxc_template_config] = old_template_config_file.to_s end diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 58a6474..1c1a024 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -249,8 +249,9 @@ module Vagrant write_config(contents) end - def update_config_keys - @cli.update_config(config_path) + def update_config_keys(path = nil) + path = path || config_path + @cli.update_config(path) rescue Errors::ExecuteError # not on LXC 2.1+. Doesn't matter, ignore. end