Sha256: b4df709c5a04088cd9abce00b0a9b32d7e1c81fb0fb08b5bd3ab0da12c271921

Contents?: true

Size: 1.15 KB

Versions: 4

Compression:

Stored size: 1.15 KB

Contents

module VagrantPlugins
  module Skytap
    module Action
      # This is based on code from the VirtualBox provider.
      class PrepareForwardedPortCollisionParams
        def initialize(app, env)
          @app = app
        end

        # This logic is based on the VirtualBox provider
        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
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
vagrant-skytap-0.2.3 lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb
vagrant-skytap-0.2.2 lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb
vagrant-skytap-0.2.1 lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb
vagrant-skytap-0.2.0 lib/vagrant-skytap/action/prepare_forwarded_port_collision_params.rb