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.



6
7
8
# File 'lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb', line 6

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

Instance Method Details

#call(env) ⇒ Object

This logic is based on the VirtualBox provider



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb', line 11

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