class Landrush::Action::RedirectDns

Public Instance Methods

_gateway_for_ip(ip) click to toggle source

Poor man's gateway; strip the last octet and jam a 1 on there.

# File lib/landrush/action/redirect_dns.rb, line 37
def _gateway_for_ip(ip)
  ip.split('.').tap(&:pop).push(1).join('.')
end
_target_host() click to toggle source
# File lib/landrush/action/redirect_dns.rb, line 22
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)
  else
    # As a fallthrough default use the first non loopback IP. This IP should be reachable from the guest as well
    Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
  end
end
call(env) click to toggle source
# File lib/landrush/action/redirect_dns.rb, line 6
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
redirect_dns() click to toggle source
# File lib/landrush/action/redirect_dns.rb, line 15
def redirect_dns
  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