`--[no-]parallel` for vagrant up

This commit is contained in:
Mitchell Hashimoto 2013-04-16 15:22:14 -07:00
parent f3cf23e873
commit 0f089c5671
5 changed files with 29 additions and 17 deletions

View File

@ -1,5 +1,10 @@
## 1.2.1 (unreleased) ## 1.2.1 (unreleased)
FEATURES:
- Add a `--[no-]parallel` flag to `vagrant up` to enable/disable
parallelism. Vagrant will parallelize by default.
IMPROVEMENTS: IMPROVEMENTS:
- Get rid of arbitrary 4 second sleep when connecting via SSH. The - Get rid of arbitrary 4 second sleep when connecting via SSH. The

View File

@ -6,9 +6,9 @@ module Vagrant
# This class executes multiple actions as a single batch, parallelizing # This class executes multiple actions as a single batch, parallelizing
# the action calls if possible. # the action calls if possible.
class BatchAction class BatchAction
def initialize(disable_parallel=false) def initialize(allow_parallel=true)
@actions = [] @actions = []
@disable_parallel = disable_parallel @allow_parallel = allow_parallel
@logger = Log4r::Logger.new("vagrant::batch_action") @logger = Log4r::Logger.new("vagrant::batch_action")
end end
@ -27,14 +27,14 @@ module Vagrant
# Run all the queued up actions, parallelizing if possible. # Run all the queued up actions, parallelizing if possible.
# #
# This will parallelize if and only if the provider of every machine # This will parallelize if and only if the provider of every machine
# supports parallelization. Parallelizing can additionally be disabled # supports parallelization and parallelization is possible from
# by passing the option into the initializer of this class. # initialization of the class.
def run def run
par = true
if @disable_parallel
par = false par = false
@logger.info("Disabled parallelization by force.")
if @allow_parallel
par = true
@logger.info("Enabling parallelization by default.")
end end
if par if par

View File

@ -197,11 +197,11 @@ module Vagrant
# #
# This handles the case where batch actions are disabled by the # This handles the case where batch actions are disabled by the
# VAGRANT_NO_PARALLEL environmental variable. # VAGRANT_NO_PARALLEL environmental variable.
def batch(disable_parallel=false) def batch(parallel=true)
disable_parallel ||= !!ENV["VAGRANT_NO_PARALLEL"] parallel = false if ENV["VAGRANT_NO_PARALLEL"]
@batch_lock.synchronize do @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 it so that the caller can setup actions
yield b yield b

View File

@ -11,12 +11,19 @@ module VagrantPlugins
def execute def execute
options = {} options = {}
options[:parallel] = true
opts = OptionParser.new do |o| 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 "" o.separator ""
build_start_options(o, options) 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, o.on("--provider provider", String,
"Back the machine with a specific provider.") do |provider| "Back the machine with a specific provider.") do |provider|
options[:provider] = provider options[:provider] = provider
@ -31,7 +38,7 @@ module VagrantPlugins
@logger.debug("'Up' each target VM...") @logger.debug("'Up' each target VM...")
# Build up the batch job of what we'll do # 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| with_target_vms(argv, :provider => options[:provider]) do |machine|
@env.ui.info(I18n.t( @env.ui.info(I18n.t(
"vagrant.commands.up.upping", "vagrant.commands.up.upping",

View File

@ -58,7 +58,7 @@ describe Vagrant::Environment do
context "without the disabling env var" do context "without the disabling env var" do
it "should run without disabling parallelization" do it "should run without disabling parallelization" do
with_temp_env("VAGRANT_NO_PARALLEL" => nil) 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) batch.should_receive(:run)
instance.batch {} instance.batch {}
@ -67,10 +67,10 @@ describe Vagrant::Environment do
it "should run with disabling parallelization if explicit" do it "should run with disabling parallelization if explicit" do
with_temp_env("VAGRANT_NO_PARALLEL" => nil) 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) batch.should_receive(:run)
instance.batch(true) {} instance.batch(false) {}
end end
end end
end end
@ -78,7 +78,7 @@ describe Vagrant::Environment do
context "with the disabling env var" do context "with the disabling env var" do
it "should run with disabling parallelization" do it "should run with disabling parallelization" do
with_temp_env("VAGRANT_NO_PARALLEL" => "yes") 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) batch.should_receive(:run)
instance.batch {} instance.batch {}