Class: VagrantPlugins::ProviderVeertu::Action::PrepareForwardedPortCollisionParams

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ PrepareForwardedPortCollisionParams

Returns a new instance of PrepareForwardedPortCollisionParams.



5
6
7
# File 'lib/vagrant-veertu/action/prepare_forwarded_port_collision_params.rb', line 5

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

Instance Method Details

#call(env) ⇒ Object



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

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[:machine].provider.driver.read_used_ports

  # Build the remap for any existing collision detections
  remap = {}
  env[:port_collision_remap] = remap
  env[:machine].provider.driver.read_forwarded_ports.each do |_nic, name, hostport, _guestport|
    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] == name
        remap[options[:host]] = hostport
        break
      end
    end
  end

  @app.call(env)
end