From d5c5c4f523679002e4cfb13b941e7e2581690701 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 21 Jan 2013 11:38:37 -0600 Subject: [PATCH] Convert all VirtualBox provider internals to use new state API --- plugins/providers/virtualbox/action/boot.rb | 2 +- plugins/providers/virtualbox/action/check_accessible.rb | 2 +- plugins/providers/virtualbox/action/check_created.rb | 2 +- plugins/providers/virtualbox/action/check_running.rb | 2 +- plugins/providers/virtualbox/action/created.rb | 2 +- plugins/providers/virtualbox/action/discard_state.rb | 2 +- plugins/providers/virtualbox/action/export.rb | 3 ++- plugins/providers/virtualbox/action/halt.rb | 4 ++-- plugins/providers/virtualbox/action/import.rb | 2 +- plugins/providers/virtualbox/action/is_running.rb | 2 +- plugins/providers/virtualbox/action/is_saved.rb | 2 +- plugins/providers/virtualbox/action/resume.rb | 2 +- plugins/providers/virtualbox/action/suspend.rb | 2 +- 13 files changed, 15 insertions(+), 14 deletions(-) diff --git a/plugins/providers/virtualbox/action/boot.rb b/plugins/providers/virtualbox/action/boot.rb index 26a06ed7d..3d1a5f229 100644 --- a/plugins/providers/virtualbox/action/boot.rb +++ b/plugins/providers/virtualbox/action/boot.rb @@ -34,7 +34,7 @@ module VagrantPlugins # If the VM is not starting or running, something went wrong # and we need to show a useful error. - state = @env[:machine].provider.state + state = @env[:machine].provider.state.id raise Errors::VMFailedToRun if state != :starting && state != :running sleep 2 if !@env["vagrant.test"] diff --git a/plugins/providers/virtualbox/action/check_accessible.rb b/plugins/providers/virtualbox/action/check_accessible.rb index f000825b1..e92bcf492 100644 --- a/plugins/providers/virtualbox/action/check_accessible.rb +++ b/plugins/providers/virtualbox/action/check_accessible.rb @@ -7,7 +7,7 @@ module VagrantPlugins end def call(env) - if env[:machine].state == :inaccessible + if env[:machine].state.id == :inaccessible # The VM we are attempting to manipulate is inaccessible. This # is a very bad situation and can only be fixed by the user. It # also prohibits us from actually doing anything with the virtual diff --git a/plugins/providers/virtualbox/action/check_created.rb b/plugins/providers/virtualbox/action/check_created.rb index 307cc1ed4..b1315e7b0 100644 --- a/plugins/providers/virtualbox/action/check_created.rb +++ b/plugins/providers/virtualbox/action/check_created.rb @@ -9,7 +9,7 @@ module VagrantPlugins end def call(env) - if env[:machine].state == :not_created + if env[:machine].state.id == :not_created raise Vagrant::Errors::VMNotCreatedError end diff --git a/plugins/providers/virtualbox/action/check_running.rb b/plugins/providers/virtualbox/action/check_running.rb index 483493602..99ac428a4 100644 --- a/plugins/providers/virtualbox/action/check_running.rb +++ b/plugins/providers/virtualbox/action/check_running.rb @@ -9,7 +9,7 @@ module VagrantPlugins end def call(env) - if env[:machine].state != :running + if env[:machine].state.id != :running raise Vagrant::Errors::VMNotRunningError end diff --git a/plugins/providers/virtualbox/action/created.rb b/plugins/providers/virtualbox/action/created.rb index 804801459..f1ff75d9f 100644 --- a/plugins/providers/virtualbox/action/created.rb +++ b/plugins/providers/virtualbox/action/created.rb @@ -8,7 +8,7 @@ module VagrantPlugins def call(env) # Set the result to be true if the machine is created. - env[:result] = env[:machine].state != :not_created + env[:result] = env[:machine].state.id != :not_created # Call the next if we have one (but we shouldn't, since this # middleware is built to run with the Call-type middlewares) diff --git a/plugins/providers/virtualbox/action/discard_state.rb b/plugins/providers/virtualbox/action/discard_state.rb index b19ccbfea..b7d9753ea 100644 --- a/plugins/providers/virtualbox/action/discard_state.rb +++ b/plugins/providers/virtualbox/action/discard_state.rb @@ -7,7 +7,7 @@ module VagrantPlugins end def call(env) - if env[:machine].provider.state == :saved + if env[:machine].provider.state.id == :saved env[:ui].info I18n.t("vagrant.actions.vm.discard_state.discarding") env[:machine].provider.driver.discard_saved_state end diff --git a/plugins/providers/virtualbox/action/export.rb b/plugins/providers/virtualbox/action/export.rb index 2bf9f3353..8beb9869e 100644 --- a/plugins/providers/virtualbox/action/export.rb +++ b/plugins/providers/virtualbox/action/export.rb @@ -13,7 +13,8 @@ module VagrantPlugins def call(env) @env = env - raise Vagrant::Errors::VMPowerOffToPackage if @env[:machine].provider.state != :poweroff + raise Vagrant::Errors::VMPowerOffToPackage if \ + @env[:machine].provider.state.id != :poweroff setup_temp_dir export diff --git a/plugins/providers/virtualbox/action/halt.rb b/plugins/providers/virtualbox/action/halt.rb index 42b749acd..d51990910 100644 --- a/plugins/providers/virtualbox/action/halt.rb +++ b/plugins/providers/virtualbox/action/halt.rb @@ -7,7 +7,7 @@ module VagrantPlugins end def call(env) - current_state = env[:machine].provider.state + current_state = env[:machine].provider.state.id if current_state == :running || current_state == :gurumeditation # If the VM is running and we're not forcing, we can # attempt a graceful shutdown @@ -17,7 +17,7 @@ module VagrantPlugins end # If we're not powered off now, then force it - if env[:machine].provider.state != :poweroff + if env[:machine].provider.state.id != :poweroff env[:ui].info I18n.t("vagrant.actions.vm.halt.force") env[:machine].provider.driver.halt end diff --git a/plugins/providers/virtualbox/action/import.rb b/plugins/providers/virtualbox/action/import.rb index d7f287e90..14ac2b0bb 100644 --- a/plugins/providers/virtualbox/action/import.rb +++ b/plugins/providers/virtualbox/action/import.rb @@ -33,7 +33,7 @@ module VagrantPlugins end def recover(env) - if env[:machine].provider.state != :not_created + if env[:machine].provider.state.id != :not_created return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError) # Interrupted, destroy the VM. We note that we don't want to diff --git a/plugins/providers/virtualbox/action/is_running.rb b/plugins/providers/virtualbox/action/is_running.rb index 565b3a735..7aa148858 100644 --- a/plugins/providers/virtualbox/action/is_running.rb +++ b/plugins/providers/virtualbox/action/is_running.rb @@ -8,7 +8,7 @@ module VagrantPlugins def call(env) # Set the result to be true if the machine is running. - env[:result] = env[:machine].state == :running + env[:result] = env[:machine].state.id == :running # Call the next if we have one (but we shouldn't, since this # middleware is built to run with the Call-type middlewares) diff --git a/plugins/providers/virtualbox/action/is_saved.rb b/plugins/providers/virtualbox/action/is_saved.rb index 749f64964..18474b5eb 100644 --- a/plugins/providers/virtualbox/action/is_saved.rb +++ b/plugins/providers/virtualbox/action/is_saved.rb @@ -8,7 +8,7 @@ module VagrantPlugins def call(env) # Set the result to be true if the machine is saved. - env[:result] = env[:machine].state == :saved + env[:result] = env[:machine].state.id == :saved # Call the next if we have one (but we shouldn't, since this # middleware is built to run with the Call-type middlewares) diff --git a/plugins/providers/virtualbox/action/resume.rb b/plugins/providers/virtualbox/action/resume.rb index 9967b91fe..6deab6e91 100644 --- a/plugins/providers/virtualbox/action/resume.rb +++ b/plugins/providers/virtualbox/action/resume.rb @@ -7,7 +7,7 @@ module VagrantPlugins end def call(env) - if env[:machine].provider.state == :saved + if env[:machine].provider.state.id == :saved env[:ui].info I18n.t("vagrant.actions.vm.resume.resuming") env[:action_runner].run(Boot, env) end diff --git a/plugins/providers/virtualbox/action/suspend.rb b/plugins/providers/virtualbox/action/suspend.rb index 9a9b7a94b..af4d1cc9e 100644 --- a/plugins/providers/virtualbox/action/suspend.rb +++ b/plugins/providers/virtualbox/action/suspend.rb @@ -7,7 +7,7 @@ module VagrantPlugins end def call(env) - if env[:machine].provider.state == :running + if env[:machine].provider.state.id == :running env[:ui].info I18n.t("vagrant.actions.vm.suspend.suspending") env[:machine].provider.driver.suspend end