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.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

View file

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

View file

@ -1,6 +1,14 @@
module Vagrant
module LXC
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

View file

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

View file

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