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}")
|
@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
|
||||||
|
|
|
@ -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,24 +18,42 @@ 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]
|
||||||
# If the VM is created, then we confirm that we want to
|
b2.use MessageNotCreated
|
||||||
# destroy it.
|
next
|
||||||
message = I18n.t("vagrant.commands.destroy.confirmation",
|
end
|
||||||
:name => env[:machine].name)
|
|
||||||
confirm = Vagrant::Action::Builder.build(Confirm, message)
|
|
||||||
|
|
||||||
b2.use Call, confirm do |env2, b3|
|
# If the VM is created, then we confirm that we want to
|
||||||
if env2[:result]
|
# destroy it.
|
||||||
b3.use Vagrant::Action::General::Validate
|
message = I18n.t("vagrant.commands.destroy.confirmation",
|
||||||
b3.use CheckAccessible
|
:name => env[:machine].name)
|
||||||
else
|
confirm = Vagrant::Action::Builder.build(Confirm, message)
|
||||||
env2[:ui].info I18n.t("vagrant.commands.destroy.will_not_destroy",
|
|
||||||
:name => env[:machine.name])
|
b2.use Call, confirm do |env2, b3|
|
||||||
end
|
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
|
||||||
|
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
|
||||||
|
|
|
@ -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