Introduce parallel destroy for certain providers
This commit introduces parallel destroy using the batch action class for the destroy command.
This commit is contained in:
parent
52824f20b4
commit
2d7858ff8a
|
@ -18,6 +18,11 @@ module VagrantPlugins
|
||||||
o.on("-f", "--force", "Destroy without confirmation.") do |f|
|
o.on("-f", "--force", "Destroy without confirmation.") do |f|
|
||||||
options[:force] = f
|
options[:force] = f
|
||||||
end
|
end
|
||||||
|
|
||||||
|
o.on("--[no-]parallel",
|
||||||
|
"Enable or disable parallelism if provider supports it") do |p|
|
||||||
|
options[:parallel] = p
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Parse the options
|
# Parse the options
|
||||||
|
@ -25,25 +30,31 @@ module VagrantPlugins
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
@logger.debug("'Destroy' each target VM...")
|
@logger.debug("'Destroy' each target VM...")
|
||||||
declined = 0
|
|
||||||
total = 0
|
|
||||||
with_target_vms(argv, reverse: true) do |vm|
|
|
||||||
action_env = vm.action(
|
|
||||||
:destroy, force_confirm_destroy: options[:force])
|
|
||||||
|
|
||||||
total += 1
|
if options[:parallel]
|
||||||
declined += 1 if action_env.key?(:force_confirm_destroy_result) &&
|
options[:force] = true
|
||||||
action_env[:force_confirm_destroy_result] == false
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Nothing was declined
|
machines = []
|
||||||
return 0 if declined == 0
|
|
||||||
|
|
||||||
# Everything was declined
|
@env.batch(options[:parallel]) do |batch|
|
||||||
return 1 if declined == total
|
with_target_vms(argv, reverse: true) do |vm|
|
||||||
|
machines << vm
|
||||||
|
batch.action(vm, :destroy, force_confirm_destroy: options[:force])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Some was declined
|
states = machines.map { |m| m.state.id }
|
||||||
return 2
|
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
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue