core: MachineIndex#valid? checks state and ID again

This commit is contained in:
Mitchell Hashimoto 2014-05-05 21:29:40 -07:00
parent bc4d91fb73
commit d526dd54fe
2 changed files with 18 additions and 8 deletions

View File

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

View File

@ -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}")