Class: Yast::LanItemsClass

Inherits:
Module
  • Object
show all
Includes:
Logger, Wicked
Defined in:
src/modules/LanItems.rb

Overview

FIXME: well this class really is not nice

Constant Summary

Constants included from Wicked

Wicked::BASH_OUTPUT_PATH, Wicked::BASH_PATH

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Wicked

#parse_ntp_servers, #reload_config

Class Method Details

.publish_variable(name, type) ⇒ Object

This helper allows YARD to extract DSL-defined attributes. Unfortunately YARD has problems with the Capitalized ones, so those must be done manually.


739
740
741
# File 'src/modules/LanItems.rb', line 739

def self.publish_variable(name, type)
  publish variable: name, type: type
end

Instance Method Details

#add_device_to_routing(name = current_name) ⇒ Object

TODO:

This method exists just to keep some compatibility during the migration to network-ng.

Adds a new interface with the given name


747
748
749
750
751
752
# File 'src/modules/LanItems.rb', line 747

def add_device_to_routing(name = current_name)
  config = yast_config
  return if config.nil?
  return if config.interfaces.any? { |i| i.name == name }
  yast_config.interfaces << Y2Network::Interface.new(name)
end

#Commit(builder) ⇒ Object

Commit pending operation

It commits only content of the corresponding ifcfg into NetworkInterfaces. All other stuff which is managed by LanItems (like udev's, ...) is handled elsewhere


496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
# File 'src/modules/LanItems.rb', line 496

def Commit(builder)
  log.info "committing builder #{builder.inspect}"
  builder.save # does all modification, later only things that is not yet converted

  # TODO: still needed?
  if DriverType(builder.type.short_name) == "ctc"
    if Ops.get(NetworkConfig.Config, "WAIT_FOR_INTERFACES").nil? ||
        Ops.less_than(
          Ops.get_integer(NetworkConfig.Config, "WAIT_FOR_INTERFACES", 0),
          40
        )
      Ops.set(NetworkConfig.Config, "WAIT_FOR_INTERFACES", 40)
    end
  end

  true
end

#createS390Device(dev_attrs = {}) ⇒ Object

Creates eth emulation for s390 devices

If it contains s390 device attributes definition, then these definitions takes precendence over values assigned to corresponding LanItems' global variables before the method invocation. Hash keys are strings named after LanItems' s390 globals.


532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
# File 'src/modules/LanItems.rb', line 532

def createS390Device(dev_attrs = {})
  Builtins.y2milestone("creating device s390 network device, #{dev_attrs}")

  # FIXME: leftover from dropping LanUdevAuto module. This was its way how to
  # configure s390 specific globals. When running in "normal" mode these attributes
  # are initialized elsewhere (see S390Dialog in include/network/lan/hardware.rb)
  if !dev_attrs.empty?
    Select("")
    @type = dev_attrs["type"] || ""
    @qeth_chanids = dev_attrs["chanids"] || ""
    @qeth_layer2 = dev_attrs.fetch("layer2", false)
    @chan_mode = dev_attrs["protocol"] || ""
    @iucv_user = dev_attrs["router"] || ""
  end

  result = true
  # command to create device
  command1 = ""
  # command to find created device
  command2 = ""
  case @type
  when "hsi", "qeth"
    @portnumber_param = if Ops.greater_than(Builtins.size(@qeth_portnumber), 0)
      Builtins.sformat("-n %1", @qeth_portnumber.to_s.shellescape)
    else
      ""
    end
    @options_param = if Ops.greater_than(Builtins.size(@qeth_options), 0)
      Builtins.sformat("-o %1", @qeth_options.shellescape)
    else
      ""
    end
    command1 = Builtins.sformat(
      "/sbin/qeth_configure %1 %2 %3 %4 %5 1",
      @options_param,
      @qeth_layer2 ? "-l" : "",
      @portnumber_param,
      @qeth_chanids
    )
    command2 = Builtins.sformat(
      "/usr/bin/ls /sys/devices/qeth/%1/net/ | /usr/bin/head -n1 | /usr/bin/tr -d '\n'",
      Ops.get(Builtins.splitstring(@qeth_chanids, " "), 0, "")
    )
  when "ctc"
    # chan_ids (read, write), protocol
    command1 = Builtins.sformat(
      "/sbin/ctc_configure %1 1 %2",
      @qeth_chanids,
      @chan_mode.shellescape
    )
    command2 = Builtins.sformat(
      "/usr/bin/ls /sys/devices/ctcm/%1/net/ | /usr/bin/head -n1 | /usr/bin/tr -d '\n'",
      Ops.get(Builtins.splitstring(@qeth_chanids, " "), 0, "").shellescape
    )
  when "lcs"
    # chan_ids (read, write), protocol
    command1 = Builtins.sformat(
      "/sbin/ctc_configure %1 1 %2",
      @qeth_chanids,
      @chan_mode.shellescape
    )
    command2 = Builtins.sformat(
      "/usr/bin/ls /sys/devices/lcs/%1/net/ | /usr/bin/head -n1 | /usr/bin/tr -d '\n'",
      Ops.get(Builtins.splitstring(@qeth_chanids, " "), 0, "").shellescape
    )
  when "iucv"
    # router
    command1 = Builtins.sformat("/sbin/iucv_configure %1 1", @iucv_user.shellescape)
    command2 = Builtins.sformat(
      "/usr/bin/ls /sys/devices/%1/*/net/ | /usr/bin/head -n1 | /usr/bin/tr -d '\n'",
      @type.shellescape
    )
  else
    Builtins.y2error("Unsupported type : %1", @type)
  end
  Builtins.y2milestone("execute %1", command1)
  output1 = SCR.Execute(path(".target.bash_output"), command1)
  if Ops.get_integer(output1, "exit", -1) == 0 &&
      Builtins.size(Ops.get_string(output1, "stderr", "")) == 0
    Builtins.y2milestone("Success : %1", output1)
  else
    Builtins.y2error("Problem occured : %1", output1)
    result = false
  end
  Builtins.y2milestone("output1 %1", output1)

  if result
    Builtins.y2milestone("command2 %1", command2)
    output2 = Convert.convert(
      SCR.Execute(path(".target.bash_output"), command2),
      from: "any",
      to:   "map <string, any>"
    )
    Builtins.y2milestone("output2 %1", output2)
    if Ops.get_integer(output2, "exit", -1) == 0 &&
        Builtins.size(Ops.get_string(output2, "stderr", "")) == 0
      Ops.set(
        @Items,
        [@current, "ifcfg"],
        Ops.get_string(output2, "stdout", "")
      )
      Ops.set(
        @Items,
        [@current, "hwinfo", "dev_name"],
        Ops.get_string(output2, "stdout", "")
      )
      Builtins.y2milestone(
        "Device %1 created",
        Ops.get_string(output2, "stdout", "")
      )
    else
      Builtins.y2error("Some problem occured : %1", output2)
      result = false
    end
  end

  result
end

#createUdevFromIfaceName(interfaces) ⇒ Object

Creates a list of udev rules for old style named interfaces

It takes a whole "interfaces" section of AY profile and produces a list of udev rules to guarantee device naming persistency. The rule is base on attributes described in old style name

@param [Array] list of hashes describing interfaces in AY profile @return [Array] list of hashes for udev rules


659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
# File 'src/modules/LanItems.rb', line 659

def createUdevFromIfaceName(interfaces)
  return [] if !interfaces || interfaces.empty?

  udev_rules = []
  attr_map = {
    "id"  => "ATTR{address}",
    "bus" => "KERNELS"
  }

  # rubocop:disable Next
  # the check is disabled bcs the code uses capture groups. Rewriting
  # the code would require some tricks to access these groups
  interfaces.each do |interface|
    if /.*-(?<attr>id|bus)-(?<value>.*)/ =~ interface["device"]
      udev_rules << {
        "rule"  => attr_map[attr],
        "value" => value,
        "name"  => getDeviceName(interface["device"])
      }
    end
  end
  # rubocop:enable Next

  log.info("converted interfaces: #{interfaces}")

  udev_rules
end

#current_device_namesObject

Return the current device names

@ return [Array]


174
175
176
# File 'src/modules/LanItems.rb', line 174

def current_device_names
  GetNetcardInterfaces().map { |i| current_name_for(i) }.reject(&:empty?)
end

#current_nameString

Return the actual name of the current Yast::LanItems


167
168
169
# File 'src/modules/LanItems.rb', line 167

def current_name
  current_name_for(@current)
end

#dhcp?(devmap) ⇒ Boolean

Checks whether given device configuration is set to use a dhcp bootproto

ideally should replace @see isCurrentDHCP


480
481
482
483
484
# File 'src/modules/LanItems.rb', line 480

def dhcp?(devmap)
  return false unless devmap["BOOTPROTO"]

  Y2Network::BootProtocol.from_name(devmap["BOOTPROTO"]).dhcp?
end

#dhcp_ntp_serversHash<String, Array<String>] key is device name, value is list of ntp servers obtained from the device

Returns hash of NTP servers

Provides map with NTP servers obtained via any of dhcp aware interfaces


726
727
728
729
730
731
# File 'src/modules/LanItems.rb', line 726

def dhcp_ntp_servers
  dhcp_ifaces = find_dhcp_ifaces

  result = dhcp_ifaces.map { |iface| [iface, parse_ntp_servers(iface)] }.to_h
  result.delete_if { |_, ntps| ntps.empty? }
end

#find_configured(device) ⇒ Object

Finds item_id by device name

If an item is associated with config file of given name (ifcfg-) then its id is returned


330
331
332
# File 'src/modules/LanItems.rb', line 330

def find_configured(device)
  @Items.select { |_k, v| v["ifcfg"] == device }.keys.first
end

#find_dhcp_ifacesArray<String>

Finds all NICs configured with DHCP


266
267
268
# File 'src/modules/LanItems.rb', line 266

def find_dhcp_ifaces
  find_by_sysconfig { |ifcfg| dhcp?(ifcfg) }
end

#find_set_hostname_ifacesArray<String>

Finds all devices which has DHCLIENT_SET_HOSTNAME set to "yes"


282
283
284
285
286
# File 'src/modules/LanItems.rb', line 282

def find_set_hostname_ifaces
  find_by_sysconfig do |ifcfg|
    ifcfg["DHCLIENT_SET_HOSTNAME"] == "yes"
  end
end

#find_static_ifacesArray<String>

Find all NICs configured statically


273
274
275
276
277
# File 'src/modules/LanItems.rb', line 273

def find_static_ifaces
  find_by_sysconfig do |ifcfg|
    ifcfg.fetch("BOOTPROTO", "").match(/static/i)
  end
end

#find_type_ifaces(type) ⇒ Array

Finds all items of given device type


255
256
257
258
259
260
261
# File 'src/modules/LanItems.rb', line 255

def find_type_ifaces(type)
  items = GetNetcardInterfaces().select do |iface|
    GetDeviceType(iface) == type
  end

  GetDeviceNames(items)
end

#getCurrentItemObject

Returns configuration for currently modified item.


124
125
126
# File 'src/modules/LanItems.rb', line 124

def getCurrentItem
  GetLanItem(@current)
end

#GetCurrentMapObject


194
195
196
# File 'src/modules/LanItems.rb', line 194

def GetCurrentMap
  GetDeviceMap(@current)
end

#GetDeviceMap(itemId) ⇒ Object

Returns ifcfg configuration for particular item


188
189
190
191
192
# File 'src/modules/LanItems.rb', line 188

def GetDeviceMap(itemId)
  return nil if !IsItemConfigured(itemId)

  NetworkInterfaces.devmap(GetDeviceName(itemId))
end

#GetDeviceName(item_id) ⇒ Object

Returns device name for given lan item.

First it looks into the item's netconfig and if it doesn't exist it uses device name from hwinfo if available.


145
146
147
148
149
150
151
152
153
# File 'src/modules/LanItems.rb', line 145

def GetDeviceName(item_id)
  lan_item = GetLanItem(item_id)

  return lan_item["ifcfg"] if lan_item["ifcfg"]
  return lan_item["hwinfo"]["dev_name"] || "" if lan_item["hwinfo"]

  log.error("Item #{item_id} has no dev_name nor configuration associated")
  "" # this should never happen
end

#getDeviceName(oldname) ⇒ String

It finds a new style device name for device name in old fashioned format

It goes through currently present devices and tries to mach it to given old fashioned name


340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
# File 'src/modules/LanItems.rb', line 340

def getDeviceName(oldname)
  newname = oldname

  hardware = ReadHardware("netcard")

  hardware.each do |hw|
    hw_dev_name = hw["dev_name"] || ""
    hw_dev_mac = hw["permanent_mac"] || hw["mac"] || ""
    hw_dev_busid = hw["busid"] || ""

    case oldname
    when /.*-id-#{hw_dev_mac}/i
      log.info("device by ID found: #{oldname}")
      newname = hw_dev_name
    when /.*-bus-#{hw_dev_busid}/i
      log.info("device by BUS found #{oldname}")
      newname = hw_dev_name
    end
  end

  log.info("nothing changed, #{newname} is old style dev_name") if oldname == newname

  newname
end

#GetDeviceNames(items) ⇒ Object

transforms given list of item ids onto device names

item id is index into internal @Items structure


158
159
160
161
162
# File 'src/modules/LanItems.rb', line 158

def GetDeviceNames(items)
  return [] unless items

  items.map { |itemId| GetDeviceName(itemId) }.reject(&:empty?)
end

#GetDeviceType(itemId) ⇒ Object

Returns device type for particular lan item


181
182
183
# File 'src/modules/LanItems.rb', line 181

def GetDeviceType(itemId)
  NetworkInterfaces.GetType(GetDeviceName(itemId))
end

#GetLanItem(itemId) ⇒ Object

Returns configuration of item (see LanItems::Items) with given id.


119
120
121
# File 'src/modules/LanItems.rb', line 119

def GetLanItem(itemId)
  Items()[itemId] || {}
end

#GetModifiedBoolean

Function which returns if the settings were modified


226
227
228
# File 'src/modules/LanItems.rb', line 226

def GetModified
  @modified
end

#GetNetcardInterfacesObject

Creates list of all known netcard items

It means list of item ids of all netcards which are detected and/or configured in the system


242
243
244
# File 'src/modules/LanItems.rb', line 242

def GetNetcardInterfaces
  Items().keys
end

#GetNetcardNamesObject

Creates list of names of all known netcards configured even unconfigured


247
248
249
# File 'src/modules/LanItems.rb', line 247

def GetNetcardNames
  GetDeviceNames(GetNetcardInterfaces())
end

#getNetworkInterfaces(type = nil) ⇒ Object

Get list of all configured interfaces

return [Array] list of strings - interface names (eth0, ...) FIXME: rename e.g. to configured_interfaces


313
314
315
316
317
318
319
320
321
# File 'src/modules/LanItems.rb', line 313

def getNetworkInterfaces(type = nil)
  configurations = NetworkInterfaces.FilterDevices("netcard")
  devtypes = type ? [type] : NetworkInterfaces.CardRegex["netcard"].to_s.split("|")

  devtypes.inject([]) do |acc, conf_type|
    conf = configurations[conf_type].to_h
    acc.concat(conf.keys)
  end
end

#Import(settings) ⇒ Boolean

Imports data from AY profile

As network related configuration is spread over the whole AY profile's networking section the function requires hash map with whole AY profile hash representation as returned by LanAutoClient#FromAY profile.


394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
# File 'src/modules/LanItems.rb', line 394

def Import(settings)
  reset_cache

  @autoinstall_settings["start_immediately"] = settings.fetch("start_immediately", false)
  @autoinstall_settings["strict_IP_check_timeout"] = settings.fetch("strict_IP_check_timeout", -1)
  @autoinstall_settings["keep_install_network"] = settings.fetch("keep_install_network", true)

  # FIXME: createS390Device does two things, it
  # - updates internal structures
  # - creates s390 device eth emulation
  # So, it belongs partly into Import and partly into Write. Note, that
  # the code is currently unable to revert already created emulated device.
  NetworkAutoYast.instance.activate_s390_devices(settings.fetch("s390-devices", {})) if Arch.s390

  # settings == {} has special meaning 'Reset' used by AY
  SetModified() if !settings.empty?

  true
end

#invalid_dhcp_cfgsArray

Creates a list of config files which contain corrupted DHCLIENT_SET_HOSTNAME setup


291
292
293
294
295
296
297
298
299
# File 'src/modules/LanItems.rb', line 291

def invalid_dhcp_cfgs
  devs = LanItems.find_set_hostname_ifaces
  dev_ifcfgs = devs.map { |d| "ifcfg-#{d}" }

  return dev_ifcfgs if devs.size > 1
  return dev_ifcfgs << "dhcp" if !devs.empty? && DNS.dhcp_hostname

  []
end

#ip_overview(dev_map) ⇒ Array

Creates details for device's overview based on ip configuration type

Produces list of strings. Strings are intended for "bullet" list, e.g.:


433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
# File 'src/modules/LanItems.rb', line 433

def ip_overview(dev_map)
  bullets = []

  ip = DeviceProtocol(dev_map)

  if ip =~ /DHCP/
    bullets << format("%s %s", _("IP address assigned using"), ip)
  elsif IP.Check(ip)
    prefixlen = dev_map["PREFIXLEN"] || ""
    if !prefixlen.empty?
      bullets << format(_("IP address: %s/%s"), ip, prefixlen)
    else
      subnetmask = dev_map["NETMASK"]
      bullets << format(_("IP address: %s, subnet mask %s"), ip, subnetmask)
    end
  end

  # build aliases overview
  item_aliases = dev_map["_aliases"] || {}
  if !item_aliases.empty? && !NetworkService.is_network_manager
    item_aliases.each do |_key2, desc|
      parameters = format("%s/%s", desc["IPADDR"], desc["PREFIXLEN"])
      bullets << format("%s (%s)", desc["LABEL"], parameters)
    end
  end

  bullets
end

#isCurrentDHCPObject

Check if currently edited device gets its IP address from DHCP (v4, v6 or both)


471
472
473
474
475
# File 'src/modules/LanItems.rb', line 471

def isCurrentDHCP
  return false unless @bootproto

  Y2Network::BootProtocol.from_name(@bootproto).dhcp?
end

#isCurrentHotplugObject

Is current device hotplug or not? I.e. is connected via usb/pcmci?


463
464
465
466
# File 'src/modules/LanItems.rb', line 463

def isCurrentHotplug
  hotplugtype = Ops.get_string(getCurrentItem, ["hwinfo", "hotplug"], "")
  hotplugtype == "usb" || hotplugtype == "pcmci"
end

#IsItemConfigured(itemId) ⇒ Object

Returns true if the item (see LanItems::Items) has netconfig configuration.


132
133
134
135
136
137
# File 'src/modules/LanItems.rb', line 132

def IsItemConfigured(itemId)
  ret = !GetLanItem(itemId)["ifcfg"].to_s.empty?
  log.info("IsItemConfigured: item=#{itemId} configured=#{ret}")

  ret
end

#mainObject


42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'src/modules/LanItems.rb', line 42

def main
  textdomain "network"

  Yast.import "Arch"
  Yast.import "NetworkInterfaces"
  Yast.import "NetworkConfig"
  Yast.import "Directory"
  Yast.include self, "network/complex.rb"
  Yast.include self, "network/routines.rb"
  Yast.include self, "network/lan/s390.rb"

  reset_cache

  # Hardware information
  # @see #ReadHardware
  @Hardware = []
  @udev_net_rules = {}
  @driver_options = {}

  # used at autoinstallation time
  @autoinstall_settings = {}

  # Data was modified?
  # current selected HW
  @hw = {}

  # Which operation is pending?
  @operation = nil

  # in special cases when rcnetwork reload is not enought
  @force_restart = false

  @description = ""

  @type = ""
  # ifcfg name for the @current device
  @device = ""
  @current = -1
  @hotplug = ""

  @Requires = []

  # s390 options
  @qeth_portnumber = ""
  # * ctc as PROTOCOL (or ctc mode, number in { 0, 1, .., 4 }, default: 0)
  @chan_mode = "0"
  @qeth_options = ""
  @ipa_takeover = false
  # * iucv as ROUTER (or iucv user, a zVM guest, string of 1 to 8 chars )
  @iucv_user = ""
  # #84148
  # 26bdd00.pdf
  # Ch 7: qeth device driver for OSA-Express (QDIO) and HiperSockets
  # MAC address handling for IPv4 with the layer2 option
  @qeth_layer2 = false
  @qeth_macaddress = "00:00:00:00:00:00"
  @qeth_chanids = ""
  # Timeout for LCS LANCMD
  @lcs_timeout = "5"

  # aliases
  @aliases = {}

  # for TUN / TAP devices
  @tunnel_set_owner = ""
  @tunnel_set_group = ""

  Yast.include self, "network/hardware.rb"

  # this is the map of kernel modules vs. requested firmware
  # non-empty keys are firmware packages shipped by SUSE
  @request_firmware = YAML.load_file(Directory.find_data_file("network/firmwares.yml"))
end

#move_routes(from, to) ⇒ Object

Assigns all the routes from one interface to another


758
759
760
761
762
763
764
765
766
767
# File 'src/modules/LanItems.rb', line 758

def move_routes(from, to)
  config = yast_config
  return unless config && config.routing
  routing = config.routing
  add_device_to_routing(to)
  target_interface = config.interfaces.by_name(to)
  return unless target_interface
  routing.routes.select { |r| r.interface && r.interface.name == from }
         .each { |r| r.interface = target_interface }
end

#new_type_device(type) ⇒ String

Returns unused name for device of given type

When already having eth0, eth1, enp0s3 devices (eth type) and asks for new device of eth type it will e.g. return eth2 as a free name.

Method always returns name in the oldfashioned schema (eth0, br1, ...)

Raises:

  • (ArgumentError)

    when type is nil or empty


697
698
699
# File 'src/modules/LanItems.rb', line 697

def new_type_device(type)
  new_type_devices(type, 1).first
end

#new_type_devices(type, count) ⇒ Array<String>

Returns a list of unused names for devices of given type

Also @see new_type_device

Raises:

  • (ArgumentError)

    when type is nil or empty


709
710
711
712
713
714
715
716
717
718
# File 'src/modules/LanItems.rb', line 709

def new_type_devices(type, count)
  raise ArgumentError, "Valid device type expected" if type.nil? || type.empty?
  return [] if count < 1

  known_devs = find_type_ifaces(type)

  candidates = (0..known_devs.size + count - 1).map { |c| "#{type}#{c}" }

  (candidates - known_devs)[0..count - 1]
end

#ReadHwObject

preinitializates @Items according info on physically detected network cards


366
367
368
369
370
371
# File 'src/modules/LanItems.rb', line 366

def ReadHw
  @Items = {}
  @Hardware = ReadHardware("netcard")
  # Hardware = [$["active":true, "bus":"pci", "busid":"0000:02:00.0", "dev_name":"wlan0", "drivers":[$["active":true, "modprobe":true, "modules":[["ath5k" , ""]]]], "link":true, "mac":"00:22:43:37:55:c3", "modalias":"pci:v0000168Cd0000001Csv00001A3Bsd00001026bc02s c00i00", "module":"ath5k", "name":"AR242x 802.11abg Wireless PCI Express Adapter", "num":0, "options":"", "re quires":[], "sysfs_id":"/devices/pci0000:00/0000:00:1c.1/0000:02:00.0", "type":"wlan", "udi":"/org/freedeskto p/Hal/devices/pci_168c_1c", "wl_auth_modes":["open", "sharedkey", "wpa-psk", "wpa-eap"], "wl_bitrates":nil, " wl_channels":["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11"], "wl_enc_modes":["WEP40", "WEP104", "T KIP", "CCMP"]], $["active":true, "bus":"pci", "busid":"0000:01:00.0", "dev_name":"eth0", "drivers":[$["active ":true, "modprobe":true, "modules":[["atl1e", ""]]]], "link":false, "mac":"00:23:54:3f:7c:c3", "modalias":"pc i:v00001969d00001026sv00001043sd00008324bc02sc00i00", "module":"atl1e", "name":"L1 Gigabit Ethernet Adapter", "num":1, "options":"", "requires":[], "sysfs_id":"/devices/pci0000:00/0000:00:1c.3/0000:01:00.0", "type":"et h", "udi":"/org/freedesktop/Hal/devices/pci_1969_1026", "wl_auth_modes":nil, "wl_bitrates":nil, "wl_channels" :nil, "wl_enc_modes":nil]];
  nil
end

#reset_cacheObject

Clears internal cache of the module to default values

TODO: LanItems consists of several sets of internal variables. 1) cache of items describing network interface 2) variables used as a kind of iterator in the cache 3) variables which keeps (some of) attributes of the current item (= item which is being pointed by the iterator)


380
381
382
383
384
# File 'src/modules/LanItems.rb', line 380

def reset_cache
  LanItems.Items = {}

  @modified = false
end

#SetDeviceMap(item_id, devmap) ⇒ Object

Sets item's sysconfig device map to given one

It updates NetworkInterfaces according given map. Map is expected to be a hash where both key even value are strings


204
205
206
207
208
209
# File 'src/modules/LanItems.rb', line 204

def SetDeviceMap(item_id, devmap)
  devname = GetDeviceName(item_id)
  return false if devname.nil? || devname.empty?

  NetworkInterfaces.Change2(devname, devmap, false)
end

#SetItemObject


514
515
516
517
518
519
520
521
522
523
# File 'src/modules/LanItems.rb', line 514

def SetItem(*)
  @hotplug = ""
  Builtins.y2debug("type=%1", @type)
  if Builtins.issubstring(@type, "-")
    @type = Builtins.regexpsub(@type, "([^-]+)-.*$", "\\1")
  end
  Builtins.y2debug("type=%1", @type)

  nil
end

#SetItemSysconfigOpt(item_id, opt, value) ⇒ Object

Sets one option in items sysconfig device map

Currently no checks on sysconfig option validity are performed


216
217
218
219
220
221
222
# File 'src/modules/LanItems.rb', line 216

def SetItemSysconfigOpt(item_id, opt, value)
  devmap = GetDeviceMap(item_id)
  return false if devmap.nil?

  devmap[opt] = value
  SetDeviceMap(item_id, devmap)
end

#SetModifiedObject

Function sets internal variable, which indicates, that any settings were modified, to "true"


232
233
234
235
236
# File 'src/modules/LanItems.rb', line 232

def SetModified
  @modified = true

  nil
end

#summary(type) ⇒ String

Creates a summary of the configured items.

It supports differents types of summaries depending on the options[:type]


421
422
423
# File 'src/modules/LanItems.rb', line 421

def summary(type)
  LanItemsSummary.new.send(type)
end

#valid_dhcp_cfg?Boolean

Checks if system DHCLIENT_SET_HOSTNAME is valid


304
305
306
# File 'src/modules/LanItems.rb', line 304

def valid_dhcp_cfg?
  invalid_dhcp_cfgs.empty?
end