Skip to content

Commit

Permalink
Stop using the deprecated GetNtpServers* methods
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Feb 19, 2020
1 parent a3e90c3 commit 90adda8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/clients/ntp-client_proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,12 @@ def configured_ntp_items
# @return [Array<Yast::Term>] ntp address Item
def timezone_ntp_items
timezone_country = Timezone.GetCountryForTimezone(Timezone.timezone)
NtpClient.GetNtpServersByCountry(timezone_country, true)
servers = NtpClient.country_ntp_servers(timezone_country)
# Select the first occurrence of pool.ntp.org as the default option (bnc#940881)
selected = servers.find { |s| s.end_with?("pool.ntp.org") }
servers.map do |server|
Item(Id(server.hostname), server.hostname, server.hostname == selected)
end
end

# List of dhcp ntp servers Yast::Term items with the ntp address ID and
Expand Down
15 changes: 11 additions & 4 deletions src/lib/y2ntp_client/widgets/pool_widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,15 @@ def help

private

# Returns the country for the given address
#
# FIXME: if the UI used a proper object instead of just a string, this
# method will not be needed.
#
# @param address [String] Server address
def country_for(address)
Yast::NtpClient.GetNtpServers.fetch(address, {})["country"]
server = Yast::NtpClient.public_ntp_servers.find { |s| s.hostname == address }
server ? server.country : nil
end
end

Expand Down Expand Up @@ -382,7 +389,7 @@ def label

# macro seeItemsSelection
def items
ntp_servers.map { |s, v| [s, "#{s} (#{v["country"]})"] }
ntp_servers.map { |s| [s.hostname, "#{s.hostname} (#{s.country})"] }
end

def refresh(country)
Expand All @@ -393,10 +400,10 @@ def refresh(country)
private

def ntp_servers
servers = Yast::NtpClient.GetNtpServers
servers = Yast::NtpClient.public_ntp_servers
return servers if @country.to_s.empty?

servers.find_all { |_s, v| v["country"] == @country }
servers.select { |s| s.country == @country }
end
end
end
Expand Down

0 comments on commit 90adda8

Please sign in to comment.