Properly handle the case that VM doesn't exist for the VB driver.
This commit is contained in:
parent
0cc63c05e2
commit
85a499ffb8
|
@ -1,11 +1,24 @@
|
||||||
|
require "log4r"
|
||||||
|
|
||||||
module VagrantPlugins
|
module VagrantPlugins
|
||||||
module ProviderVirtualBox
|
module ProviderVirtualBox
|
||||||
class Provider < Vagrant.plugin("1", :provider)
|
class Provider < Vagrant.plugin("1", :provider)
|
||||||
attr_reader :driver
|
attr_reader :driver
|
||||||
|
|
||||||
def initialize(machine)
|
def initialize(machine)
|
||||||
|
@logger = Log4r::Logger.new("vagrant::provider::virtualbox")
|
||||||
@machine = machine
|
@machine = machine
|
||||||
|
|
||||||
|
begin
|
||||||
|
@logger.debug("Instantiating the driver for machine ID: #{@machine.id.inspect}")
|
||||||
@driver = Driver::Meta.new(@machine.id)
|
@driver = Driver::Meta.new(@machine.id)
|
||||||
|
rescue Driver::Meta::VMNotFound
|
||||||
|
# The virtual machine doesn't exist, so we probably have a stale
|
||||||
|
# ID. Just clear the id out of the machine and reload it.
|
||||||
|
@logger.debug("VM not found! Clearing saved machine ID and reloading.")
|
||||||
|
@machine.id = nil
|
||||||
|
retry
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# @see Vagrant::Plugin::V1::Provider#action
|
# @see Vagrant::Plugin::V1::Provider#action
|
||||||
|
|
|
@ -283,6 +283,17 @@ describe Vagrant::Machine do
|
||||||
instance.id = "foo"
|
instance.id = "foo"
|
||||||
new_instance.id.should == "foo"
|
new_instance.id.should == "foo"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should delete the ID" do
|
||||||
|
instance.id = "foo"
|
||||||
|
|
||||||
|
second = new_instance
|
||||||
|
second.id.should == "foo"
|
||||||
|
second.id = nil
|
||||||
|
|
||||||
|
third = new_instance
|
||||||
|
third.id.should be_nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "ssh info" do
|
describe "ssh info" do
|
||||||
|
|
Loading…
Reference in New Issue