diff --git a/lib/vagrant-lxc/driver/cli.rb b/lib/vagrant-lxc/driver/cli.rb index e26531c..9bbcf4a 100644 --- a/lib/vagrant-lxc/driver/cli.rb +++ b/lib/vagrant-lxc/driver/cli.rb @@ -23,6 +23,15 @@ module Vagrant run(:ls).split(/\s+/).uniq 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 if @name && run(:info, '--name', @name) =~ /^state:[^A-Z]+([A-Z]+)$/ $1.downcase.to_sym diff --git a/spec/unit/driver/cli_spec.rb b/spec/unit/driver/cli_spec.rb index 41ff7ea..3d91de7 100644 --- a/spec/unit/driver/cli_spec.rb +++ b/spec/unit/driver/cli_spec.rb @@ -5,7 +5,6 @@ require 'vagrant-lxc/driver/cli' describe Vagrant::LXC::Driver::CLI do describe 'list' do let(:lxc_ls_out) { "dup-container\na-container dup-container" } - let(:exec_args) { @exec_args } let(:result) { @result } before do @@ -24,6 +23,18 @@ describe Vagrant::LXC::Driver::CLI do 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 let(:template) { 'quantal-64' } let(:name) { 'quantal-container' }