diff --git a/lib/vagrant-lxc/action/handle_box_metadata.rb b/lib/vagrant-lxc/action/handle_box_metadata.rb index 239a58e..c61cbc2 100644 --- a/lib/vagrant-lxc/action/handle_box_metadata.rb +++ b/lib/vagrant-lxc/action/handle_box_metadata.rb @@ -13,26 +13,21 @@ module Vagrant def call(env) box = env[:machine].box metadata = box.metadata - template_name = metadata['template-name'] - - after_create = metadata['after-create-script'] ? - box.directory.join(metadata['after-create-script']).to_s : - nil metadata.merge!( - 'template-name' => "vagrant-#{box.name}-#{template_name}", - 'lxc-cache-path' => box.directory.to_s, - 'after-create-script' => after_create + 'template-name' => "vagrant-#{box.name}", + 'lxc-cache-path' => box.directory.to_s ) # Prepends "lxc-" to the template file so that `lxc-create` is able to find it + src = box.directory.join('lxc-template').to_s dest = LXC_TEMPLATES_PATH.join("lxc-#{metadata['template-name']}").to_s - src = box.directory.join(template_name).to_s @logger.debug('Copying LXC template into place') # This should only ask for administrative permission once, even # though its executed in multiple subshells. system(%Q[sudo su root -c "cp #{src} #{dest}"]) + system(%Q[sudo su root -c "cd #{box.directory} && tar xfz rootfs.tar.gz"]) @app.call(env) end diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index 18f2ceb..f1666c4 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -37,6 +37,10 @@ module Vagrant @name = SecureRandom.hex(6) public_key = Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s + meta_opts = metadata.fetch('template-opts', {}).map do |opt, value| + [opt, value] + end.flatten + # TODO: Handle errors lxc :create, # lxc-create options @@ -44,9 +48,9 @@ module Vagrant '--name', @name, '--', # Template options - '-S', public_key, - '--cache-path', metadata['lxc-cache-path'], - '-T', metadata['tar-cache'] + '--auth-key', public_key, + '--cache', metadata['lxc-cache-path'], + *meta_opts @name end diff --git a/spec/unit/action/handle_box_metadata_spec.rb b/spec/unit/action/handle_box_metadata_spec.rb index f7fe0eb..9fabbcc 100644 --- a/spec/unit/action/handle_box_metadata_spec.rb +++ b/spec/unit/action/handle_box_metadata_spec.rb @@ -4,11 +4,8 @@ require 'vagrant-lxc/action/base_action' require 'vagrant-lxc/action/handle_box_metadata' describe Vagrant::LXC::Action::HandleBoxMetadata do - let(:tar_cache) { 'template.zip' } - let(:template_name) { 'ubuntu-lts' } - let(:after_create) { 'setup-vagrant-user.sh' } - let(:metadata) { {'template-name' => template_name, 'tar-cache' => tar_cache, 'after-create-script' => after_create} } - let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: Pathname.new('/path/to/box')) } + let(:metadata) { {'template-opts' => {'--foo' => 'bar'}} } + let(:box) { mock(:box, name: 'box-name', metadata: metadata, directory: Pathname.new('/path/to/box')) } let(:machine) { mock(:machine, box: box) } let(:app) { mock(:app, call: true) } let(:env) { {machine: machine} } @@ -24,17 +21,15 @@ describe Vagrant::LXC::Action::HandleBoxMetadata do metadata['lxc-cache-path'].should == box.directory.to_s end - it 'prepends box directory to after-create-script' do - metadata['after-create-script'].should == "#{box.directory.to_s}/#{after_create}" - end - it 'prepends vagrant and box name to template-name' do - metadata['template-name'].should == "vagrant-#{box.name}-#{template_name}" + metadata['template-name'].should == "vagrant-#{box.name}" end it 'copies box template file to the right folder' do - src = box.directory.join(template_name).to_s + src = box.directory.join('lxc-template').to_s dest = "/usr/share/lxc/templates/lxc-#{metadata['template-name']}" subject.should have_received(:system).with("sudo su root -c \"cp #{src} #{dest}\"") end + + pending 'extracts rootfs' end diff --git a/spec/unit/container_spec.rb b/spec/unit/container_spec.rb index 81aa2d0..4d61e4b 100644 --- a/spec/unit/container_spec.rb +++ b/spec/unit/container_spec.rb @@ -78,14 +78,13 @@ describe Vagrant::LXC::Container do describe 'creation' do let(:name) { 'random-container-name' } let(:template_name) { 'template-name' } - let(:tar_cache_path) { '/path/to/tar/cache' } let(:lxc_cache) { '/path/to/cache' } let(:public_key_path) { Vagrant.source_root.join('keys', 'vagrant.pub').expand_path.to_s } before do subject.stub(lxc: true) SecureRandom.stub(hex: name) - subject.create 'template-name' => template_name, 'tar-cache' => tar_cache_path, 'lxc-cache-path' => lxc_cache + subject.create 'template-name' => template_name, 'lxc-cache-path' => lxc_cache, 'template-opts' => { '--foo' => 'bar'} end it 'calls lxc-create with the right arguments' do @@ -94,9 +93,9 @@ describe Vagrant::LXC::Container do '--template', template_name, '--name', name, '--', - '-S', public_key_path, - '--cache-path', lxc_cache, - '-T', tar_cache_path + '--auth-key', public_key_path, + '--cache', lxc_cache, + '--foo', 'bar' ) end end