Add support for reading installed lxc version from cli object

This commit is contained in:
Fabio Rehm 2013-04-08 22:27:29 -03:00
parent fd0c863f34
commit dd5c1b1c6b
2 changed files with 21 additions and 1 deletions

View file

@ -23,6 +23,15 @@ module Vagrant
run(:ls).split(/\s+/).uniq run(:ls).split(/\s+/).uniq
end end
def version
if run(:version) =~ /lxc version:\s+(.+)\s*$/
$1.downcase
else
# TODO: Raise an user friendly error
raise 'Unable to parse lxc version!'
end
end
def state def state
if @name && run(:info, '--name', @name) =~ /^state:[^A-Z]+([A-Z]+)$/ if @name && run(:info, '--name', @name) =~ /^state:[^A-Z]+([A-Z]+)$/
$1.downcase.to_sym $1.downcase.to_sym

View file

@ -5,7 +5,6 @@ require 'vagrant-lxc/driver/cli'
describe Vagrant::LXC::Driver::CLI do describe Vagrant::LXC::Driver::CLI do
describe 'list' do describe 'list' do
let(:lxc_ls_out) { "dup-container\na-container dup-container" } let(:lxc_ls_out) { "dup-container\na-container dup-container" }
let(:exec_args) { @exec_args }
let(:result) { @result } let(:result) { @result }
before do before do
@ -24,6 +23,18 @@ describe Vagrant::LXC::Driver::CLI do
end end
end end
describe 'version' do
let(:lxc_version_out) { "lxc version: 0.x.y-rc1\n" }
before do
subject.stub(:run).with(:version).and_return(lxc_version_out)
end
it 'parses the version from the output' do
subject.version.should == '0.x.y-rc1'
end
end
describe 'create' do describe 'create' do
let(:template) { 'quantal-64' } let(:template) { 'quantal-64' }
let(:name) { 'quantal-container' } let(:name) { 'quantal-container' }