Skip to content

Commit

Permalink
Changes based on CR.
Browse files Browse the repository at this point in the history
  • Loading branch information
teclator committed Sep 7, 2021
1 parent 465f45e commit 22bc81b
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/lib/y2network/ntp_server.rb
Expand Up @@ -22,6 +22,7 @@
require "yast2/equatable"

Yast.import "Product"
Yast.import "ProductFeatures"

module Y2Network
# Represents an NTP server
Expand Down Expand Up @@ -49,14 +50,30 @@ class << self

# Determines the default servers
#
# The content of this list depends on the base product.
# It reads the default NTP servers from the control file, in case of not defined
# the content of this list will depend on the base product.
#
# @param products [Array<Hash>] List of base products
# @return [Array<NtpServer>] Default NTP servers
def default_servers(products = nil)
(control_servers || product_servers(products)).map { |s| new(s) }
servers = control_servers

if servers
log.info "Using the servers defined in the control file: #{servers.inspect}"
else
servers = product_servers(products)
log.info "Using the NTP product servers: #{servers.inspect}"
end

servers.map { |s| new(s) }
end

private

# It returns a list of NTP servers based on the base products list.
#
# @param products [Array<Hash>] List of base products
# @return [Array<NtpServer>] Default NTP servers
def product_servers(products)
base_products = products || Yast::Product.FindBaseProducts

Expand All @@ -67,16 +84,14 @@ def product_servers(products)
"suse"
end

log.info "Using the '#{host}' NTP product servers"

(0..DEFAULT_SERVERS - 1).map { |i| "#{i}.#{host}.#{DEFAULT_SUBDOMAIN}" }
end

# Convenience method to fetch the default NTP servers from the control file
#
# @return [Array<NtpServer>] Default NTP servers
def control_servers
Yast.import "ProductFeatures"
servers = Yast::ProductFeatures.GetSection("globals")["default_ntp_servers"]
log.info "Using the servers defined in the control file: #{servers.inspect}" if servers
servers
Yast::ProductFeatures.GetSection("globals")["default_ntp_servers"]
end
end

Expand Down

0 comments on commit 22bc81b

Please sign in to comment.