Class: Landrush::Action::RedirectDns
- Inherits:
-
Object
- Object
- Landrush::Action::RedirectDns
- Includes:
- Common
- Defined in:
- lib/landrush/action/redirect_dns.rb
Constant Summary
Constants included from Common
Instance Method Summary collapse
-
#_gateway_for_ip(ip) ⇒ Object
Poor man’s gateway; strip the last octet and jam a 1 on there.
- #_target_host ⇒ Object
- #call(env) ⇒ Object
- #redirect_dns ⇒ Object
Methods included from Common
#config, #docker?, #enabled?, #guest_redirect_dns?, 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.
37 38 39 |
# File 'lib/landrush/action/redirect_dns.rb', line 37 def _gateway_for_ip(ip) ip.split('.').tap(&:pop).push(1).join('.') end |
#_target_host ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# 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) ⇒ Object
6 7 8 9 10 11 12 13 |
# 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 |