Skip to content

Commit

Permalink
Do not lose host alias when changing ip. bnc#709176
Browse files Browse the repository at this point in the history
  • Loading branch information
mchf committed Nov 26, 2018
1 parent 7ff5b20 commit a7fdb60
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/include/network/lan/address.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1608,10 +1608,20 @@ def update_hostname(ipaddr, hostname)

return if !(ip_changed || hostname_changed || hostname.empty?)

log.info("Dropping record for #{LanItems.ipaddr} from /etc/hosts")

# store old names, remove the record
names = Host.names(LanItems.ipaddr).first
Host.remove_ip(LanItems.ipaddr)
Host.Update(initial_hostname, hostname, ipaddr) if !hostname.empty?

if ip_changed && !hostname_changed
log.info("Dropping record for #{LanItems.ipaddr} from /etc/hosts")

Host.add_name(ipaddr, names)
end
if !hostname.empty? && hostname_changed
log.info("Updating cannonical name for #{LanItems.ipaddr} in /etc/hosts")

Host.Update(initial_hostname, hostname, ipaddr)
end

nil
end
Expand Down

0 comments on commit a7fdb60

Please sign in to comment.