`--[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)
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

View File

@ -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

View File

@ -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

View File

@ -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",

View File

@ -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 {}