Class: Vagrant::Action::Builtin::HandleForwardedPortCollisions
- Inherits:
-
Object
- Object
- Vagrant::Action::Builtin::HandleForwardedPortCollisions
- Includes:
- Util::IPv4Interfaces, Util::IsPortOpen
- Defined in:
- lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb
Overview
This middleware class will detect and handle collisions with forwarded ports, whether that means raising an error or repairing them automatically.
Parameters it takes from the environment hash:
:port_collision_repair
- If true, it will attempt to repair port collisions. If false, it will raise an exception when there is a collision.:port_collision_extra_in_use
- An array of ports that are considered in use.:port_collision_remap
- A hash remapping certain host ports to other host ports.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ HandleForwardedPortCollisions
constructor
A new instance of HandleForwardedPortCollisions.
- #recover(env) ⇒ Object
Methods included from Util::IPv4Interfaces
Methods included from Util::IsPortOpen
Constructor Details
#initialize(app, env) ⇒ HandleForwardedPortCollisions
Returns a new instance of HandleForwardedPortCollisions.
34 35 36 37 |
# File 'lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb', line 34 def initialize(app, env) @app = app @logger = Log4r::Logger.new("vagrant::action::builtin::handle_port_collisions") end |
Instance Method Details
#call(env) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb', line 39 def call(env) @leased = [] @machine = env[:machine] # Acquire a process-level lock so that we don't choose a port # that someone else also chose. begin env[:machine].env.lock("fpcollision") do handle(env) end rescue Errors::EnvironmentLockedError sleep 1 retry end @app.call(env) # Always run the recover method so that we release leases recover(env) end |
#recover(env) ⇒ Object
60 61 62 |
# File 'lib/vagrant/action/builtin/handle_forwarded_port_collisions.rb', line 60 def recover(env) lease_release end |