Skip to content

Commit

Permalink
use better names for some API calls (thanks @mvidner)
Browse files Browse the repository at this point in the history
  • Loading branch information
jreidinger committed Oct 13, 2016
1 parent c460b5b commit 43ebe40
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/lib/cfa/hosts.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand All @@ -86,10 +86,10 @@ def delete_host(ip)
# @param [String] canonical
# @param [Array<String>] 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

Expand All @@ -114,7 +114,7 @@ def set_host(ip, canonical, aliases = [])
# @param [String] canonical
# @param [Array<String>] 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
Expand Down
18 changes: 9 additions & 9 deletions src/modules/Host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 43ebe40

Please sign in to comment.