Class: Landrush::Action::RedirectDns

Inherits:
Object
  • Object
show all
Includes:
Common
Defined in:
lib/landrush/action/redirect_dns.rb

Constant Summary

Constants included from Common

Common::SUPPORTED_PROVIDERS

Instance Method Summary collapse

Methods included from Common

#config, #enabled?, #guest_redirect_dns?, #handle_action_stack, included, #info, #initialize, #libvirt?, #log, #machine, #machine_hostname, #parallels?, #provider, #read_machine_hostname, #virtualbox?, #vmware?

Instance Method Details

#_gateway_for_ip(ip) ⇒ Object

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



36
37
38
# File 'lib/landrush/action/redirect_dns.rb', line 36

def _gateway_for_ip(ip)
  ip.split('.').tap(&:pop).push(1).join('.')
end

#_target_hostObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/landrush/action/redirect_dns.rb', line 24

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

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/landrush/action/redirect_dns.rb', line 6

def call(env)
  handle_action_stack(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_dnsObject



15
16
17
18
19
20
21
22
# File 'lib/landrush/action/redirect_dns.rb', line 15

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