Allow multiple VMs to be specified for relevant commands
This commit is contained in:
parent
3338b6c134
commit
ff36845259
|
@ -64,7 +64,7 @@ module Vagrant
|
||||||
# @param [String] name The name of the VM. Nil if every VM.
|
# @param [String] name The name of the VM. Nil if every VM.
|
||||||
# @param [Boolean] single_target If true, then an exception will be
|
# @param [Boolean] single_target If true, then an exception will be
|
||||||
# raised if more than one target is found.
|
# raised if more than one target is found.
|
||||||
def with_target_vms(name=nil, options=nil)
|
def with_target_vms(names=nil, options=nil)
|
||||||
# Using VMs requires a Vagrant environment to be properly setup
|
# Using VMs requires a Vagrant environment to be properly setup
|
||||||
raise Errors::NoEnvironmentError if !@env.root_path
|
raise Errors::NoEnvironmentError if !@env.root_path
|
||||||
|
|
||||||
|
@ -73,28 +73,30 @@ module Vagrant
|
||||||
|
|
||||||
# First determine the proper array of VMs.
|
# First determine the proper array of VMs.
|
||||||
vms = []
|
vms = []
|
||||||
if name
|
if names.length > 0
|
||||||
raise Errors::MultiVMEnvironmentRequired if !@env.multivm?
|
names.each do |name|
|
||||||
|
raise Errors::MultiVMEnvironmentRequired if !@env.multivm?
|
||||||
|
|
||||||
if name =~ /^\/(.+?)\/$/
|
if name =~ /^\/(.+?)\/$/
|
||||||
# This is a regular expression name, so we convert to a regular
|
# This is a regular expression name, so we convert to a regular
|
||||||
# expression and allow that sort of matching.
|
# expression and allow that sort of matching.
|
||||||
regex = Regexp.new($1.to_s)
|
regex = Regexp.new($1.to_s)
|
||||||
|
|
||||||
@env.vms.each do |name, vm|
|
@env.vms.each do |name, vm|
|
||||||
vms << vm if name =~ regex
|
vms << vm if name =~ regex
|
||||||
|
end
|
||||||
|
|
||||||
|
raise Errors::VMNoMatchError if vms.empty?
|
||||||
|
else
|
||||||
|
# String name, just look for a specific VM
|
||||||
|
vms << @env.vms[name.to_sym]
|
||||||
|
raise Errors::VMNotFoundError, :name => name if !vms[0]
|
||||||
end
|
end
|
||||||
|
|
||||||
raise Errors::VMNoMatchError if vms.empty?
|
|
||||||
else
|
|
||||||
# String name, just look for a specific VM
|
|
||||||
vms << @env.vms[name.to_sym]
|
|
||||||
raise Errors::VMNotFoundError, :name => name if !vms[0]
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
vms = @env.vms_ordered
|
vms = @env.vms_ordered
|
||||||
end
|
end
|
||||||
|
|
||||||
# Make sure we're only working with one VM if single target
|
# Make sure we're only working with one VM if single target
|
||||||
raise Errors::MultiVMTargetRequired if options[:single_target] && vms.length != 1
|
raise Errors::MultiVMTargetRequired if options[:single_target] && vms.length != 1
|
||||||
|
|
||||||
|
|
|
@ -20,7 +20,7 @@ module Vagrant
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
@logger.debug("'Destroy' each target VM...")
|
@logger.debug("'Destroy' each target VM...")
|
||||||
with_target_vms(argv[0], :reverse => true) do |vm|
|
with_target_vms(argv, :reverse => true) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
# Boolean whether we should actually go through with the destroy
|
# Boolean whether we should actually go through with the destroy
|
||||||
# or not. This is true only if the "--force" flag is set or if the
|
# or not. This is true only if the "--force" flag is set or if the
|
||||||
|
|
|
@ -21,7 +21,7 @@ module Vagrant
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
@logger.debug("Halt command: #{argv.inspect} #{options.inspect}")
|
@logger.debug("Halt command: #{argv.inspect} #{options.inspect}")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
@logger.info("Halting #{vm.name}")
|
@logger.info("Halting #{vm.name}")
|
||||||
vm.halt(:force => options[:force])
|
vm.halt(:force => options[:force])
|
||||||
|
|
|
@ -54,7 +54,7 @@ module Vagrant
|
||||||
end
|
end
|
||||||
|
|
||||||
def package_target(name, options)
|
def package_target(name, options)
|
||||||
with_target_vms(name, :single_target => true) do |vm|
|
with_target_vms([ name ], :single_target => true) do |vm|
|
||||||
raise Errors::VMNotCreatedError if !vm.created?
|
raise Errors::VMNotCreatedError if !vm.created?
|
||||||
@logger.debug("Packaging VM: #{vm.name}")
|
@logger.debug("Packaging VM: #{vm.name}")
|
||||||
package_vm(vm, options)
|
package_vm(vm, options)
|
||||||
|
|
|
@ -16,7 +16,8 @@ module Vagrant
|
||||||
|
|
||||||
# Go over each VM and provision!
|
# Go over each VM and provision!
|
||||||
@logger.debug("'provision' each target VM...")
|
@logger.debug("'provision' each target VM...")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
if vm.state == :running
|
if vm.state == :running
|
||||||
@logger.info("Provisioning: #{vm.name}")
|
@logger.info("Provisioning: #{vm.name}")
|
||||||
|
|
|
@ -9,7 +9,8 @@ module Vagrant
|
||||||
|
|
||||||
def execute
|
def execute
|
||||||
options = {}
|
options = {}
|
||||||
opts = OptionParser.new do |opts|
|
|
||||||
|
opts = OptionParser.new do |opts|
|
||||||
opts.banner = "Usage: vagrant reload [vm-name]"
|
opts.banner = "Usage: vagrant reload [vm-name]"
|
||||||
opts.separator ""
|
opts.separator ""
|
||||||
build_start_options(opts, options)
|
build_start_options(opts, options)
|
||||||
|
@ -20,7 +21,7 @@ module Vagrant
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
@logger.debug("'reload' each target VM...")
|
@logger.debug("'reload' each target VM...")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
@logger.info("Reloading: #{vm.name}")
|
@logger.info("Reloading: #{vm.name}")
|
||||||
vm.reload(options)
|
vm.reload(options)
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Vagrant
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
@logger.debug("'resume' each target VM...")
|
@logger.debug("'resume' each target VM...")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
@logger.info("Resume: #{vm.name}")
|
@logger.info("Resume: #{vm.name}")
|
||||||
vm.resume
|
vm.resume
|
||||||
|
|
|
@ -36,7 +36,7 @@ module Vagrant
|
||||||
argv = [] if argv == ssh_args
|
argv = [] if argv == ssh_args
|
||||||
|
|
||||||
# Execute the actual SSH
|
# Execute the actual SSH
|
||||||
with_target_vms(argv[0], :single_target => true) do |vm|
|
with_target_vms(argv, :single_target => true) do |vm|
|
||||||
# Basic checks that are required for proper SSH
|
# Basic checks that are required for proper SSH
|
||||||
raise Errors::VMNotCreatedError if !vm.created?
|
raise Errors::VMNotCreatedError if !vm.created?
|
||||||
raise Errors::VMInaccessible if !vm.state == :inaccessible
|
raise Errors::VMInaccessible if !vm.state == :inaccessible
|
||||||
|
|
|
@ -23,7 +23,7 @@ module Vagrant
|
||||||
argv = parse_options(opts)
|
argv = parse_options(opts)
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
with_target_vms(argv[0], :single_target => true) do |vm|
|
with_target_vms(argv, :single_target => true) do |vm|
|
||||||
raise Errors::VMNotCreatedError if !vm.created?
|
raise Errors::VMNotCreatedError if !vm.created?
|
||||||
raise Errors::VMInaccessible if !vm.state == :inaccessible
|
raise Errors::VMInaccessible if !vm.state == :inaccessible
|
||||||
|
|
||||||
|
|
|
@ -16,7 +16,7 @@ module Vagrant
|
||||||
|
|
||||||
state = nil
|
state = nil
|
||||||
results = []
|
results = []
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
state = vm.state.to_s if !state
|
state = vm.state.to_s if !state
|
||||||
results << "#{vm.name.to_s.ljust(25)}#{vm.state.to_s.gsub("_", " ")}"
|
results << "#{vm.name.to_s.ljust(25)}#{vm.state.to_s.gsub("_", " ")}"
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,7 +15,7 @@ module Vagrant
|
||||||
return if !argv
|
return if !argv
|
||||||
|
|
||||||
@logger.debug("'suspend' each target VM...")
|
@logger.debug("'suspend' each target VM...")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
@logger.info("Suspending: #{vm.name}")
|
@logger.info("Suspending: #{vm.name}")
|
||||||
vm.suspend
|
vm.suspend
|
||||||
|
|
|
@ -21,7 +21,7 @@ module Vagrant
|
||||||
|
|
||||||
# Go over each VM and bring it up
|
# Go over each VM and bring it up
|
||||||
@logger.debug("'Up' each target VM...")
|
@logger.debug("'Up' each target VM...")
|
||||||
with_target_vms(argv[0]) do |vm|
|
with_target_vms(argv) do |vm|
|
||||||
if vm.created?
|
if vm.created?
|
||||||
@logger.info("Booting: #{vm.name}")
|
@logger.info("Booting: #{vm.name}")
|
||||||
vm.ui.info I18n.t("vagrant.commands.up.vm_created")
|
vm.ui.info I18n.t("vagrant.commands.up.vm_created")
|
||||||
|
|
Loading…
Reference in New Issue