Module: Yast::Wicked
- Included in:
- Y2Network::Wicked::HostnameReader, Y2Network::Wicked::InterfacesReader, 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
- WICKED_PATH =
"/usr/sbin/wicked".freeze
Instance Method Summary collapse
-
#firmware_configured_by?(interface) ⇒ Symbol?
Returns the firmware extension used for configuring the given interface or nil when it is not configured by firmware.
-
#firmware_interfaces ⇒ Array <String>
Returns an array of interface names which are configured via firmware.
-
#firmware_interfaces_by_extension ⇒ Hash
Returns a hash with each firmware extension as the key and the specific extension configured interfaces as an array value.
-
#ibft_interfaces ⇒ Array <String>
Returns an array of interface names which are configured using iBFT.
-
#parse_hostname(iface) ⇒ String
Parses wicked runtime configuration and returns hostname if set.
-
#parse_ntp_servers(iface) ⇒ Array<String>
Parses wicked runtime configuration and returns list of ntp servers.
-
#query_wicked(iface, query) ⇒ String
Parses wicked runtime dhcp lease file for the given query.
-
#reload_config(devs) ⇒ Boolean
Reloads configuration for each device named in devs.
Instance Method Details
#firmware_configured_by?(interface) ⇒ Symbol?
Returns the firmware extension used for configuring the given interface or nil when it is not configured by firmware
119 120 121 |
# File 'src/lib/network/wicked.rb', line 119 def firmware_configured_by?(interface) firmware_interfaces_by_extension.find { |_, v| v.include?(interface) }&.first end |
#firmware_interfaces ⇒ Array <String>
Returns an array of interface names which are configured via firmware
93 94 95 96 |
# File 'src/lib/network/wicked.rb', line 93 def firmware_interfaces interfaces = firmware_interfaces_by_extension.values.flatten (ibft_interfaces + interfaces).uniq end |
#firmware_interfaces_by_extension ⇒ Hash
Returns a hash with each firmware extension as the key and the specific extension configured interfaces as an array value
105 106 107 108 109 110 111 112 113 |
# File 'src/lib/network/wicked.rb', line 105 def firmware_interfaces_by_extension return @firmware_interfaces_by_extension if @firmware_interfaces_by_extension output = Yast::Execute.stdout.locally!(WICKED_PATH, "firmware", "interfaces") @firmware_interfaces_by_extension = output.split("\n").each_with_object({}) do |line, result| firmware, *interfaces = line.split(/\s+/) result[firmware.to_sym] = result.fetch(firmware.to_sym, []) + interfaces if firmware end end |
#ibft_interfaces ⇒ Array <String>
Returns an array of interface names which are configured using iBFT
86 87 88 |
# File 'src/lib/network/wicked.rb', line 86 def ibft_interfaces @ibft_interfaces ||= Yast::Execute.stdout.locally!(IBFT_CMD, "-l").split(/\s+/).uniq end |
#parse_hostname(iface) ⇒ String
Parses wicked runtime configuration and returns hostname if set
54 55 56 57 58 |
# File 'src/lib/network/wicked.rb', line 54 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
46 47 48 |
# File 'src/lib/network/wicked.rb', line 46 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.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'src/lib/network/wicked.rb', line 67 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
35 36 37 38 39 40 |
# File 'src/lib/network/wicked.rb', line 35 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 |