Handle the case properly where the VM in `.vagrant` doesn't exist anymore
This commit is contained in:
parent
3eede78876
commit
36632c4bb7
|
@ -5,9 +5,16 @@ module Vagrant
|
|||
module Driver
|
||||
# This class contains the logic to drive VirtualBox.
|
||||
class VirtualBox
|
||||
# This is raised if the VM is not found when initializing a driver
|
||||
# with a UUID.
|
||||
class VMNotFound < StandardError; end
|
||||
|
||||
# Include this so we can use `Subprocess` more easily.
|
||||
include Vagrant::Util
|
||||
|
||||
# The UUID of the virtual machine we represent
|
||||
attr_reader :uuid
|
||||
|
||||
# The version of virtualbox that is running.
|
||||
attr_reader :version
|
||||
|
||||
|
@ -15,6 +22,13 @@ module Vagrant
|
|||
@logger = Log4r::Logger.new("vagrant::driver::virtualbox")
|
||||
@uuid = uuid
|
||||
|
||||
if @uuid
|
||||
# Verify the VM exists, and if it doesn't, then don't worry
|
||||
# about it (mark the UUID as nil)
|
||||
r = raw("showvminfo", @uuid)
|
||||
raise VMNotFound if r.exit_code != 0
|
||||
end
|
||||
|
||||
# Read and assign the version of VirtualBox we know which
|
||||
# specific driver to instantiate.
|
||||
begin
|
||||
|
|
|
@ -114,7 +114,14 @@ module Vagrant
|
|||
end
|
||||
|
||||
def reload!
|
||||
@driver = Driver::VirtualBox.new(@uuid)
|
||||
begin
|
||||
@driver = Driver::VirtualBox.new(@uuid)
|
||||
rescue Driver::VirtualBox::VMNotFound
|
||||
# Clear the UUID since this VM doesn't exist. Note that this calls
|
||||
# back into `reload!` but shouldn't ever result in infinite
|
||||
# recursion since `@uuid` will be nil.
|
||||
self.uuid = nil
|
||||
end
|
||||
end
|
||||
|
||||
def package(options=nil)
|
||||
|
|
Loading…
Reference in New Issue