Start moving the halt commands over to the new provider interface
This commit is contained in:
parent
e5f250121a
commit
31a3a3f2e2
|
@ -22,13 +22,8 @@ module VagrantPlugins
|
|||
|
||||
@logger.debug("Halt command: #{argv.inspect} #{options.inspect}")
|
||||
with_target_vms(argv) do |vm|
|
||||
if vm.created?
|
||||
@logger.info("Halting #{vm.name}")
|
||||
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
|
||||
# XXX: "force"
|
||||
vm.action(:halt)
|
||||
end
|
||||
|
||||
# Success, exit status 0
|
||||
|
|
|
@ -6,6 +6,7 @@ module VagrantPlugins
|
|||
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
|
||||
autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __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
|
||||
# things.
|
||||
|
@ -17,24 +18,42 @@ module VagrantPlugins
|
|||
Vagrant::Action::Builder.new.tap do |b|
|
||||
b.use CheckVirtualbox
|
||||
b.use Call, Created do |env1, b2|
|
||||
if env1[:result]
|
||||
# If the VM is created, then we confirm that we want to
|
||||
# destroy it.
|
||||
message = I18n.t("vagrant.commands.destroy.confirmation",
|
||||
:name => env[:machine].name)
|
||||
confirm = Vagrant::Action::Builder.build(Confirm, message)
|
||||
if !env1[:result]
|
||||
b2.use MessageNotCreated
|
||||
next
|
||||
end
|
||||
|
||||
b2.use Call, confirm do |env2, b3|
|
||||
if env2[:result]
|
||||
b3.use Vagrant::Action::General::Validate
|
||||
b3.use CheckAccessible
|
||||
else
|
||||
env2[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
|
||||
:name => env[:machine.name])
|
||||
end
|
||||
# If the VM is created, then we confirm that we want to
|
||||
# destroy it.
|
||||
message = I18n.t("vagrant.commands.destroy.confirmation",
|
||||
:name => env[:machine].name)
|
||||
confirm = Vagrant::Action::Builder.build(Confirm, message)
|
||||
|
||||
b2.use Call, confirm do |env2, b3|
|
||||
if env2[:result]
|
||||
b3.use Vagrant::Action::General::Validate
|
||||
b3.use CheckAccessible
|
||||
else
|
||||
env2[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
|
||||
:name => env[:machine.name])
|
||||
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
|
||||
env1[:ui].info I18n.t("vagrant.commands.common.vm_not_created")
|
||||
b2.use MessageNotCreated
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue