diff --git a/lib/vagrant-lxc/action/create.rb b/lib/vagrant-lxc/action/create.rb index 0bce830..4a5f089 100644 --- a/lib/vagrant-lxc/action/create.rb +++ b/lib/vagrant-lxc/action/create.rb @@ -14,6 +14,7 @@ module Vagrant env[:machine].provider.driver.create( container_name, env[:lxc_template_src], + env[:lxc_template_config], env[:lxc_template_opts] ) diff --git a/lib/vagrant-lxc/action/handle_box_metadata.rb b/lib/vagrant-lxc/action/handle_box_metadata.rb index 1471369..e169d8e 100644 --- a/lib/vagrant-lxc/action/handle_box_metadata.rb +++ b/lib/vagrant-lxc/action/handle_box_metadata.rb @@ -22,6 +22,10 @@ module Vagrant @env[:lxc_template_opts] = template_opts @env[:lxc_template_src] = template_src + if template_config_file.exist? + @env[:lxc_template_config] = template_config_file.to_s + end + @app.call env end @@ -29,6 +33,10 @@ module Vagrant @template_src ||= @box.directory.join('lxc-template').to_s end + def template_config_file + @template_config_file ||= @box.directory.join('lxc.conf') + end + def template_opts @template_opts ||= @box.metadata.fetch('template-opts', {}).dup.merge!( '--tarball' => rootfs_tarball, diff --git a/lib/vagrant-lxc/driver.rb b/lib/vagrant-lxc/driver.rb index fed94d5..c9f5388 100644 --- a/lib/vagrant-lxc/driver.rb +++ b/lib/vagrant-lxc/driver.rb @@ -33,12 +33,12 @@ module Vagrant Pathname.new(base_path.join('rootfs')) end - def create(name, template_path, template_options = {}) + def create(name, template_path, config_file, template_options = {}) @cli.name = @container_name = name import_template(template_path) do |template_name| @logger.debug "Creating container..." - @cli.create template_name, template_options + @cli.create template_name, config_file, template_options end end diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index 0898595..133a828 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -46,13 +46,18 @@ module Vagrant 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.unshift '--' unless extra.empty? run :create, '--template', template, '--name', @name, + *(config_opts), *extra end