Convert all VirtualBox provider internals to use new state API

This commit is contained in:
Mitchell Hashimoto 2013-01-21 11:38:37 -06:00
parent 8c4a7350fe
commit d5c5c4f523
13 changed files with 15 additions and 14 deletions

View File

@ -34,7 +34,7 @@ module VagrantPlugins
# If the VM is not starting or running, something went wrong # If the VM is not starting or running, something went wrong
# and we need to show a useful error. # 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 raise Errors::VMFailedToRun if state != :starting && state != :running
sleep 2 if !@env["vagrant.test"] sleep 2 if !@env["vagrant.test"]

View File

@ -7,7 +7,7 @@ module VagrantPlugins
end end
def call(env) def call(env)
if env[:machine].state == :inaccessible if env[:machine].state.id == :inaccessible
# The VM we are attempting to manipulate is inaccessible. This # The VM we are attempting to manipulate is inaccessible. This
# is a very bad situation and can only be fixed by the user. It # is a very bad situation and can only be fixed by the user. It
# also prohibits us from actually doing anything with the virtual # also prohibits us from actually doing anything with the virtual

View File

@ -9,7 +9,7 @@ module VagrantPlugins
end end
def call(env) def call(env)
if env[:machine].state == :not_created if env[:machine].state.id == :not_created
raise Vagrant::Errors::VMNotCreatedError raise Vagrant::Errors::VMNotCreatedError
end end

View File

@ -9,7 +9,7 @@ module VagrantPlugins
end end
def call(env) def call(env)
if env[:machine].state != :running if env[:machine].state.id != :running
raise Vagrant::Errors::VMNotRunningError raise Vagrant::Errors::VMNotRunningError
end end

View File

@ -8,7 +8,7 @@ module VagrantPlugins
def call(env) def call(env)
# Set the result to be true if the machine is created. # 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 # Call the next if we have one (but we shouldn't, since this
# middleware is built to run with the Call-type middlewares) # middleware is built to run with the Call-type middlewares)

View File

@ -7,7 +7,7 @@ module VagrantPlugins
end end
def call(env) 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[:ui].info I18n.t("vagrant.actions.vm.discard_state.discarding")
env[:machine].provider.driver.discard_saved_state env[:machine].provider.driver.discard_saved_state
end end

View File

@ -13,7 +13,8 @@ module VagrantPlugins
def call(env) def call(env)
@env = 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 setup_temp_dir
export export

View File

@ -7,7 +7,7 @@ module VagrantPlugins
end end
def call(env) def call(env)
current_state = env[:machine].provider.state current_state = env[:machine].provider.state.id
if current_state == :running || current_state == :gurumeditation if current_state == :running || current_state == :gurumeditation
# If the VM is running and we're not forcing, we can # If the VM is running and we're not forcing, we can
# attempt a graceful shutdown # attempt a graceful shutdown
@ -17,7 +17,7 @@ module VagrantPlugins
end end
# If we're not powered off now, then force it # 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[:ui].info I18n.t("vagrant.actions.vm.halt.force")
env[:machine].provider.driver.halt env[:machine].provider.driver.halt
end end

View File

@ -33,7 +33,7 @@ module VagrantPlugins
end end
def recover(env) 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) return if env["vagrant.error"].is_a?(Vagrant::Errors::VagrantError)
# Interrupted, destroy the VM. We note that we don't want to # Interrupted, destroy the VM. We note that we don't want to

View File

@ -8,7 +8,7 @@ module VagrantPlugins
def call(env) def call(env)
# Set the result to be true if the machine is running. # 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 # Call the next if we have one (but we shouldn't, since this
# middleware is built to run with the Call-type middlewares) # middleware is built to run with the Call-type middlewares)

View File

@ -8,7 +8,7 @@ module VagrantPlugins
def call(env) def call(env)
# Set the result to be true if the machine is saved. # 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 # Call the next if we have one (but we shouldn't, since this
# middleware is built to run with the Call-type middlewares) # middleware is built to run with the Call-type middlewares)

View File

@ -7,7 +7,7 @@ module VagrantPlugins
end end
def call(env) 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[:ui].info I18n.t("vagrant.actions.vm.resume.resuming")
env[:action_runner].run(Boot, env) env[:action_runner].run(Boot, env)
end end

View File

@ -7,7 +7,7 @@ module VagrantPlugins
end end
def call(env) 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[:ui].info I18n.t("vagrant.actions.vm.suspend.suspending")
env[:machine].provider.driver.suspend env[:machine].provider.driver.suspend
end end