diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb index fcabe2f..fa46623 100644 --- a/lib/vagrant-lxc/action/create.rb +++ b/lib/vagrant-lxc/action/create.rb @@ -19,7 +19,8 @@ module Vagrant container_name = generate_container_name(env) end - env[:machine].provider.driver.create( + driver = env[:machine].provider.driver + driver.create( container_name, config.backingstore, config.backingstore_options, @@ -27,6 +28,7 @@ module Vagrant env[:lxc_template_config], env[:lxc_template_opts] ) + driver.update_config_keys env[:machine].id = container_name diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index 5ab98d6..5cf13d1 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -45,6 +45,10 @@ module Vagrant Pathname.new("#{containers_path}/#{@container_name}") end + def config_path + base_path.join('config').to_s + end + def rootfs_path config_entry = config_string.match(/^lxc\.rootfs\s+=\s+(.+)$/)[1] case config_entry @@ -72,7 +76,7 @@ module Vagrant end def config_string - @sudo_wrapper.run('cat', base_path.join('config').to_s) + @sudo_wrapper.run('cat', config_path) end def create(name, backingstore, backingstore_options, template_path, config_file, template_options = {}) @@ -240,6 +244,12 @@ module Vagrant write_config(contents) end + def update_config_keys + @cli.update_config(config_path) + rescue Errors::ExecuteError + # not on LXC 2.1+. Doesn't matter, ignore. + end + protected def write_customizations(customizations) @@ -260,8 +270,8 @@ module Vagrant file.chmod 0644 file.write contents file.close - @sudo_wrapper.run 'cp', '-f', file.path, base_path.join('config').to_s - @sudo_wrapper.run 'chown', 'root:root', base_path.join('config').to_s + @sudo_wrapper.run 'cp', '-f', file.path, config_path + @sudo_wrapper.run 'chown', 'root:root', config_path end end end diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index 98c414c..0f29caa 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -42,6 +42,10 @@ module Vagrant run(:config, param).gsub("\n", '') end + def update_config(path) + run('update-config', '-c', path) + end + def state if @name && run(:info, '--name', @name, retryable: true) =~ /^state:[^A-Z]+([A-Z]+)$/i $1.downcase.to_sym diff --git a/templates/sudoers.rb.erb b/templates/sudoers.rb.erb index a38fabc..e3e731a 100644 --- a/templates/sudoers.rb.erb +++ b/templates/sudoers.rb.erb @@ -119,6 +119,7 @@ Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-shutdown', '--name', /.*/ Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-attach', '--name', /.*/, '**' Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-attach', '-h' Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-config', 'lxc.lxcpath' +Whitelist.add '<%= cmd_paths['lxc_bin'] %>/lxc-update-config', '-c', /.*/ ## # Commands from driver/action/remove_temporary_files.rb