2012-04-19 20:59:48 +00:00
|
|
|
module VagrantPlugins
|
|
|
|
module CommandDestroy
|
2012-11-07 05:05:14 +00:00
|
|
|
class Command < Vagrant.plugin("2", :command)
|
2013-11-23 22:00:42 +00:00
|
|
|
def self.synopsis
|
|
|
|
"stops and deletes all traces of the vagrant machine"
|
|
|
|
end
|
|
|
|
|
2010-08-25 06:05:40 +00:00
|
|
|
def execute
|
2012-02-08 06:58:01 +00:00
|
|
|
options = {}
|
2013-01-29 18:33:40 +00:00
|
|
|
options[:force] = false
|
2012-02-08 06:58:01 +00:00
|
|
|
|
2012-08-14 06:18:50 +00:00
|
|
|
opts = OptionParser.new do |o|
|
2014-02-08 08:20:50 +00:00
|
|
|
o.banner = "Usage: vagrant destroy [options] [name]"
|
|
|
|
o.separator ""
|
|
|
|
o.separator "Options:"
|
2012-08-14 06:18:50 +00:00
|
|
|
o.separator ""
|
2012-02-08 06:58:01 +00:00
|
|
|
|
2012-08-14 06:18:50 +00:00
|
|
|
o.on("-f", "--force", "Destroy without confirmation.") do |f|
|
2012-02-08 06:58:01 +00:00
|
|
|
options[:force] = f
|
|
|
|
end
|
2011-12-17 19:05:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Parse the options
|
|
|
|
argv = parse_options(opts)
|
|
|
|
return if !argv
|
|
|
|
|
|
|
|
@logger.debug("'Destroy' each target VM...")
|
2013-07-11 02:39:20 +00:00
|
|
|
declined = false
|
2012-03-11 22:32:17 +00:00
|
|
|
with_target_vms(argv, :reverse => true) do |vm|
|
2013-07-11 02:39:20 +00:00
|
|
|
action_env = vm.action(
|
|
|
|
:destroy, :force_confirm_destroy => options[:force])
|
|
|
|
|
|
|
|
declined = true if action_env.has_key?(:force_confirm_destroy_result) &&
|
|
|
|
action_env[:force_confirm_destroy_result] == false
|
2010-08-25 06:05:40 +00:00
|
|
|
end
|
2012-03-23 15:07:35 +00:00
|
|
|
|
2013-07-11 02:39:20 +00:00
|
|
|
# Success if no confirms were declined
|
|
|
|
declined ? 1 : 0
|
2012-07-28 02:29:40 +00:00
|
|
|
end
|
2010-08-25 06:05:40 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|