A regex string can be passed to commands in Multi-VM

This commit is contained in:
Mitchell Hashimoto 2011-12-26 18:12:02 -08:00
parent 8f522225a1
commit 4428daf344
4 changed files with 30 additions and 4 deletions

View File

@ -10,6 +10,9 @@
logging is silent.
- `system` renamed to `guest` throughout the source. Any `config.vm.system`
configurations must be changed to `config.vm.guest`
- All Vagrant commands that take a VM name in a Multi-VM environment
can now be given a regular expression. If the name starts and ends with a "/"
then it is assumed to be a regular expression. [GH-573]
- Removed Thor as a dependency for the command line interfaces. This resulted
in general speed increases across all command line commands.
- Linux uses `shutdown -h` instead of `halt` to hopefully more consistently

View File

@ -69,8 +69,22 @@ module Vagrant
vms = []
if name
raise Errors::MultiVMEnvironmentRequired if !@env.multivm?
vms << @env.vms[name.to_sym]
raise Errors::VMNotFoundError, :name => name if !vms[0]
if name =~ /^\/(.+?)\/$/
# This is a regular expression name, so we convert to a regular
# expression and allow that sort of matching.
regex = Regexp.new($1.to_s)
@env.vms.each do |name, vm|
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
else
vms = @env.vms_ordered
end

View File

@ -348,6 +348,11 @@ module Vagrant
error_key(:vm_inaccessible)
end
class VMNoMatchError < VagrantError
status_code(63)
error_key(:vm_no_match)
end
class VMNotCreatedError < VagrantError
status_code(6)
error_key(:vm_creation_required)

View File

@ -166,8 +166,12 @@ en:
with VirtualBox that Vagrant can not cleanly recover from. Please open VirtualBox
and clear out your inaccessible virtual machines or find a way to fix
them.
vm_not_found: "A VM by the name of %{name} was not found."
vm_not_running: "VM must be running to open SSH connection."
vm_no_match: |-
No virtual machines matched the regular expression given.
vm_not_found: |-
A VM by the name of %{name} was not found.
vm_not_running: |-
VM must be running to open SSH connection.
#-------------------------------------------------------------------------------
# Translations for config validation errors