Module: Vagrant::Util::GuestHosts::Unix
Constant Summary collapse
- DEAFAULT_LOOPBACK_CHECK_LIMIT =
5.freeze
Instance Method Summary collapse
-
#add_hostname_to_loopback_interface(comm, name, loop_bound = DEAFAULT_LOOPBACK_CHECK_LIMIT) ⇒ Object
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.
Instance Method Details
#add_hostname_to_loopback_interface(comm, name, loop_bound = DEAFAULT_LOOPBACK_CHECK_LIMIT) ⇒ Object
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
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# 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 " grep -w '\#{name}' /etc/hosts || {\n for i in \#{[*1..loop_bound].join(' ')}; do\n grep -w \"127.0.${i}.1\" /etc/hosts || {\n echo \"127.0.${i}.1 \#{name} \#{basename}\" >> /etc/hosts\n break\n }\n done\n }\n EOH\nend\n".gsub(/^ {14}/, '') |