diff --git a/CHANGELOG.md b/CHANGELOG.md index 98576e320..751808a7c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ## 1.2.1 (unreleased) +FEATURES: + + - Add a `--[no-]parallel` flag to `vagrant up` to enable/disable + parallelism. Vagrant will parallelize by default. + IMPROVEMENTS: - Get rid of arbitrary 4 second sleep when connecting via SSH. The diff --git a/lib/vagrant/batch_action.rb b/lib/vagrant/batch_action.rb index 5df193666..5ae8f7cc4 100644 --- a/lib/vagrant/batch_action.rb +++ b/lib/vagrant/batch_action.rb @@ -6,9 +6,9 @@ module Vagrant # This class executes multiple actions as a single batch, parallelizing # the action calls if possible. class BatchAction - def initialize(disable_parallel=false) + def initialize(allow_parallel=true) @actions = [] - @disable_parallel = disable_parallel + @allow_parallel = allow_parallel @logger = Log4r::Logger.new("vagrant::batch_action") end @@ -27,14 +27,14 @@ module Vagrant # Run all the queued up actions, parallelizing if possible. # # This will parallelize if and only if the provider of every machine - # supports parallelization. Parallelizing can additionally be disabled - # by passing the option into the initializer of this class. + # supports parallelization and parallelization is possible from + # initialization of the class. def run - par = true + par = false - if @disable_parallel - par = false - @logger.info("Disabled parallelization by force.") + if @allow_parallel + par = true + @logger.info("Enabling parallelization by default.") end if par diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index 339db08ab..1e2b042e4 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -197,11 +197,11 @@ module Vagrant # # This handles the case where batch actions are disabled by the # VAGRANT_NO_PARALLEL environmental variable. - def batch(disable_parallel=false) - disable_parallel ||= !!ENV["VAGRANT_NO_PARALLEL"] + def batch(parallel=true) + parallel = false if ENV["VAGRANT_NO_PARALLEL"] @batch_lock.synchronize do - BatchAction.new(disable_parallel).tap do |b| + BatchAction.new(parallel).tap do |b| # Yield it so that the caller can setup actions yield b diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index 8ad3b969f..480342ecd 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -11,12 +11,19 @@ module VagrantPlugins def execute options = {} + options[:parallel] = true + opts = OptionParser.new do |o| - o.banner = "Usage: vagrant up [vm-name] [--[no-]provision] [--provider provider] [-h]" + o.banner = "Usage: vagrant up [vm-name] [options] [-h]" o.separator "" build_start_options(o, options) + o.on("--[no-]parallel", + "Enable or disable parallelism if provider supports it.") do |parallel| + options[:parallel] = parallel + end + o.on("--provider provider", String, "Back the machine with a specific provider.") do |provider| options[:provider] = provider @@ -31,7 +38,7 @@ module VagrantPlugins @logger.debug("'Up' each target VM...") # Build up the batch job of what we'll do - @env.batch do |batch| + @env.batch(options[:parallel]) do |batch| with_target_vms(argv, :provider => options[:provider]) do |machine| @env.ui.info(I18n.t( "vagrant.commands.up.upping", diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 694700638..971bca9f7 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -58,7 +58,7 @@ describe Vagrant::Environment do context "without the disabling env var" do it "should run without disabling parallelization" do with_temp_env("VAGRANT_NO_PARALLEL" => nil) do - Vagrant::BatchAction.should_receive(:new).with(false).and_return(batch) + Vagrant::BatchAction.should_receive(:new).with(true).and_return(batch) batch.should_receive(:run) instance.batch {} @@ -67,10 +67,10 @@ describe Vagrant::Environment do it "should run with disabling parallelization if explicit" do with_temp_env("VAGRANT_NO_PARALLEL" => nil) do - Vagrant::BatchAction.should_receive(:new).with(true).and_return(batch) + Vagrant::BatchAction.should_receive(:new).with(false).and_return(batch) batch.should_receive(:run) - instance.batch(true) {} + instance.batch(false) {} end end end @@ -78,7 +78,7 @@ describe Vagrant::Environment do context "with the disabling env var" do it "should run with disabling parallelization" do with_temp_env("VAGRANT_NO_PARALLEL" => "yes") do - Vagrant::BatchAction.should_receive(:new).with(true).and_return(batch) + Vagrant::BatchAction.should_receive(:new).with(false).and_return(batch) batch.should_receive(:run) instance.batch {}