Error if forwarded port with same host port is declared multiple times

This commit is contained in:
Mitchell Hashimoto 2013-03-15 22:11:49 -07:00
parent f03175b4af
commit 6e7427ca4d
3 changed files with 16 additions and 0 deletions

View File

@ -4,6 +4,8 @@ IMPROVEMENTS:
- Don't load plugins on any `vagrant plugin` command, so that errors
are avoided. [GH-1418]
- An error will be shown if you forward a port to the same host port
multiple times.
BUG FIXES:

View File

@ -1,5 +1,6 @@
require "pathname"
require "securerandom"
require "set"
require "vagrant"
require "vagrant/config/v2/util"
@ -277,12 +278,23 @@ module VagrantPlugins
# Validate networks
has_fp_port_error = false
fp_host_ports = Set.new
networks.each do |type, options|
if type == :forwarded_port
if !has_fp_port_error && (!options[:guest] || !options[:host])
errors << I18n.t("vagrant.config.vm.network_fp_requires_ports")
has_fp_port_error = true
end
if options[:host]
if fp_host_ports.include?(options[:host])
errors << I18n.t("vagrant.config.vm.network_fp_host_not_unique",
:host => options[:host].to_s)
end
fp_host_ports.add(options[:host])
end
end
end

View File

@ -456,6 +456,8 @@ en:
nfs_requires_host: |-
Using NFS shared folders requires a host to be specified
using `config.vagrant.host`.
network_fp_host_not_unique: |-
Forwarded port '%{host}' (host port) is declared multiple times
network_fp_requires_ports: |-
Forwarded port definitions require a "host" and "guest" value
shared_folder_hostpath_missing: |-