diff --git a/CHANGELOG.md b/CHANGELOG.md index 0413a14a9..92118f11b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ - Add an `fsid` option to Linux NFS exports. [GH-736] - Fix edge case where an exception could be raised in networking code. [GH-742] - Add missing translation for the "guru meditation" state. [GH-745] + - Check that VirtualBox exists before certain commands. [GH-746] ## 0.9.7 (February 9, 2012) diff --git a/lib/vagrant/action.rb b/lib/vagrant/action.rb index 2d920fc9a..86ff9ce25 100644 --- a/lib/vagrant/action.rb +++ b/lib/vagrant/action.rb @@ -20,6 +20,7 @@ module Vagrant end module General + autoload :CheckVirtualbox, 'vagrant/action/general/check_virtualbox' autoload :Package, 'vagrant/action/general/package' autoload :Validate, 'vagrant/action/general/validate' end diff --git a/lib/vagrant/action/builtin.rb b/lib/vagrant/action/builtin.rb index eb10ab42e..5f7a26614 100644 --- a/lib/vagrant/action/builtin.rb +++ b/lib/vagrant/action/builtin.rb @@ -20,6 +20,7 @@ module Vagrant # provision - Provisions a running VM register(:provision) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use VM::Provision @@ -30,6 +31,7 @@ module Vagrant # environment. register(:start) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use VM::CleanMachineFolder @@ -53,6 +55,7 @@ module Vagrant # a restart if fails. register(:halt) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use VM::DiscardState @@ -63,6 +66,7 @@ module Vagrant # suspend - Suspends the VM register(:suspend) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use VM::Suspend @@ -72,6 +76,7 @@ module Vagrant # resume - Resume a VM register(:resume) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use VM::CheckPortCollisions @@ -82,6 +87,7 @@ module Vagrant # reload - Halts then restarts the VM register(:reload) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use registry.get(:halt) @@ -92,6 +98,7 @@ module Vagrant # up - Imports, prepares, then starts a fresh VM. register(:up) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use VM::CheckBox @@ -106,6 +113,7 @@ module Vagrant # destroy - Halts, cleans up, and destroys an existing VM register(:destroy) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::CheckAccessible use registry.get(:halt), :force => true @@ -120,6 +128,7 @@ module Vagrant # package - Export and package the VM register(:package) do Builder.new do + use General::CheckVirtualbox use General::Validate use VM::SetupPackageFiles use VM::CheckAccessible @@ -135,6 +144,7 @@ module Vagrant # box_add - Download and add a box. register(:box_add) do Builder.new do + use General::CheckVirtualbox use Box::Download use Box::Unpackage use Box::Verify diff --git a/lib/vagrant/action/general/check_virtualbox.rb b/lib/vagrant/action/general/check_virtualbox.rb new file mode 100644 index 000000000..fe4c55378 --- /dev/null +++ b/lib/vagrant/action/general/check_virtualbox.rb @@ -0,0 +1,17 @@ +module Vagrant + module Action + module General + # Checks that virtualbox is installed and ready to be used. + class CheckVirtualbox + def initialize(app, env) + @app = app + end + + def call(env) + env[:vm].driver.verify! + @app.call(env) + end + end + end + end +end diff --git a/lib/vagrant/action/general/validate.rb b/lib/vagrant/action/general/validate.rb index ab2b53aea..5045918dd 100644 --- a/lib/vagrant/action/general/validate.rb +++ b/lib/vagrant/action/general/validate.rb @@ -6,12 +6,11 @@ module Vagrant class Validate def initialize(app, env) @app = app - @env = env end def call(env) - @env[:vm].config.validate!(@env[:vm].env) if !@env.has_key?("validate") || @env["validate"] - @app.call(@env) + env[:vm].config.validate!(env[:vm].env) if !env.has_key?("validate") || env["validate"] + @app.call(env) end end end diff --git a/lib/vagrant/driver/virtualbox.rb b/lib/vagrant/driver/virtualbox.rb index e689de0ee..ae7ec9f94 100644 --- a/lib/vagrant/driver/virtualbox.rb +++ b/lib/vagrant/driver/virtualbox.rb @@ -99,6 +99,7 @@ module Vagrant :ssh_port, :start, :suspend, + :verify!, :verify_image, :vm_exists? diff --git a/lib/vagrant/driver/virtualbox_4_0.rb b/lib/vagrant/driver/virtualbox_4_0.rb index 27377e86e..b4e6b7eb1 100644 --- a/lib/vagrant/driver/virtualbox_4_0.rb +++ b/lib/vagrant/driver/virtualbox_4_0.rb @@ -440,6 +440,12 @@ module Vagrant execute("controlvm", @uuid, "savestate") end + def verify! + # This command sometimes fails if kernel drivers aren't properly loaded + # so we just run the command and verify that it succeeded. + execute("list", "hostonlyifs") + end + def verify_image(path) r = raw("import", path.to_s, "--dry-run") return r.exit_code == 0 diff --git a/lib/vagrant/driver/virtualbox_4_1.rb b/lib/vagrant/driver/virtualbox_4_1.rb index 9a43119cb..45e2d5aeb 100644 --- a/lib/vagrant/driver/virtualbox_4_1.rb +++ b/lib/vagrant/driver/virtualbox_4_1.rb @@ -440,6 +440,12 @@ module Vagrant execute("controlvm", @uuid, "savestate") end + def verify! + # This command sometimes fails if kernel drivers aren't properly loaded + # so we just run the command and verify that it succeeded. + execute("list", "hostonlyifs") + end + def verify_image(path) r = raw("import", path.to_s, "--dry-run") return r.exit_code == 0 diff --git a/lib/vagrant/driver/virtualbox_base.rb b/lib/vagrant/driver/virtualbox_base.rb index 96feb91c8..7edddbb45 100644 --- a/lib/vagrant/driver/virtualbox_base.rb +++ b/lib/vagrant/driver/virtualbox_base.rb @@ -234,6 +234,12 @@ module Vagrant def suspend end + # Verifies that the driver is ready to accept work. + # + # This should raise a VagrantError if things are not ready. + def verify! + end + # Verifies that an image can be imported properly. # # @param [String] path Path to an OVF file.