diff --git a/lib/vagrant/command/base.rb b/lib/vagrant/command/base.rb index 38c2c144f..e0298fc8b 100644 --- a/lib/vagrant/command/base.rb +++ b/lib/vagrant/command/base.rb @@ -64,7 +64,7 @@ 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, options=nil) + def with_target_vms(names=nil, options=nil) # Using VMs requires a Vagrant environment to be properly setup raise Errors::NoEnvironmentError if !@env.root_path @@ -73,28 +73,30 @@ module Vagrant # First determine the proper array of VMs. vms = [] - if name - raise Errors::MultiVMEnvironmentRequired if !@env.multivm? + if names.length > 0 + names.each do |name| + raise Errors::MultiVMEnvironmentRequired if !@env.multivm? - if name =~ /^\/(.+?)\/$/ - # This is a regular expression name, so we convert to a regular - # expression and allow that sort of matching. - regex = Regexp.new($1.to_s) + if name =~ /^\/(.+?)\/$/ + # This is a regular expression name, so we convert to a regular + # expression and allow that sort of matching. + regex = Regexp.new($1.to_s) - @env.vms.each do |name, vm| - vms << vm if name =~ regex + @env.vms.each do |name, vm| + vms << vm if name =~ regex + end + + raise Errors::VMNoMatchError if vms.empty? + else + # String name, just look for a specific VM + vms << @env.vms[name.to_sym] + raise Errors::VMNotFoundError, :name => name if !vms[0] end - - raise Errors::VMNoMatchError if vms.empty? - else - # String name, just look for a specific VM - vms << @env.vms[name.to_sym] - raise Errors::VMNotFoundError, :name => name if !vms[0] end else vms = @env.vms_ordered end - + # Make sure we're only working with one VM if single target raise Errors::MultiVMTargetRequired if options[:single_target] && vms.length != 1 diff --git a/lib/vagrant/command/destroy.rb b/lib/vagrant/command/destroy.rb index abbc13001..7d3ca4cd6 100644 --- a/lib/vagrant/command/destroy.rb +++ b/lib/vagrant/command/destroy.rb @@ -20,7 +20,7 @@ module Vagrant return if !argv @logger.debug("'Destroy' each target VM...") - with_target_vms(argv[0], :reverse => true) do |vm| + with_target_vms(argv, :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 diff --git a/lib/vagrant/command/halt.rb b/lib/vagrant/command/halt.rb index ce32a92d4..401037eec 100644 --- a/lib/vagrant/command/halt.rb +++ b/lib/vagrant/command/halt.rb @@ -21,7 +21,7 @@ module Vagrant return if !argv @logger.debug("Halt command: #{argv.inspect} #{options.inspect}") - with_target_vms(argv[0]) do |vm| + with_target_vms(argv) do |vm| if vm.created? @logger.info("Halting #{vm.name}") vm.halt(:force => options[:force]) diff --git a/lib/vagrant/command/package.rb b/lib/vagrant/command/package.rb index a8c5f7180..c9d0392bf 100644 --- a/lib/vagrant/command/package.rb +++ b/lib/vagrant/command/package.rb @@ -54,7 +54,7 @@ module Vagrant end def package_target(name, options) - with_target_vms(name, :single_target => 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) diff --git a/lib/vagrant/command/provision.rb b/lib/vagrant/command/provision.rb index 86bf337c9..89bfd43bf 100644 --- a/lib/vagrant/command/provision.rb +++ b/lib/vagrant/command/provision.rb @@ -16,7 +16,8 @@ module Vagrant # Go over each VM and provision! @logger.debug("'provision' each target VM...") - with_target_vms(argv[0]) do |vm| + with_target_vms(argv) do |vm| + if vm.created? if vm.state == :running @logger.info("Provisioning: #{vm.name}") diff --git a/lib/vagrant/command/reload.rb b/lib/vagrant/command/reload.rb index be675e445..ac3d63b4b 100644 --- a/lib/vagrant/command/reload.rb +++ b/lib/vagrant/command/reload.rb @@ -9,7 +9,8 @@ module Vagrant def execute options = {} - opts = OptionParser.new do |opts| + + opts = OptionParser.new do |opts| opts.banner = "Usage: vagrant reload [vm-name]" opts.separator "" build_start_options(opts, options) @@ -20,7 +21,7 @@ module Vagrant return if !argv @logger.debug("'reload' each target VM...") - with_target_vms(argv[0]) do |vm| + with_target_vms(argv) do |vm| if vm.created? @logger.info("Reloading: #{vm.name}") vm.reload(options) diff --git a/lib/vagrant/command/resume.rb b/lib/vagrant/command/resume.rb index e810d666e..b4ed7ea49 100644 --- a/lib/vagrant/command/resume.rb +++ b/lib/vagrant/command/resume.rb @@ -15,7 +15,7 @@ module Vagrant return if !argv @logger.debug("'resume' each target VM...") - with_target_vms(argv[0]) do |vm| + with_target_vms(argv) do |vm| if vm.created? @logger.info("Resume: #{vm.name}") vm.resume diff --git a/lib/vagrant/command/ssh.rb b/lib/vagrant/command/ssh.rb index 42384ae2b..cc2d780a3 100644 --- a/lib/vagrant/command/ssh.rb +++ b/lib/vagrant/command/ssh.rb @@ -36,7 +36,7 @@ module Vagrant argv = [] if argv == ssh_args # Execute the actual SSH - with_target_vms(argv[0], :single_target => true) do |vm| + with_target_vms(argv, :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 diff --git a/lib/vagrant/command/ssh_config.rb b/lib/vagrant/command/ssh_config.rb index 5d406d0e9..f8bcd2f53 100644 --- a/lib/vagrant/command/ssh_config.rb +++ b/lib/vagrant/command/ssh_config.rb @@ -23,7 +23,7 @@ module Vagrant argv = parse_options(opts) return if !argv - with_target_vms(argv[0], :single_target => true) do |vm| + with_target_vms(argv, :single_target => true) do |vm| raise Errors::VMNotCreatedError if !vm.created? raise Errors::VMInaccessible if !vm.state == :inaccessible diff --git a/lib/vagrant/command/status.rb b/lib/vagrant/command/status.rb index 94bb12628..4c2ec1452 100644 --- a/lib/vagrant/command/status.rb +++ b/lib/vagrant/command/status.rb @@ -16,7 +16,7 @@ module Vagrant state = nil results = [] - with_target_vms(argv[0]) do |vm| + with_target_vms(argv) do |vm| state = vm.state.to_s if !state results << "#{vm.name.to_s.ljust(25)}#{vm.state.to_s.gsub("_", " ")}" end diff --git a/lib/vagrant/command/suspend.rb b/lib/vagrant/command/suspend.rb index 9be41ef9e..fd121a456 100644 --- a/lib/vagrant/command/suspend.rb +++ b/lib/vagrant/command/suspend.rb @@ -15,7 +15,7 @@ module Vagrant return if !argv @logger.debug("'suspend' each target VM...") - with_target_vms(argv[0]) do |vm| + with_target_vms(argv) do |vm| if vm.created? @logger.info("Suspending: #{vm.name}") vm.suspend diff --git a/lib/vagrant/command/up.rb b/lib/vagrant/command/up.rb index 5dfddfe82..394f65765 100644 --- a/lib/vagrant/command/up.rb +++ b/lib/vagrant/command/up.rb @@ -21,7 +21,7 @@ module Vagrant # Go over each VM and bring it up @logger.debug("'Up' each target VM...") - with_target_vms(argv[0]) do |vm| + with_target_vms(argv) do |vm| if vm.created? @logger.info("Booting: #{vm.name}") vm.ui.info I18n.t("vagrant.commands.up.vm_created")