Sha256: febf3a7960bf16379be0f8259517868e029c38991b24e9ef817cc9fb97e29168

Contents?: true

Size: 1.36 KB

Versions: 10

Compression:

Stored size: 1.36 KB

Contents

module Vagrant
  module Actions
    module VM
      class ForwardPorts < Base
        def prepare
          VirtualBox::VM.all.each do |vm|
            next if !vm.running? || vm.uuid == @runner.uuid

            vm.forwarded_ports.each do |fp|
              @runner.env.config.vm.forwarded_ports.each do |name, options|
                if fp.hostport.to_s == options[:hostport].to_s
                  raise ActionException.new(:vm_port_collision, :name => name, :hostport => fp.hostport.to_s, :guestport => options[:guestport].to_s)
                end
              end
            end
          end
        end

        def execute!
          clear
          forward_ports
        end

        def clear
          logger.info "Deleting any previously set forwarded ports..."
          @runner.vm.forwarded_ports.collect { |p| p.destroy }
        end

        def forward_ports
          logger.info "Forwarding ports..."

          @runner.env.config.vm.forwarded_ports.each do |name, options|
            logger.info "Forwarding \"#{name}\": #{options[:guestport]} => #{options[:hostport]}"
            port = VirtualBox::ForwardedPort.new
            port.name = name
            port.hostport = options[:hostport]
            port.guestport = options[:guestport]
            @runner.vm.forwarded_ports << port
          end

          @runner.vm.save
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
vagrantup-0.3.4 lib/vagrant/actions/vm/forward_ports.rb
vagrantup-0.3.3 lib/vagrant/actions/vm/forward_ports.rb
vagrantup-0.3.2 lib/vagrant/actions/vm/forward_ports.rb
vagrantup-0.3.1 lib/vagrant/actions/vm/forward_ports.rb
vagrantup-0.3.0 lib/vagrant/actions/vm/forward_ports.rb
vagrant-0.3.4 lib/vagrant/actions/vm/forward_ports.rb
vagrant-0.3.3 lib/vagrant/actions/vm/forward_ports.rb
vagrant-0.3.2 lib/vagrant/actions/vm/forward_ports.rb
vagrant-0.3.1 lib/vagrant/actions/vm/forward_ports.rb
vagrant-0.3.0 lib/vagrant/actions/vm/forward_ports.rb