Module: Yast::Wicked

Included in:
LanItemsClass, NetworkAutoconfiguration
Defined in:
src/lib/network/wicked.rb

Constant Summary collapse

BASH_PATH =
Path.new(".target.bash")
BASH_OUTPUT_PATH =
Path.new(".target.bash_output")

Instance Method Summary collapse

Instance Method Details

#parse_ntp_servers(iface) ⇒ Array<String>

Parses wicked runtime configuration and returns list of ntp servers

Parameters:

  • iface (String)

    network device

Returns:

  • (Array<String>)

    list of NTP servers

Raises:

  • (ArgumentError)

43
44
45
46
47
48
49
50
51
52
53
# File 'src/lib/network/wicked.rb', line 43

def parse_ntp_servers(iface)
  raise ArgumentError, "A network device has to be specified" if iface.nil? || iface.empty?
  raise "Parsing NTP Servers not supported for network service in use" if !NetworkService.is_wicked

  lease_files = ["ipv4", "ipv6"].map { |ip| "/var/lib/wicked/lease-#{iface}-dhcp-#{ip}.xml" }
  lease_files.find_all { |f| File.file?(f) }.reduce([]) do |stack, file|
    result = SCR.Execute(BASH_OUTPUT_PATH, "/usr/sbin/wicked xpath --file #{file.shellescape} \"%{//ntp/server}\"")

    stack + result.fetch("stdout", "").split("\n")
  end
end

#reload_config(devs) ⇒ Boolean

Reloads configuration for each device named in devs

Parameters:

  • devs (Array)

    list of device names

Returns:

  • (Boolean)

    true if configuration was reloaded; false otherwise

Raises:

  • (ArgumentError)

32
33
34
35
36
37
# File 'src/lib/network/wicked.rb', line 32

def reload_config(devs)
  raise ArgumentError if devs.nil?
  return true if devs.empty?

  SCR.Execute(BASH_PATH, "/usr/sbin/wicked ifreload #{devs.map(&:shellescape).join(" ")}").zero?
end