Destroy VMs in reverse order. [GH-739]

This commit is contained in:
Mitchell Hashimoto 2012-02-14 10:42:30 -08:00
parent 2cf146cf6b
commit 96a920e4e5
6 changed files with 13 additions and 6 deletions

View File

@ -19,6 +19,7 @@
[GH-726]
- Fix issue where Vagrant would sometimes "lose" a VM if an exception
occurred. [GH-725]
- `vagrant destroy` destroys virtual machines in reverse order. [GH-739]
## 0.9.7 (February 9, 2012)

View File

@ -60,10 +60,13 @@ module Vagrant
# @param [String] name The name of the VM. Nil if every VM.
# @param [Boolean] single_target If true, then an exception will be
# raised if more than one target is found.
def with_target_vms(name=nil, single_target=false)
def with_target_vms(name=nil, options=nil)
# Using VMs requires a Vagrant environment to be properly setup
raise Errors::NoEnvironmentError if !@env.root_path
# Setup the options hash
options ||= {}
# First determine the proper array of VMs.
vms = []
if name
@ -89,7 +92,10 @@ module Vagrant
end
# Make sure we're only working with one VM if single target
raise Errors::MultiVMTargetRequired if single_target && vms.length != 1
raise Errors::MultiVMTargetRequired if options[:single_target] && vms.length != 1
# If we asked for reversed ordering, then reverse it
vms.reverse! if options[:reverse]
# Go through each VM and yield it!
vms.each do |old_vm|

View File

@ -20,7 +20,7 @@ module Vagrant
return if !argv
@logger.debug("'Destroy' each target VM...")
with_target_vms(argv[0]) do |vm|
with_target_vms(argv[0], :reverse => true) do |vm|
if vm.created?
# Boolean whether we should actually go through with the destroy
# or not. This is true only if the "--force" flag is set or if the

View File

@ -51,7 +51,7 @@ module Vagrant
end
def package_target(name, options)
with_target_vms(name, true) do |vm|
with_target_vms(name, :single_target => true) do |vm|
raise Errors::VMNotCreatedError if !vm.created?
@logger.debug("Packaging VM: #{vm.name}")
package_vm(vm, options)

View File

@ -36,7 +36,7 @@ module Vagrant
argv = [] if argv == ssh_args
# Execute the actual SSH
with_target_vms(argv[0], true) do |vm|
with_target_vms(argv[0], :single_target => true) do |vm|
# Basic checks that are required for proper SSH
raise Errors::VMNotCreatedError if !vm.created?
raise Errors::VMInaccessible if !vm.state == :inaccessible

View File

@ -19,7 +19,7 @@ module Vagrant
argv = parse_options(opts)
return if !argv
with_target_vms(argv[0], true) do |vm|
with_target_vms(argv[0], :single_target => true) do |vm|
raise Errors::VMNotCreatedError if !vm.created?
raise Errors::VMInaccessible if !vm.state == :inaccessible