From 43ebe40889d51b526c35219edffeb18f9f6814e5 Mon Sep 17 00:00:00 2001 From: Josef Reidinger Date: Thu, 13 Oct 2016 09:24:29 +0200 Subject: [PATCH] use better names for some API calls (thanks @mvidner) --- src/lib/cfa/hosts.rb | 8 ++++---- src/modules/Host.rb | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/cfa/hosts.rb b/src/lib/cfa/hosts.rb index 8ce989273..8bd8d3681 100644 --- a/src/lib/cfa/hosts.rb +++ b/src/lib/cfa/hosts.rb @@ -62,7 +62,7 @@ def host(ip) # deletes all occurences of given ip in host table # @return [void] - def delete_host(ip) + def delete_by_ip(ip) entries = data.select(ip_matcher(ip)) if entries.empty? log.info "no entry to delete for ip #{ip}" @@ -86,10 +86,10 @@ def delete_host(ip) # @param [String] canonical # @param [Array] aliases # @return [void] - def set_host(ip, canonical, aliases = []) + def set_entry(ip, canonical, aliases = []) entries = data.select(ip_matcher(ip)) if entries.empty? - add_host(ip, canonical, aliases) + add_entry(ip, canonical, aliases) return end @@ -114,7 +114,7 @@ def set_host(ip, canonical, aliases = []) # @param [String] canonical # @param [Array] aliases # @return [void] - def add_host(ip, canonical, aliases = []) + def add_entry(ip, canonical, aliases = []) log.info "adding new entry for ip #{ip}" entry_line = AugeasTree.new entry_line["ipaddr"] = ip diff --git a/src/modules/Host.rb b/src/modules/Host.rb index 41a62a7a3..b74172fd3 100644 --- a/src/modules/Host.rb +++ b/src/modules/Host.rb @@ -51,7 +51,7 @@ def main # Remove all entries from the host table. def clear @hosts.hosts.keys.each do |ip| - @hosts.delete_host(ip) + @hosts.delete_by_ip(ip) end @modified = true end @@ -68,14 +68,14 @@ def names(address) # remove all instances of ip in hosts table def remove_ip(address) - @hosts.delete_host(address) + @hosts.delete_by_ip(address) end # Add another name to the list for address (which may be empty so far) # FIXME: used only in one place, which looks wrong def add_name(address, name) canonical, *aliases = name.split(" ") - @hosts.add_host(address, canonical, aliases) + @hosts.add_entry(address, canonical, aliases) @modified = true end @@ -98,7 +98,7 @@ def EnsureHostnameResolvable # Do not add it if product default says no # and remove 127.0.02 entry if it exists - @hosts.delete_host(local_ip) + @hosts.delete_by_ip(local_ip) end @modified = true @@ -235,7 +235,7 @@ def Update(oldhn, newhn, ip) # Add localhost if missing if @hosts.host("127.0.0.1").empty? - @hosts.add_host("127.0.0.1", "localhost") + @hosts.add_entry("127.0.0.1", "localhost") end # Omit some IP addresses @@ -247,12 +247,12 @@ def Update(oldhn, newhn, ip) nick = nick.empty? ? [] : [nick] hosts = @hosts.host(ip) if hosts.empty? - @hosts.add_host(ip, newhn, nick) + @hosts.add_entry(ip, newhn, nick) else canonical, *aliases = hosts.last aliases << newhn aliases.concat(nick) - @hosts.set_host(ip, canonical, aliases) + @hosts.set_entry(ip, canonical, aliases) end true @@ -331,10 +331,10 @@ def SetModified # Give address a new list of names. def set_names(address, names) - @hosts.delete_host(address) + @hosts.delete_by_ip(address) names.each do |name| canonical, *aliases = name.split(" ") - @hosts.add_host(address, canonical, aliases) + @hosts.add_entry(address, canonical, aliases) end @modified = true end