Check if a port is open prior to forwarding [GH-821]

This commit is contained in:
Mitchell Hashimoto 2012-03-23 10:31:27 -04:00
parent d08a65e7f7
commit c1445a0130
2 changed files with 7 additions and 1 deletions

View File

@ -13,6 +13,8 @@
- Chef-solo provisioner now supports encrypted data bags. [GH-816] - Chef-solo provisioner now supports encrypted data bags. [GH-816]
- Enable the NAT DNS proxy by default, allowing your DNS to continue - Enable the NAT DNS proxy by default, allowing your DNS to continue
working when you switch networks. [GH-834] working when you switch networks. [GH-834]
- Checking for port forwarding collisions also checks for other applications
that are potentially listening on that port as well. [GH-821]
## 1.0.1 (March 11, 2012) ## 1.0.1 (March 11, 2012)

View File

@ -1,9 +1,13 @@
require "vagrant/util/is_port_open"
module Vagrant module Vagrant
module Action module Action
module VM module VM
# Action that checks to make sure there are no forwarded port collisions, # Action that checks to make sure there are no forwarded port collisions,
# and raises an exception if there is. # and raises an exception if there is.
class CheckPortCollisions class CheckPortCollisions
include Util::IsPortOpen
def initialize(app, env) def initialize(app, env)
@app = app @app = app
end end
@ -29,7 +33,7 @@ module Vagrant
hostport = options[:hostport].to_i hostport = options[:hostport].to_i
hostport = current[options[:name]] if current.has_key?(options[:name]) hostport = current[options[:name]] if current.has_key?(options[:name])
if existing.include?(hostport) if existing.include?(hostport) || is_port_open?("localhost", hostport)
# We have a collision! Handle it # We have a collision! Handle it
send("handle_#{handler}".to_sym, options, existing) send("handle_#{handler}".to_sym, options, existing)
end end