Skip to content
This repository has been archived by the owner on Nov 24, 2022. It is now read-only.

Commit

Permalink
create: with LXC 2.1+ run lxc-update-config on new boxes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Virgil Dupras committed Jan 14, 2018
1 parent 2b08ae1 commit c74ddbf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/vagrant-lxc/action/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ def call(env)
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,
env[:lxc_template_src],
env[:lxc_template_config],
env[:lxc_template_opts]
)
driver.update_config_keys

env[:machine].id = container_name

Expand Down
16 changes: 13 additions & 3 deletions lib/vagrant-lxc/driver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ def base_path
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
Expand Down Expand Up @@ -72,7 +76,7 @@ def mac_address
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 = {})
Expand Down Expand Up @@ -240,6 +244,12 @@ def prune_customizations
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)
Expand All @@ -260,8 +270,8 @@ def write_config(contents)
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
Expand Down
4 changes: 4 additions & 0 deletions lib/vagrant-lxc/driver/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ def config(param)
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
Expand Down
1 change: 1 addition & 0 deletions templates/sudoers.rb.erb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c74ddbf

Please sign in to comment.