Add autostart as an option for vagrant boxes

Added specs for the environment and vagrantfile. Added a methd to retrieve
autostart_machine_names. Changed the plugin up/command to use autostart_machine_names
when no argument was given to the command.
This commit is contained in:
Ramon de la Fuente 2014-03-04 22:51:25 +01:00 committed by Mitchell Hashimoto
parent c8c74693fa
commit f6a5e20688
5 changed files with 69 additions and 1 deletions

View File

@ -426,6 +426,16 @@ module Vagrant
vagrantfile.machine_names vagrantfile.machine_names
end 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<Symbol>] 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 # 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 # case of a single-machine environment, this is just the single machine
# name. In the case of a multi-machine environment, then this can # name. In the case of a multi-machine environment, then this can

View File

@ -197,6 +197,20 @@ module Vagrant
@config.vm.defined_vm_keys.dup @config.vm.defined_vm_keys.dup
end end
# Returns a list of the machines that are defined within this
# Vagrantfile that do not have "autostart" set to false.
#
# @return [Array<Symbol>]
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 # Returns the name of the machine that is designated as the
# "primary." # "primary."
# #

View File

@ -55,7 +55,11 @@ module VagrantPlugins
# Build up the batch job of what we'll do # Build up the batch job of what we'll do
@env.batch(options[:parallel]) do |batch| @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( @env.ui.info(I18n.t(
"vagrant.commands.up.upping", "vagrant.commands.up.upping",
:name => machine.name, :name => machine.name,

View File

@ -956,5 +956,22 @@ VF
env = isolated_env.create_vagrant_env env = isolated_env.create_vagrant_env
expect(env.machine_names).to eq([:foo, :bar]) expect(env.machine_names).to eq([:foo, :bar])
end 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
end end

View File

@ -318,6 +318,29 @@ describe Vagrant::Vagrantfile do
end end
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 describe "#primary_machine_name" do
it "returns the default name when single-VM" do it "returns the default name when single-VM" do
configure { |config| } configure { |config| }