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
|
module Driver
|
||||||
# This class contains the logic to drive VirtualBox.
|
# This class contains the logic to drive VirtualBox.
|
||||||
class 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 this so we can use `Subprocess` more easily.
|
||||||
include Vagrant::Util
|
include Vagrant::Util
|
||||||
|
|
||||||
|
# The UUID of the virtual machine we represent
|
||||||
|
attr_reader :uuid
|
||||||
|
|
||||||
# The version of virtualbox that is running.
|
# The version of virtualbox that is running.
|
||||||
attr_reader :version
|
attr_reader :version
|
||||||
|
|
||||||
|
@ -15,6 +22,13 @@ module Vagrant
|
||||||
@logger = Log4r::Logger.new("vagrant::driver::virtualbox")
|
@logger = Log4r::Logger.new("vagrant::driver::virtualbox")
|
||||||
@uuid = uuid
|
@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
|
# Read and assign the version of VirtualBox we know which
|
||||||
# specific driver to instantiate.
|
# specific driver to instantiate.
|
||||||
begin
|
begin
|
||||||
|
|
|
@ -114,7 +114,14 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def reload!
|
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
|
end
|
||||||
|
|
||||||
def package(options=nil)
|
def package(options=nil)
|
||||||
|
|
Loading…
Reference in New Issue