Sha256: 7cd8f25a0dcd10690e1d2c9b32da85f6a683fbdfb35c0c882bca09e76c4a4375

Contents?: true

Size: 912 Bytes

Versions: 1

Compression:

Stored size: 912 Bytes

Contents

module Landrush
  module Action
    class RedirectDns
      include Common

      def call(env)
        handle_action_stack(env) do
          redirect_dns if enabled?
        end
      end

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

        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 then
          _gateway_for_ip(@machine.guest.capability(:configured_dns_server))
        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-0.6.0 lib/landrush/action/redirect_dns.rb