diff --git a/lib/vagrant/environment.rb b/lib/vagrant/environment.rb index b6ff1d472..8a2efbb6e 100644 --- a/lib/vagrant/environment.rb +++ b/lib/vagrant/environment.rb @@ -426,6 +426,16 @@ module Vagrant vagrantfile.machine_names end + # This returns a list of the configured machines for this environment + # that do not have "autostart" set to false. + # Each of the names returned by this method is valid to be used with + # the {#machine} method. + # + # @return [Array] Configured autostart machine names. + def autostart_machine_names + vagrantfile.autostart_machine_names + end + # This returns the name of the machine that is the "primary." In the # case of a single-machine environment, this is just the single machine # name. In the case of a multi-machine environment, then this can diff --git a/lib/vagrant/vagrantfile.rb b/lib/vagrant/vagrantfile.rb index fde3769cf..2b83b254d 100644 --- a/lib/vagrant/vagrantfile.rb +++ b/lib/vagrant/vagrantfile.rb @@ -197,6 +197,20 @@ module Vagrant @config.vm.defined_vm_keys.dup end + # Returns a list of the machines that are defined within this + # Vagrantfile that do not have "autostart" set to false. + # + # @return [Array] + def autostart_machine_names + machines = [] + # Remove any machines that have autostart set to false from machine_names + @config.vm.defined_vms.each do |name, subvm| + machines << name if subvm.options[:autostart] == nil or subvm.options[:autostart] == true + end + + return machines + end + # Returns the name of the machine that is designated as the # "primary." # diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index 7c7ea76ce..3b000fc60 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -55,7 +55,11 @@ module VagrantPlugins # Build up the batch job of what we'll do @env.batch(options[:parallel]) do |batch| - with_target_vms(argv, :provider => options[:provider]) do |machine| + names = argv + if names.empty? then + names = @env.autostart_machine_names + end + with_target_vms(names, :provider => options[:provider]) do |machine| @env.ui.info(I18n.t( "vagrant.commands.up.upping", :name => machine.name, diff --git a/test/unit/vagrant/environment_test.rb b/test/unit/vagrant/environment_test.rb index 5c7606f76..f32f497ea 100644 --- a/test/unit/vagrant/environment_test.rb +++ b/test/unit/vagrant/environment_test.rb @@ -956,5 +956,22 @@ VF env = isolated_env.create_vagrant_env expect(env.machine_names).to eq([:foo, :bar]) end + + it "should return only the machine names configured to autostart" do + # Create the config + isolated_env = isolated_environment do |e| + e.vagrantfile(<<-VF) +Vagrant.configure("2") do |config| + config.vm.define "foo" + config.vm.define "bar", autostart: false + config.vm.define "baz", autostart: true +end +VF + end + + env = isolated_env.create_vagrant_env + env.autostart_machine_names.should == [:foo, :baz] + end + end end diff --git a/test/unit/vagrant/vagrantfile_test.rb b/test/unit/vagrant/vagrantfile_test.rb index c9b9b913f..0cdcf29c9 100644 --- a/test/unit/vagrant/vagrantfile_test.rb +++ b/test/unit/vagrant/vagrantfile_test.rb @@ -318,6 +318,29 @@ describe Vagrant::Vagrantfile do end end + describe "#autostart_machine_names" do + it "returns machine_names if no autostart values where set" do + configure do |config| + config.vm.define "foo" + config.vm.define "bar" + end + + expect(subject.autostart_machine_names).to eq( + subject.machine_names) + end + + it "returns only machine_names without autostart or autostart true" do + configure do |config| + config.vm.define "foo" + config.vm.define "bar", autostart: false + config.vm.define "baz", autostart: true + end + + expect(subject.autostart_machine_names).to eq( + [:foo, :baz]) + end + end + describe "#primary_machine_name" do it "returns the default name when single-VM" do configure { |config| }