create: with LXC 2.1+ run lxc-update-config on new boxes
When running with LXC 2.1+, ensure that our boxes have up-to-date config keys by running the `lxc-update-config` utility that ships with LXC 2.1+. When the command doesn't exist (LXC <2.1), we do nothing. ref #445
This commit is contained in:
parent
2b08ae199f
commit
c74ddbf2fc
4 changed files with 21 additions and 4 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue