From e64696e839bc83b3a13dcbb339b40fc1c2e52162 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 10 Apr 2013 15:37:04 -0700 Subject: [PATCH] Automatically override forwarded ports if host ports match --- CHANGELOG.md | 2 ++ plugins/kernel_v2/config/vm.rb | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f0c11e008..381ea92d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,8 @@ IMPROVEMENTS: - Shared folders with the same guest path will overwrite each other. No more shared folder IDs. - Shell provisioner outputs script it is running. [GH-1568] + - Automatically merge forwarded ports that share the same host + port. BUG FIXES: diff --git a/plugins/kernel_v2/config/vm.rb b/plugins/kernel_v2/config/vm.rb index 92600b874..96f25e6c2 100644 --- a/plugins/kernel_v2/config/vm.rb +++ b/plugins/kernel_v2/config/vm.rb @@ -133,9 +133,21 @@ module VagrantPlugins # @param [Hash] options Options for the network. def network(type, options=nil) options ||= {} - id = options[:id] || SecureRandom.uuid + + if !options[:id] + default_id = nil + + 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] + end + + options[:id] = default_id || SecureRandom.uuid + end # Scope the ID by type so that different types can share IDs + id = options[:id] id = "#{type}-#{id}" # Merge in the previous settings if we have them.