core: nitpick the protocol forwarded port checking

This commit is contained in:
Mitchell Hashimoto 2013-08-28 16:32:47 -07:00
parent 44d65de076
commit 29aab20a9d
2 changed files with 9 additions and 5 deletions

View File

@ -156,6 +156,7 @@ module VagrantPlugins
# @param [Hash] options Options for the network.
def network(type, options=nil)
options ||= {}
options[:protocol] ||= "tcp"
if !options[:id]
default_id = nil
@ -163,7 +164,7 @@ module VagrantPlugins
if type == :forwarded_port
# For forwarded ports, set the default ID to the
# host port so that host ports overwrite each other.
default_id = options[:host].to_s + (options[:protocol] || "tcp").to_s
default_id = "#{options[:protocol]}#{options[:host]}"
end
options[:id] = default_id || SecureRandom.uuid
@ -383,7 +384,7 @@ module VagrantPlugins
# Validate networks
has_fp_port_error = false
fp_host_ports_and_protocol = Set.new
fp_used = Set.new
valid_network_types = [:forwarded_port, :private_network, :public_network]
networks.each do |type, options|
@ -399,12 +400,14 @@ module VagrantPlugins
end
if options[:host]
if fp_host_ports_and_protocol.include?(options[:host].to_s + (options[:protocol] || "tcp").to_s)
key = "#{options[:protocol]}#{options[:host]}"
if fp_used.include?(key)
errors << I18n.t("vagrant.config.vm.network_fp_host_not_unique",
:host => options[:host].to_s + (options[:protocol] || "tcp").to_s)
:host => options[:host].to_s,
:protocol => options[:protocol].to_s)
end
fp_host_ports_and_protocol.add(options[:host].to_s + (options[:protocol] || "tcp").to_s)
fp_used.add(key)
end
end

View File

@ -661,6 +661,7 @@ en:
An IP is required for a private network.
network_fp_host_not_unique: |-
Forwarded port '%{host}' (host port) is declared multiple times
with the protocol '%{protocol}'.
network_fp_requires_ports: |-
Forwarded port definitions require a "host" and "guest" value
network_type_invalid: |-