Support bundling lxc config files with base boxes

This commit is contained in:
Fabio Rehm 2013-06-06 00:04:59 -03:00
parent 75a2d0c65d
commit 5c2973108b
4 changed files with 17 additions and 3 deletions

View file

@ -14,6 +14,7 @@ module Vagrant
env[:machine].provider.driver.create( env[:machine].provider.driver.create(
container_name, container_name,
env[:lxc_template_src], env[:lxc_template_src],
env[:lxc_template_config],
env[:lxc_template_opts] env[:lxc_template_opts]
) )

View file

@ -22,6 +22,10 @@ module Vagrant
@env[:lxc_template_opts] = template_opts @env[:lxc_template_opts] = template_opts
@env[:lxc_template_src] = template_src @env[:lxc_template_src] = template_src
if template_config_file.exist?
@env[:lxc_template_config] = template_config_file.to_s
end
@app.call env @app.call env
end end
@ -29,6 +33,10 @@ module Vagrant
@template_src ||= @box.directory.join('lxc-template').to_s @template_src ||= @box.directory.join('lxc-template').to_s
end end
def template_config_file
@template_config_file ||= @box.directory.join('lxc.conf')
end
def template_opts def template_opts
@template_opts ||= @box.metadata.fetch('template-opts', {}).dup.merge!( @template_opts ||= @box.metadata.fetch('template-opts', {}).dup.merge!(
'--tarball' => rootfs_tarball, '--tarball' => rootfs_tarball,

View file

@ -33,12 +33,12 @@ module Vagrant
Pathname.new(base_path.join('rootfs')) Pathname.new(base_path.join('rootfs'))
end end
def create(name, template_path, template_options = {}) def create(name, template_path, config_file, template_options = {})
@cli.name = @container_name = name @cli.name = @container_name = name
import_template(template_path) do |template_name| import_template(template_path) do |template_name|
@logger.debug "Creating container..." @logger.debug "Creating container..."
@cli.create template_name, template_options @cli.create template_name, config_file, template_options
end end
end end

View file

@ -46,13 +46,18 @@ module Vagrant
end end
end end
def create(template, template_opts = {}) def create(template, config_file, template_opts = {})
if config_file
config_opts = ['-f', config_file]
end
extra = template_opts.to_a.flatten extra = template_opts.to_a.flatten
extra.unshift '--' unless extra.empty? extra.unshift '--' unless extra.empty?
run :create, run :create,
'--template', template, '--template', template,
'--name', @name, '--name', @name,
*(config_opts),
*extra *extra
end end