Class: VagrantPlugins::Skytap::Action::PrepareForwardedPortCollisionParams

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb

Overview

This is based on code from the VirtualBox provider.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PrepareForwardedPortCollisionParams

Returns a new instance of PrepareForwardedPortCollisionParams.



28
29
30
# File 'lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb', line 28

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb', line 32

def call(env)
  # Get the forwarded ports used by other virtual machines and
  # consider those in use as well.
  env[:port_collision_extra_in_use] = env[:host].capability(:read_used_ports, env[:machine])

  # Build the remap for any existing collision detections
  remap = {}
  env[:port_collision_remap] = remap
  env[:host].capability(:read_forwarded_ports, env[:machine]).each do |fp|
    env[:machine].config.vm.networks.each do |type, options|
      next if type != :forwarded_port

      # If the ID matches the name of the forwarded port, then
      # remap.
      if options[:id] == fp.id
        remap[options[:host]] = fp.host_port
        break
      end
    end
  end

  @app.call(env)
end