2012-07-27 05:39:27 +00:00
|
|
|
require "vagrant/action/builder"
|
|
|
|
|
|
|
|
module VagrantPlugins
|
|
|
|
module ProviderVirtualBox
|
|
|
|
module Action
|
|
|
|
autoload :CheckAccessible, File.expand_path("../action/check_accessible", __FILE__)
|
|
|
|
autoload :CheckVirtualbox, File.expand_path("../action/check_virtualbox", __FILE__)
|
2012-07-27 06:56:47 +00:00
|
|
|
autoload :Created, File.expand_path("../action/created", __FILE__)
|
2012-07-28 17:43:16 +00:00
|
|
|
autoload :MessageNotCreated, File.expand_path("../action/message_not_created", __FILE__)
|
2012-07-27 06:56:47 +00:00
|
|
|
|
|
|
|
# Include the built-in modules so that we can use them as top-level
|
|
|
|
# things.
|
|
|
|
include Vagrant::Action::Builtin
|
2012-07-27 05:39:27 +00:00
|
|
|
|
|
|
|
# This is the action that is primarily responsible for completely
|
|
|
|
# freeing the resources of the underlying virtual machine.
|
|
|
|
def self.action_destroy
|
|
|
|
Vagrant::Action::Builder.new.tap do |b|
|
|
|
|
b.use CheckVirtualbox
|
2012-07-28 02:34:46 +00:00
|
|
|
b.use Call, Created do |env1, b2|
|
2012-07-28 17:43:16 +00:00
|
|
|
if !env1[:result]
|
|
|
|
b2.use MessageNotCreated
|
|
|
|
next
|
|
|
|
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)
|
2012-07-28 02:29:40 +00:00
|
|
|
|
2012-07-28 17:43:16 +00:00
|
|
|
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])
|
2012-07-28 02:29:40 +00:00
|
|
|
end
|
2012-07-28 17:43:16 +00:00
|
|
|
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
|
2012-07-28 02:29:40 +00:00
|
|
|
else
|
2012-07-28 17:43:16 +00:00
|
|
|
b2.use MessageNotCreated
|
2012-07-27 06:56:47 +00:00
|
|
|
end
|
|
|
|
end
|
2012-07-27 05:39:27 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|