Skip to content

Commit

Permalink
improving hostnames detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Mte90 committed Aug 12, 2020
1 parent 8e4d86e commit 5b13461
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/vagrant-goodhosts/GoodHosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,11 @@ def addHostEntries
errorText = ""
cli = get_cli
hostnames_by_ips = generateHostnamesByIps
hostnames_by_ips.each do |hostnames, ip_address|
hostnames_by_ips.each do |ip_address, hostnames|
if ip_address.nil?
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
next
end
if cli.include? ".exe"
stdin, stdout, stderr, wait_thr = Open3.popen3(cli, "add", ip_address, hostnames)
else
Expand All @@ -117,8 +121,8 @@ def removeHostEntries
errorText = ""
cli = get_cli
hostnames_by_ips = generateHostnamesByIps
hostnames_by_ips.each do |hostnames, ip_address|
if !ip_address.nil?
hostnames_by_ips.each do |ip_address, hostnames|
if ip_address.nil?
@ui.error "[vagrant-goodhosts] Error adding some hosts, no IP was provided for the following hostnames: #{hostnames}"
next
end
Expand Down Expand Up @@ -158,7 +162,7 @@ def generateHostnamesByIps()
ip_address = ip
hostnames[ip].each do |hostname|
if !ip_address.nil?
@ui.info "[vagrant-goodhosts] - removing entry for: #{ip_address} #{hostname}"
@ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
end
end
hostnames_by_ips = { ip_address => hostnames[ip].join(" ") }
Expand All @@ -167,7 +171,7 @@ def generateHostnamesByIps()
ip_address = ips[0]
hostnames[ip_address].each do |hostname|
if !ip_address.nil?
@ui.info "[vagrant-goodhosts] - removing entry for: #{ip_address} #{hostname}"
@ui.info "[vagrant-goodhosts] - found entry for: #{ip_address} #{hostname}"
end
end
hostnames_by_ips = { ip_address => hostnames[ip_address].join(" ") }
Expand Down

0 comments on commit 5b13461

Please sign in to comment.