Add support for setting custom lxc-start arguments from Vagrantfile

Useful for #10
This commit is contained in:
Fabio Rehm 2013-03-03 04:37:07 -03:00
parent 169f92bf55
commit 71c1a401cc
5 changed files with 22 additions and 7 deletions

3
example/Vagrantfile vendored
View file

@ -8,6 +8,7 @@ Vagrant.configure("2") do |config|
config.vm.hostname = 'ubuntu-cloud-box' config.vm.hostname = 'ubuntu-cloud-box'
config.vm.provider :lxc do |lxc| config.vm.provider :lxc do |lxc|
# ... soon to come lxc configs... lxc.start_opts << 'lxc.cgroup.memory.limit_in_bytes=400M'
lxc.start_opts << 'lxc.cgroup.memory.memsw.limit_in_bytes=500M'
end end
end end

View file

@ -3,7 +3,8 @@ module Vagrant
module Action module Action
class Boot < BaseAction class Boot < BaseAction
def call(env) def call(env)
env[:machine].provider.container.start config = env[:machine].provider_config
env[:machine].provider.container.start(config)
@app.call env @app.call env
end end
end end

View file

@ -1,6 +1,14 @@
module Vagrant module Vagrant
module LXC module LXC
class Config < Vagrant.plugin("2", :config) class Config < Vagrant.plugin("2", :config)
# An array of options to be passed to lxc-start when booting the machine.
#
# @return [Array]
attr_reader :start_opts
def initialize
@start_opts = []
end
end end
end end
end end

View file

@ -66,8 +66,10 @@ module Vagrant
end end
end end
def start def start(config)
lxc :start, '-d', '--name', @name # @logger.info('Starting container...')
opts = config.start_opts.map { |opt| ["-s", opt] }.flatten
lxc :start, '-d', '--name', @name, *opts
wait_until :running wait_until :running
end end

View file

@ -139,18 +139,21 @@ describe Vagrant::LXC::Container do
end end
describe 'start' do describe 'start' do
let(:config) { mock(:config, start_opts: ['a=1', 'b=2']) }
let(:name) { 'container-name' } let(:name) { 'container-name' }
before do before do
subject.stub(lxc: true, wait_until: true) subject.stub(lxc: true, wait_until: true)
subject.start subject.start(config)
end end
it 'calls lxc-start with the right arguments' do it 'calls lxc-start with the right arguments' do
subject.should have_received(:lxc).with( subject.should have_received(:lxc).with(
:start, :start,
'-d', '-d',
'--name', name '--name', name,
'-s', 'a=1',
'-s', 'b=2'
) )
end end