Start moving the halt commands over to the new provider interface

This commit is contained in:
Mitchell Hashimoto 2012-07-28 10:43:16 -07:00
parent e5f250121a
commit 31a3a3f2e2
3 changed files with 52 additions and 22 deletions

View File

@ -22,13 +22,8 @@ module VagrantPlugins
@logger.debug("Halt command: #{argv.inspect} #{options.inspect}") @logger.debug("Halt command: #{argv.inspect} #{options.inspect}")
with_target_vms(argv) do |vm| with_target_vms(argv) do |vm|
if vm.created? # XXX: "force"
@logger.info("Halting #{vm.name}") vm.action(:halt)
vm.halt(:force => options[:force])
else
@logger.info("Not halting #{vm.name}, since not created.")
vm.ui.info I18n.t("vagrant.commands.common.vm_not_created")
end
end end
# Success, exit status 0 # Success, exit status 0

View File

@ -6,6 +6,7 @@ module VagrantPlugins
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__) autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __FILE__) autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __FILE__)
autoload :Created, File.expand_path("../action/created", __FILE__) autoload :Created, File.expand_path("../action/created", __FILE__)
autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
# Include the built-in modules so that we can use them as top-level # Include the built-in modules so that we can use them as top-level
# things. # things.
@ -17,7 +18,11 @@ module VagrantPlugins
Vagrant::Action::Builder.new.tap do |b| Vagrant::Action::Builder.new.tap do |b|
b.use CheckVirtualbox b.use CheckVirtualbox
b.use Call, Created do |env1, b2| b.use Call, Created do |env1, b2|
if env1[:result] if !env1[:result]
b2.use MessageNotCreated
next
end
# If the VM is created, then we confirm that we want to # If the VM is created, then we confirm that we want to
# destroy it. # destroy it.
message = I18n.t("vagrant.commands.destroy.confirmation", message = I18n.t("vagrant.commands.destroy.confirmation",
@ -33,8 +38,22 @@ module VagrantPlugins
:name => env[:machine.name]) :name => env[:machine.name])
end end
end end
end
end
end
# This is the action that is primarily responsible for halting
# the virtual machine, gracefully or by force.
def self.action_halt
Vagrant::Action::Builder.new.tap do |b|
b.use CheckVirtualbox
b.use Call, Created do |env, b2|
if env[:result]
b2.use CheckAccessible
b2.use DiscardState
b2.use Halt
else else
env1[:ui].info I18n.t("vagrant.commands.common.vm_not_created") b2.use MessageNotCreated
end end
end end
end end

View File

@ -0,0 +1,16 @@
module VagrantPlugins
module ProviderVirtualBox
module Action
class MessageNotCreated
def initialize(app, env)
@app = app
end
def call(env)
env[:ui].info I18n.t("vagrant.commands.common.vm_not_created")
@app.call(env)
end
end
end
end
end