From d526dd54fe564858ad19970199ad561eb450df1d Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 5 May 2014 21:29:40 -0700 Subject: [PATCH] core: MachineIndex#valid? checks state and ID again --- lib/vagrant/machine_index.rb | 18 +++++++++++++----- plugins/providers/virtualbox/provider.rb | 8 +++++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/vagrant/machine_index.rb b/lib/vagrant/machine_index.rb index da276188a..c1ce238d3 100644 --- a/lib/vagrant/machine_index.rb +++ b/lib/vagrant/machine_index.rb @@ -435,11 +435,19 @@ module Vagrant # found, it is already false. return false if !found - # If the environment doesn't contain the machine with this - # name, then it is also false. At some point, we can remove - # this limitation if we support destroying machines where - # the Vagrantfile is moved. - return false if !env.machine_names.find { |n| n == self.name.to_sym } + # Get the machine + machine = nil + begin + machine = env.machine(self.name.to_sym, self.provider.to_sym) + rescue Errors::MachineNotFound + return false + end + + # Refresh the machine state + machine.state + + # If the machine doesn't have an ID, it is invalid + return false if !machine.id true end diff --git a/plugins/providers/virtualbox/provider.rb b/plugins/providers/virtualbox/provider.rb index 70adf34ef..28d220223 100644 --- a/plugins/providers/virtualbox/provider.rb +++ b/plugins/providers/virtualbox/provider.rb @@ -73,15 +73,17 @@ module VagrantPlugins # # @return [Symbol] def state - # XXX: What happens if we destroy the VM but the UUID is still - # set here? - # Determine the ID of the state here. state_id = nil state_id = :not_created if !@driver.uuid state_id = @driver.read_state if !state_id state_id = :unknown if !state_id + # If we're not created, then reset the ID to nil + if state_id == :not_created + @machine.id = nil + end + # Translate into short/long descriptions short = state_id.to_s.gsub("_", " ") long = I18n.t("vagrant.commands.status.#{state_id}")