Sha256: 8c077ab3042fa3bf8185f03ea985123d13433cece94d7218d15139c12d390910

Contents?: true

Size: 855 Bytes

Versions: 10

Compression:

Stored size: 855 Bytes

Contents

require File.join(File.dirname(__FILE__), 'forward_ports_helpers')

module Vagrant
  class Action
    module VM
      class ClearForwardedPorts
        include ForwardPortsHelpers

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

        def call(env)
          @env = env
          clear
          @app.call(env)
        end

        def clear
          if used_ports.length > 0
            @env.logger.info "Deleting any previously set forwarded ports..."
            clear_ports
            @env["vm"].reload!
          end
        end

        # Deletes existing forwarded ports.
        def clear_ports
          @env["vm"].vm.network_adapters.each do |na|
            na.nat_driver.forwarded_ports.dup.each do |fp|
              fp.destroy
            end
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
vagrantup-0.5.4 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrantup-0.5.3 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrantup-0.5.2 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrantup-0.5.1 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrantup-0.5.0 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrant-0.5.4 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrant-0.5.3 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrant-0.5.2 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrant-0.5.1 lib/vagrant/action/vm/clear_forwarded_ports.rb
vagrant-0.5.0 lib/vagrant/action/vm/clear_forwarded_ports.rb