module Vagrant::Util::GuestHosts::Unix
Constants
- DEAFAULT_LOOPBACK_CHECK_LIMIT
Public Instance Methods
add_hostname_to_loopback_interface(comm, name, loop_bound=DEAFAULT_LOOPBACK_CHECK_LIMIT)
click to toggle source
Add hostname to a loopback address on /etc/hosts if not already there Will insert name at the first free address of the form 127.0.X.1, up to the loop_bound
@param [Communicator] @param [String] full hostanme @param [int] (option) defines the upper bound for searching for an available loopback address
# File lib/vagrant/util/guest_hosts.rb, line 16 def add_hostname_to_loopback_interface(comm, name, loop_bound=DEAFAULT_LOOPBACK_CHECK_LIMIT) basename = name.split(".", 2)[0] comm.sudo <<-EOH.gsub(/^ {14}/, '') grep -w '#{name}' /etc/hosts || { for i in #{[*1..loop_bound].join(' ')}; do grep -w "127.0.${i}.1" /etc/hosts || { echo "127.0.${i}.1 #{name} #{basename}" >> /etc/hosts break } done } EOH end