Sha256: 1026b0c9a62d3e1c2c536d66ad8e478f1a246295e25373917b4458d070f6ca10

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 KB

Contents

module Landrush
  module Action
    class RedirectDns
      include Common

      def call(env)
        app.call(env)

        # This is after the middleware stack returns, which, since we're right
        # before the Network action, should mean that all interfaces are good
        # to go.
        redirect_dns if enabled? && guest_redirect_dns?
      end

      def redirect_dns
        info "setting up machine's DNS to point to our server"
        machine.guest.capability(:redirect_dns, host: _target_host, port: Server.port)

        machine.config.vm.networks.each do |type, options|
          info "network: #{type.inspect}, #{options.inspect}"
        end
      end

      def _target_host
        case provider
        when :virtualbox then
          '10.0.2.2'
        when :vmware_fusion, :libvirt then
          _gateway_for_ip(machine.guest.capability(:configured_dns_servers).first)
        when :parallels then
          machine.provider.capability(:host_address)
        end
      end

      # Poor man's gateway; strip the last octet and jam a 1 on there.
      def _gateway_for_ip(ip)
        ip.split('.').tap(&:pop).push(1).join('.')
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
landrush-1.2.0 lib/landrush/action/redirect_dns.rb