diff --git a/lib/vagrant-lxc/container.rb b/lib/vagrant-lxc/container.rb index cec7cdd..40ae6d0 100644 --- a/lib/vagrant-lxc/container.rb +++ b/lib/vagrant-lxc/container.rb @@ -12,8 +12,6 @@ module Vagrant # Include this so we can use `Subprocess` more easily. include Vagrant::Util::Retryable - CONTAINER_STATE_FILE_PATH = '/tmp/vagrant-lxc-container-state-%s' - def initialize(machine) @machine = machine @logger = Log4r::Logger.new("vagrant::provider::lxc::container") @@ -54,18 +52,14 @@ module Vagrant File.open(state_file_path, 'w') { |f| f.print state } end - def read_state_from_file - if File.exists?(state_file_path) - File.read(state_file_path).to_sym + def state + if lxc(:info, '--name', @machine.id) =~ /^state:[^A-Z]+([A-Z]+)$/ + $1.downcase.to_sym elsif @machine.id :unknown end end - def state_file_path - CONTAINER_STATE_FILE_PATH % {id: @machine.id} - end - # TODO: Review code below this line, it was pretty much a copy and paste from VirtualBox base driver def execute(*command, &block) # Get the options hash if it exists diff --git a/spec/unit/container_spec.rb b/spec/unit/container_spec.rb index 0308d5e..7503119 100644 --- a/spec/unit/container_spec.rb +++ b/spec/unit/container_spec.rb @@ -89,4 +89,25 @@ describe Vagrant::LXC::Container do subject.should have_received(:wait_until).with(:running) end end + + describe 'state' do + let(:machine_id) { 'random-machine-id' } + let(:machine) { fire_double('Vagrant::Machine', id: machine_id) } + + before do + subject.stub(lxc: "state: STOPPED\npid: 2") + end + + it 'calls lxc-info with the right arguments' do + subject.state + subject.should have_received(:lxc).with( + :info, + '--name', machine_id + ) + end + + it 'maps the output of lxc-info status out to a symbol' do + subject.state.should == :stopped + end + end end