vagrant/plugins/commands/destroy/command.rb

62 lines
1.6 KiB
Ruby
Raw Normal View History

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)
def self.synopsis
"stops and deletes all traces of the vagrant machine"
end
2010-08-25 06:05:40 +00:00
def execute
options = {}
options[:force] = false
opts = OptionParser.new do |o|
2016-05-29 05:06:51 +00:00
o.banner = "Usage: vagrant destroy [options] [name|id]"
2014-02-08 08:20:50 +00:00
o.separator ""
o.separator "Options:"
o.separator ""
o.on("-f", "--force", "Destroy without confirmation.") do |f|
options[:force] = f
end
o.on("--[no-]parallel",
"Enable or disable parallelism if provider supports it") do |p|
options[:parallel] = p
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...")
if options[:parallel]
options[:force] = true
2010-08-25 06:05:40 +00:00
end
machines = []
@env.batch(options[:parallel]) do |batch|
with_target_vms(argv, reverse: true) do |vm|
machines << vm
batch.action(vm, :destroy, force_confirm_destroy: options[:force])
end
end
states = machines.map { |m| m.state.id }
if states.uniq.length == 1 && states.first == :not_created
# Nothing was declined
return 0
elsif states.uniq.length == 1 && states.first != :not_created
# Everything was declined
return 1
else
# Some was declined
return 2
end
end
2010-08-25 06:05:40 +00:00
end
end
end