Module: Installation::DhcpNtpServers

Included in:
MicroOSRoleDialog
Defined in:
src/lib/installation/dhcp_ntp_servers.rb

Overview

This module provides a functionality for reading the NTP servers

Instance Method Summary collapse

Instance Method Details

#dhcp_ntp_serversArray<String>

List of NTP servers from DHCP

Returns:

  • (Array<String>)

    List of servers (IP or host names), empty if not provided



30
31
32
33
34
# File 'src/lib/installation/dhcp_ntp_servers.rb', line 30

def dhcp_ntp_servers
  Yast.import "Lan"

  Yast::Lan.dhcp_ntp_servers
end

#ntp_fallbackArray<String>

The fallback servers for NTP configuration

Returns:

  • (Array<String>)

    the fallback servers, empty if disabled in control.xml



56
57
58
59
60
61
62
63
64
65
66
67
# File 'src/lib/installation/dhcp_ntp_servers.rb', line 56

def ntp_fallback
  Yast.import "ProductFeatures"
  require "y2network/ntp_server"

  # propose the fallback when enabled in control file
  return [] unless Yast::ProductFeatures.GetBooleanFeature("globals", "default_ntp_setup")

  default_servers = Y2Network::NtpServer.default_servers
  return [] if default_servers.empty?

  [default_servers.sample.hostname]
end

#ntp_serversArray<String>

Propose the NTP servers from the DHCP response, fallback to a random machine from the ntp.org pool if enabled in control.xml.

Returns:

  • (Array<String>)

    proposed NTP servers, empty if nothing suitable found



42
43
44
45
46
47
48
49
# File 'src/lib/installation/dhcp_ntp_servers.rb', line 42

def ntp_servers
  # TODO: use Yast::NtpClient.ntp_conf if configured
  # to better handle going back
  servers = dhcp_ntp_servers
  servers = ntp_fallback if servers.empty?

  servers
end