Module: Yast::Wicked

Included in:
Y2Network::Wicked::HostnameReader, LanClass, 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")
IBFT_CMD =
"/etc/wicked/extensions/ibft".freeze

Instance Method Summary collapse

Instance Method Details

#ibft_interfacesArray <String>

Returns an array of interface names which are configured using iBFT

Returns:

  • (Array <String>)

    array of interface names



85
86
87
# File 'src/lib/network/wicked.rb', line 85

def ibft_interfaces
  Yast::Execute.stdout.locally!(IBFT_CMD, "-l").gsub("\n", " ").split(" ").uniq
end

#parse_hostname(iface) ⇒ String

Parses wicked runtime configuration and returns hostname if set

Parameters:

  • iface (String)

    network device

Returns:

  • (String)

    hostname



53
54
55
56
57
# File 'src/lib/network/wicked.rb', line 53

def parse_hostname(iface)
  result = query_wicked(iface, "//hostname")
  # If there is more than one just pick the first one
  result.first
end

#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



45
46
47
# File 'src/lib/network/wicked.rb', line 45

def parse_ntp_servers(iface)
  query_wicked(iface, "//ntp/server")
end

#query_wicked(iface, query) ⇒ String

Parses wicked runtime dhcp lease file for the given query

It parses both ipv4 and ipv6 lease files at once.

Parameters:

  • iface (String)

    queried interface

  • query (String)

    xpath query. See man wicked for info what is supported there.

Returns:

  • (String)

    result of the query

Raises:

  • (ArgumentError)


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'src/lib/network/wicked.rb', line 66

def query_wicked(iface, query)
  Yast.import "NetworkService"
  raise ArgumentError, "A network device has to be specified" if iface.nil? || iface.empty?
  raise "Parsing 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} \"%{#{query}}\""
    )

    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)


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

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