Class: Yast::LanClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/Lan.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) Add

Add a new device

Returns:

  • true if success



848
849
850
851
852
# File '../../src/modules/Lan.rb', line 848

def Add
  return false if LanItems.Select("") != true
  NetworkInterfaces.Add
  true
end

- (Object) AnyDHCPDevice

Create a configuration for autoyast Check if any device is configured with DHCP.

Returns:

  • true if something was proposed

  • true if any DHCP device is configured



1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
# File '../../src/modules/Lan.rb', line 1053

def AnyDHCPDevice
  # return true if there is at least one device with dhcp4, dhcp6, dhcp or dhcp+autoip
  Ops.greater_than(
    Builtins.size(
      Builtins.union(
        Builtins.union(
          NetworkInterfaces.Locate("BOOTPROTO", "dhcp4"),
          NetworkInterfaces.Locate("BOOTPROTO", "dhcp6")
        ),
        Builtins.union(
          NetworkInterfaces.Locate("BOOTPROTO", "dhcp"),
          NetworkInterfaces.Locate("BOOTPROTO", "dhcp+autoip")
        )
      )
    ),
    0
  )
end

- (Array) AutoPackages

mode

Returns:

  • (Array)

    of packages needed when writing the config in autoinst



1122
1123
1124
# File '../../src/modules/Lan.rb', line 1122

def AutoPackages
  { "install" => Packages(), "remove" => [] }
end

- (Object) Delete

Delete the given device

Parameters:

  • name

    device to delete

Returns:

  • true if success



857
858
859
860
# File '../../src/modules/Lan.rb', line 857

def Delete
  LanItems.DeleteItem
  true
end

- (Object) Export

Export data

Returns:

  • dumped settings (later acceptable by Import())



722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File '../../src/modules/Lan.rb', line 722

def Export
  devices = NetworkInterfaces.Export("")
  udev_rules = LanUdevAuto.Export(devices)
  ay = {
    "dns"                  => DNS.Export,
    # FIXME: MOD "modules"	: Modules,
    "s390-devices"         => Ops.get_map(
      udev_rules,
      "s390-devices",
      {}
    ),
    "net-udev"             => Ops.get_map(udev_rules, "net-udev", {}),
    "config"               => NetworkConfig.Export,
    "devices"              => devices,
    "ipv6"                 => @ipv6,
    "routing"              => Routing.Export,
    "managed"              => NetworkService.is_network_manager,
    "start_immediately"    => Ops.get_boolean(
      LanItems.autoinstall_settings,
      "start_immediately",
      false
    ), #start_immediately,
    "keep_install_network" => Ops.get_boolean(
      LanItems.autoinstall_settings,
      "keep_install_network",
      false
    )
  }
  Builtins.y2milestone("Exported map: %1", ay)
  deep_copy(ay)
end

- (Object) HaveXenBridge

Xen bridging confuses us (#178848)

Returns:

  • whether xenbr* exists



1128
1129
1130
1131
1132
1133
# File '../../src/modules/Lan.rb', line 1128

def HaveXenBridge
  #adapted test for xen bridged network (bnc#553794)
  have_br = FileUtils.Exists("/dev/.sysconfig/network/xenbridges")
  Builtins.y2milestone("Have Xen bridge: %1", have_br)
  have_br
end

- (Object) IfcfgsToSkipVirtualizedProposal



896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
# File '../../src/modules/Lan.rb', line 896

def IfcfgsToSkipVirtualizedProposal
  skipped = []
  Builtins.foreach(LanItems.Items) do |current, config|
    ifcfg = Ops.get_string(LanItems.Items, [current, "ifcfg"], "")
    if NetworkInterfaces.GetType(ifcfg) == "br"
      NetworkInterfaces.Edit(ifcfg)
      Builtins.y2milestone(
        "Bridge %1 with ports (%2) found",
        ifcfg,
        Ops.get_string(NetworkInterfaces.Current, "BRIDGE_PORTS", "")
      )
      skipped = Builtins.add(skipped, ifcfg)
      Builtins.foreach(
        Builtins.splitstring(
          Ops.get_string(NetworkInterfaces.Current, "BRIDGE_PORTS", ""),
          " "
        )
      ) { |port| skipped = Builtins.add(skipped, port) }
    end
    if NetworkInterfaces.GetType(ifcfg) == "bond"
      NetworkInterfaces.Edit(ifcfg)

      Builtins.foreach(LanItems.GetBondSlaves(ifcfg)) do |slave|
        Builtins.y2milestone(
          "For interface %1 found slave %2",
          ifcfg,
          slave
        )
        skipped = Builtins.add(skipped, slave)
      end
    end
    # Skip also usb device as it is not good for bridge proposal (bnc#710098)
    if NetworkInterfaces.GetType(ifcfg) == "usb"
      NetworkInterfaces.Edit(ifcfg)
      Builtins.y2milestone(
        "Usb device %1 skipped from bridge proposal",
        ifcfg
      )
      skipped = Builtins.add(skipped, ifcfg)
    end
    if NetworkInterfaces.GetValue(ifcfg, "STARTMODE") == "nfsroot"
      Builtins.y2milestone(
        "Skipped %1 interface from bridge slaves because of nfsroot.",
        ifcfg
      )
      skipped = Builtins.add(skipped, ifcfg)
    end
  end
  Builtins.y2milestone("Skipped interfaces : %1", skipped)
  deep_copy(skipped)
end

- (Object) Import(settings)

Import data

Parameters:

  • settings (Hash)

    settings to be imported

Returns:

  • true on success



674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
# File '../../src/modules/Lan.rb', line 674

def Import(settings)
  settings = deep_copy(settings)
  NetworkInterfaces.Import("netcard", Ops.get_map(settings, "devices", {}))
  Builtins.foreach(NetworkInterfaces.List("netcard")) do |device|
    LanItems.AddNew
    Ops.set(LanItems.Items, LanItems.current, { "ifcfg" => device })
  end

  Ops.set(
    LanItems.autoinstall_settings,
    "start_immediately",
    Ops.get_boolean(settings, "start_immediately", false)
  )
  Ops.set(
    LanItems.autoinstall_settings,
    "strict_IP_check_timeout",
    Ops.get_integer(settings, "strict_IP_check_timeout", -1)
  )
  Ops.set(
    LanItems.autoinstall_settings,
    "keep_install_network",
    Ops.get_boolean(settings, "keep_install_network", false)
  )

  NetworkConfig.Import(Ops.get_map(settings, "config", {}))
  DNS.Import(Builtins.eval(Ops.get_map(settings, "dns", {})))
  Routing.Import(Builtins.eval(Ops.get_map(settings, "routing", {})))

  if Ops.get_boolean(settings, "managed", false)
    if NetworkService.is_backend_available(:network_manager)
      NetworkService.use_network_manager
    else
      Report.Warning(_("AutoYaST setting networking/managed: NetworkManager is not available, Wicked will be used."))
      NetworkService.use_wicked
    end
  else
    NetworkService.use_wicked
  end
  if Builtins.haskey(settings, "ipv6")
    @ipv6 = Ops.get_boolean(settings, "ipv6", true)
  end

  LanItems.modified = true
  true
end

- (Object) isAnyInterfaceDown

function for use from autoinstallation (Fate #301032)



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File '../../src/modules/Lan.rb', line 107

def isAnyInterfaceDown
  down = false
  link_status = {}
  net_devices = Builtins.splitstring(
    Ops.get_string(
      Convert.convert(
        SCR.Execute(
          path(".target.bash_output"),
          "ls /sys/class/net/ | grep -v lo | tr '\n' ','"
        ),
        :from => "any",
        :to   => "map <string, any>"
      ),
      "stdout",
      ""
    ),
    ","
  )
  net_devices = Builtins.filter(net_devices) do |item|
    Ops.greater_than(Builtins.size(item), 0)
  end
  Builtins.foreach(net_devices) do |net_dev|
    row = Builtins.splitstring(
      Ops.get_string(
        Convert.convert(
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat(
              "ip address show dev %1 | grep 'inet\\|link' | sed 's/^ \\+//g'|cut -d' ' -f-2",
              net_dev
            )
          ),
          :from => "any",
          :to   => "map <string, any>"
        ),
        "stdout",
        ""
      ),
      "\n"
    )
    tmp_mac = ""
    addr = false
    Builtins.foreach(row) do |column|
      tmp_col = Builtins.splitstring(column, " ")
      next if Ops.less_than(Builtins.size(tmp_col), 2)
      if Builtins.issubstring(Ops.get(tmp_col, 0, ""), "link/ether")
        tmp_mac = Ops.get(tmp_col, 1, "")
      end
      if Builtins.issubstring(Ops.get(tmp_col, 0, ""), "inet") &&
          !Builtins.issubstring(Ops.get(tmp_col, 0, ""), "inet6")
        addr = true
      end
    end
    if Ops.greater_than(Builtins.size(tmp_mac), 0)
      Ops.set(link_status, tmp_mac, addr)
    end
    Builtins.y2debug("link_status %1", link_status)
  end

  Builtins.y2milestone("link_status %1", link_status)
  configurations = NetworkInterfaces.FilterDevices("")
  Builtins.foreach(
    Builtins.splitstring(
      Ops.get(NetworkInterfaces.CardRegex, "netcard", ""),
      "|"
    )
  ) do |devtype|
    Builtins.foreach(
      Convert.convert(
        Map.Keys(Ops.get_map(configurations, devtype, {})),
        :from => "list",
        :to   => "list <string>"
      )
    ) do |devname|
      mac = Ops.get_string(
        Convert.convert(
          SCR.Execute(
            path(".target.bash_output"),
            Builtins.sformat(
              "cat /sys/class/net/%1/address|tr -d '\n'",
              devname
            )
          ),
          :from => "any",
          :to   => "map <string, any>"
        ),
        "stdout",
        ""
      )
      Builtins.y2milestone("confname %1", mac)
      if !Builtins.haskey(link_status, mac)
        Builtins.y2error(
          "Mac address %1 not found in map %2!",
          mac,
          link_status
        )
      elsif Ops.get_boolean(link_status, mac, false) == false
        Builtins.y2warning("Interface with mac %1 is down!", mac)
        down = true
      else
        Builtins.y2debug("Interface with mac %1 is up", mac)
      end
    end
  end
  down
end

- (Object) main



37
38
39
40
41
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
# File '../../src/modules/Lan.rb', line 37

def main
  Yast.import "UI"
  textdomain "network"

  Yast.import "Arch"
  Yast.import "DNS"
  Yast.import "NetHwDetection"
  Yast.import "Host"
  Yast.import "IP"
  Yast.import "Map"
  Yast.import "Mode"
  Yast.import "NetworkConfig"
  Yast.import "NetworkInterfaces"
  Yast.import "NetworkService"
  Yast.import "Package"
  Yast.import "ProductFeatures"
  Yast.import "Routing"
  Yast.import "Progress"
  Yast.import "String"
  Yast.import "SuSEFirewall4Network"
  Yast.import "FileUtils"
  Yast.import "PackageSystem"
  Yast.import "LanItems"
  Yast.import "ModuleLoading"
  Yast.import "Linuxrc"
  Yast.import "LanUdevAuto"
  Yast.import "Report"

  Yast.include self, "network/complex.rb"
  Yast.include self, "network/runtime.rb"
  Yast.include self, "network/lan/bridge.rb"

  #-------------
  # GLOBAL DATA

  # gui or cli mode
  @gui = true

  @write_only = false

  # ipv6 module
  @ipv6 = true

  # Hotplug type ("" if not hot pluggable)

  # Abort function
  # return boolean return true if abort
  @AbortFunction = nil

  # list of interface names which were recently assigned as a slave to a bond device
  @bond_autoconf_slaves = []

  # Lan::Read (`cache) will do nothing if initialized already.
  @initialized = false
end

- (Object) Modified

Return a modification status

Returns:

  • true if data was modified



99
100
101
102
103
104
# File '../../src/modules/Lan.rb', line 99

def Modified
  ret = LanItems.GetModified || DNS.modified || Routing.Modified ||
    NetworkConfig.Modified ||
    NetworkService.Modified
  ret
end

- (Array) Packages

Returns of packages needed when writing the config

Returns:

  • (Array)

    of packages needed when writing the config



1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
# File '../../src/modules/Lan.rb', line 1073

def Packages
  # various device types require some special packages ...
  type_requires =  {
    # for wlan require iw instead of wireless-tools (bnc#539669)
    "wlan" => "iw",
    "vlan" => "vlan",
    "br"   => "bridge-utils",
    "tun"  => "tunctl",
    "tap"  => "tunctl"
  }
  # ... and some options require special packages as well
  option_requires =  {
    "WIRELESS_AUTH_MODE" => {
      "psk" => "wpa_supplicant",
      "eap" => "wpa_supplicant"
    }
  }

  pkgs = []
  type_requires.each do |type, package|
    ifaces = NetworkInterfaces.List(type)
    if !ifaces.empty?
      Builtins.y2milestone(
        "Network interface type #{type} requires package #{package}"
      )
      pkgs << package if !PackageSystem.Installed(package)
    end
  end

  option_requires.each do |option, option_values|
    option_values.each do |value, package|
      if NetworkInterfaces.Locate(option, value) != []
        Builtins.y2milestone(
          "Network interface with option #{option}=#{value} requires package #{package}",
        )
        pkgs << package if !PackageSystem.Installed(package)
      end
    end
  end

  if NetworkService.is_network_manager
    pkgs << "NetworkManager" if !PackageSystem.Installed("NetworkManager")
  end

  pkgs
end

- (Object) ProposeVirtualized



948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
# File '../../src/modules/Lan.rb', line 948

def ProposeVirtualized
  # in case of virtualization use special proposal
  # collect all interfaces that will be skipped from bridged proposal
  skipped = IfcfgsToSkipVirtualizedProposal()

  # first configure all connected unconfigured devices with dhcp (with default parameters)
  Builtins.foreach(LanItems.Items) do |number, lanitem|
    if IsNotEmpty(
        Ops.get_string(Convert.to_map(lanitem), ["hwinfo", "dev_name"], "")
      )
      LanItems.current = number
      valid = Ops.get_boolean(
        LanItems.getCurrentItem,
        ["hwinfo", "link"],
        false
      ) == true
      if !valid
        Builtins.y2warning("item number %1 has link:false detected", number)
      else
        if Ops.get_string(LanItems.getCurrentItem, ["hwinfo", "type"], "") == "wlan"
          Builtins.y2warning("not proposing WLAN interface")
          valid = false
        end
      end
      if !LanItems.IsCurrentConfigured && valid &&
          !Builtins.contains(
            skipped,
            Ops.get_string(
              LanItems.getCurrentItem,
              ["hwinfo", "dev_name"],
              ""
            )
          )
        Builtins.y2milestone("Not configured - start proposing")
        LanItems.ProposeItem
      end
    end
  end

  # then each configuration (except bridges) move to the bridge
  # and add old device name into bridge_ports
  Builtins.foreach(LanItems.Items) do |current, config|
    ifcfg = Ops.get_string(LanItems.Items, [current, "ifcfg"], "")
    if Builtins.contains(skipped, ifcfg)
      Builtins.y2milestone("Skipping interface %1", ifcfg)
      next
    elsif Ops.greater_than(Builtins.size(ifcfg), 0)
      NetworkInterfaces.Edit(ifcfg)
      old_config = deep_copy(NetworkInterfaces.Current)
      Builtins.y2debug("Old Config %1\n%2", ifcfg, old_config)
      new_ifcfg = Builtins.sformat(
        "br%1",
        NetworkInterfaces.GetFreeDevice("br")
      )
      Builtins.y2milestone(
        "old configuration %1, bridge %2",
        ifcfg,
        new_ifcfg
      )
      NetworkInterfaces.Name = new_ifcfg
      # from bridge interface remove all bonding-related stuff
      Builtins.foreach(NetworkInterfaces.Current) do |key, value|
        if Builtins.issubstring(key, "BONDING")
          Ops.set(NetworkInterfaces.Current, key, nil)
        end
      end
      Ops.set(NetworkInterfaces.Current, "BRIDGE", "yes")
      Ops.set(NetworkInterfaces.Current, "BRIDGE_PORTS", ifcfg)
      Ops.set(NetworkInterfaces.Current, "BRIDGE_STP", "off")
      Ops.set(NetworkInterfaces.Current, "BRIDGE_FORWARDDELAY", "0")
      # hardcode startmode (bnc#450670), it can't be ifplugd!
      Ops.set(NetworkInterfaces.Current, "STARTMODE", "auto")
      # remove description - will be replaced by new (real) one
      NetworkInterfaces.Current = Builtins.remove(
        NetworkInterfaces.Current,
        "NAME"
      )
      # remove ETHTOOLS_OPTIONS as it is useful only for real hardware
      NetworkInterfaces.Current = Builtins.remove(
        NetworkInterfaces.Current,
        "ETHTOOLS_OPTIONS"
      )
      if NetworkInterfaces.Commit
        # reconfigure existing device as newly created bridge's port
        configure_as_bridge_port(ifcfg)

        Ops.set(LanItems.Items, [current, "ifcfg"], new_ifcfg)
        LanItems.modified = true
        LanItems.force_restart = true
        Builtins.y2internal("List %1", NetworkInterfaces.List(""))
        # re-read configuration to see new items in UI
        LanItems.Read
      end
    else
      Builtins.y2warning("empty ifcfg")
    end
  end

  nil
end

- (Object) Read(cache)

Read all network settings from the SCR

Parameters:

  • cache: (Symbol)

    cache=use cached data, nocache=reread from disk (for reproposal); TODO pass to submodules

Returns:

  • true on success



265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
# File '../../src/modules/Lan.rb', line 265

def Read(cache)
  if cache == :cache && @initialized
    Builtins.y2milestone("Using cached data")
    return true
  end

  # Read dialog caption
  caption = _("Initializing Network Configuration")
  steps = 9

  sl = 0 # 1000; /* TESTING
  Builtins.sleep(sl)

  if @gui
    Progress.New(
      caption,
      " ",
      steps,
      [
        # Progress stage 1/9
        _("Detect network devices"),
        # Progress stage 2/9
        _("Read driver information"),
        # Progress stage 3/9 - multiple devices may be present, really plural
        _("Read device configuration"),
        # Progress stage 4/9
        _("Read network configuration"),
        # Progress stage 5/9
        _("Read firewall settings"),
        # Progress stage 6/9
        _("Read hostname and DNS configuration"),
        # Progress stage 7/9
        _("Read installation information"),
        # Progress stage 8/9
        _("Read routing configuration"),
        # Progress stage 9/9
        _("Detect current status")
      ],
      [],
      ""
    )
  end

  return false if Abort()

  # check the environment
  #    if(!Confirm::MustBeRoot()) return false;

  return false if Abort()
  # Progress step 1/9
  ProgressNextStage(_("Detecting ndiswrapper...")) if @gui
  # modprobe ndiswrapper before hwinfo when needed (#343893)
  if !Mode.autoinst && PackageSystem.Installed("ndiswrapper")
    Builtins.y2milestone("ndiswrapper: installed")
    if Ops.greater_than(
        Builtins.size(
          Convert.convert(
            SCR.Read(path(".target.dir"), "/etc/ndiswrapper"),
            :from => "any",
            :to   => "list <string>"
          )
        ),
        0
      )
      Builtins.y2milestone("ndiswrapper: configuration found")
      if Convert.to_integer(
          SCR.Execute(path(".target.bash"), "lsmod |grep -q ndiswrapper")
        ) != 0 &&
          Popup.YesNo(
            _(
              "Detected a ndiswrapper configuration,\n" +
                "but the kernel module was not modprobed.\n" +
                "Do you want to modprobe ndiswrapper?\n"
            )
          )
        if ModuleLoading.Load("ndiswrapper", "", "", "", false, true) == :fail
          Popup.Error(
            _(
              "ndiswrapper kernel module has not been loaded.\nCheck configuration manually.\n"
            )
          )
        end
      end
    end
  end

  # ReadHardware(""); /* TESTING
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 2/9
  ProgressNextStage(_("Detecting network devices...")) if @gui
  # Dont read hardware data in config mode
  NetHwDetection.Start if !Mode.config

  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 3/9 - multiple devices may be present, really plural
  ProgressNextStage(_("Reading device configuration...")) if @gui
  LanItems.Read
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 4/9
  ProgressNextStage(_("Reading network configuration...")) if @gui
  NetworkConfig.Read

  readIPv6

  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 5/9
  ProgressNextStage(_("Reading firewall settings...")) if @gui
  orig = Progress.set(false)
  SuSEFirewall4Network.Read
  Progress.set(orig) if @gui
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 6/9
  ProgressNextStage(_("Reading hostname and DNS configuration...")) if @gui
  DNS.Read
  Host.Read
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 7/9
  ProgressNextStage(_("Reading installation information...")) if @gui
  #    ReadInstallInf();
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 8/9
  ProgressNextStage(_("Reading routing configuration...")) if @gui
  Routing.Read
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 9/9
  ProgressNextStage(_("Detecting current status...")) if @gui
  NetworkService.Read
  Builtins.sleep(sl)

  return false if Abort()
  # Final progress step
  ProgressNextStage(_("Finished")) if @gui
  Builtins.sleep(sl)

  return false if Abort()
  LanItems.modified = false
  @initialized = true

  Progress.Finish if @gui

  true
end

- (Object) readIPv6



214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# File '../../src/modules/Lan.rb', line 214

def readIPv6
  @ipv6 = true

  methods =
    #         "module" : $[
    #                 "filelist" : ["ipv6", "50-ipv6.conf"],
    #                 "filepath" : "/etc/modprobe.d/",
    #                 "regexp"   : "^[[:space:]]*(install ipv6 /bin/true)"
    #         ]
    {
      "builtin" => {
        "filelist" => ["sysctl.conf"],
        "filepath" => "/etc/",
        "regexp"   => "^[[:space:]]*(net.ipv6.conf.all.disable_ipv6)[[:space:]]*=[[:space:]]*1"
      }
    }

  Builtins.foreach(methods) do |which, method|
    filelist = Ops.get_list(method, "filelist", [])
    filepath = Ops.get_string(method, "filepath", "")
    regexp = Ops.get_string(method, "regexp", "")
    Builtins.foreach(filelist) do |file|
      filename = Builtins.sformat("%1/%2", filepath, file)
      if FileUtils.Exists(filename)
        Builtins.foreach(
          Builtins.splitstring(
            Convert.to_string(SCR.Read(path(".target.string"), filename)),
            "\n"
          )
        ) do |row|
          if Ops.greater_than(
              Builtins.size(
                Builtins.regexptokenize(String.CutBlanks(row), regexp)
              ),
              0
            )
            Builtins.y2milestone("IPv6 is disabled by '%1' method.", which)
            @ipv6 = false
          end
        end
      end
    end
  end

  nil
end

- (Object) ReadWithCache

(a specialization used when a parameterless function is needed)



426
427
428
# File '../../src/modules/Lan.rb', line 426

def ReadWithCache
  Read(:cache)
end

- (Object) ReadWithCacheNoGUI



430
431
432
433
# File '../../src/modules/Lan.rb', line 430

def ReadWithCacheNoGUI
  @gui = false
  ReadWithCache()
end

- (Object) SetIPv6(status)



435
436
437
438
439
440
441
442
443
# File '../../src/modules/Lan.rb', line 435

def SetIPv6(status)
  if @ipv6 != status
    @ipv6 = status
    Popup.Warning(_("To apply this change, a reboot is needed."))
    LanItems.SetModified
  end

  nil
end

- (Object) Summary(mode)

Create a textual summary and a list of unconfigured devices “proposal”: for proposal, add links for direct config

Parameters:

  • mode (String)

    “split”: split configured and unconfigured?<br /> “summary”: add resolver and routing symmary,

Returns:

  • summary of the current configuration



759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
# File '../../src/modules/Lan.rb', line 759

def Summary(mode)
  split = mode == "split"

  sum = LanItems.BuildLanOverview

  # Testing improved summary
  if mode == "summary"
    Ops.set(
      sum,
      0,
      Ops.add(
        Ops.add(Ops.get_string(sum, 0, ""), DNS.Summary),
        Routing.Summary
      )
    )
  end

  deep_copy(sum)
end

- (rich text, links) SummaryGeneral

Create a textual summary for the general network settings proposal (NetworkManager + ipv6)

Returns:

  • (rich text, links)


782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
# File '../../src/modules/Lan.rb', line 782

def SummaryGeneral
  status_nm = nil
  status_v6 = nil
  status_virt_net = nil
  href_nm = nil
  href_v6 = nil
  href_virt_net = nil
  link_nm = nil
  link_v6 = nil
  link_virt_net = nil
  header_nm = _("Network Mode")

  if NetworkService.is_network_manager
    href_nm = "lan--nm-disable"
    # network mode: the interfaces are controlled by the user
    status_nm = _("Interfaces controlled by NetworkManager")
    # disable NetworkManager applet
    link_nm = Hyperlink(href_nm, _("Disable NetworkManager"))
  else
    href_nm = "lan--nm-enable"
    # network mode
    status_nm = _("Traditional network setup with NetControl - ifup")
    # enable NetworkManager applet
    # for virtual network proposal (bridged) don't show hyperlink to enable networkmanager
    link_nm = Hyperlink(href_nm, _("Enable NetworkManager"))
  end

  if @ipv6
    href_v6 = "ipv6-disable"
    # ipv6 support is enabled
    status_v6 = _("Support for IPv6 protocol is enabled")
    # disable ipv6 support
    link_v6 = Hyperlink(href_v6, _("Disable IPv6"))
  else
    href_v6 = "ipv6-enable"
    # ipv6 support is disabled
    status_v6 = _("Support for IPv6 protocol is disabled")
    # enable ipv6 support
    link_v6 = Hyperlink(href_v6, _("Enable IPv6"))
  end
  descr = Builtins.sformat(
    "<ul><li>%1: %2 (%3)</li></ul> \n\t\t\t     <ul><li>%4 (%5)</li></ul>",
    header_nm,
    status_nm,
    link_nm,
    status_v6,
    link_v6
  )
  if link_virt_net != nil
    descr = Builtins.sformat(
      "%1\n\t\t\t\t\t\t<ul><li>%2 (%3)</li></ul>",
      descr,
      status_virt_net,
      link_virt_net
    )
  end
  links = [href_nm, href_v6]
  links = Builtins.add(links, href_virt_net) if href_virt_net != nil
  [descr, links]
end

- (Object) UseNetworkManager

Uses product info and is subject to installed packages.

Returns:

  • Should NM be enabled?



865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
# File '../../src/modules/Lan.rb', line 865

def UseNetworkManager
  nm_default = false
  nm_feature = ProductFeatures.GetStringFeature(
    "network",
    "network_manager"
  )
  if nm_feature == ""
    # compatibility: use the boolean feature
    # (defaults to false)
    nm_default = ProductFeatures.GetBooleanFeature(
      "network",
      "network_manager_is_default"
    )
  elsif nm_feature == "always"
    nm_default = true
  elsif nm_feature == "laptop"
    nm_default = Arch.is_laptop
    Builtins.y2milestone("Is a laptop: %1", nm_default) # nm_feature == "never"
  else
    nm_default = false
  end

  nm_installed = Package.Installed("NetworkManager")
  Builtins.y2milestone(
    "NetworkManager wanted: %1, installed: %2",
    nm_default,
    nm_installed
  )
  nm_default && nm_installed
end

- (Object) Write

Update the SCR according to network settings

Returns:

  • true on success



493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
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
650
651
652
653
654
655
656
657
658
# File '../../src/modules/Lan.rb', line 493

def Write
  Builtins.y2milestone("Writing configuration")

  # Query modified flag in all components, not just LanItems - DNS,
  # Routing, NetworkConfig too in order not to discard changes made
  # outside LanItems (bnc#439235)
  if !Modified()
    Builtins.y2milestone("No changes to network setup -> nothing to write")
    return true
  end

  fw_is_installed = SuSEFirewall4Network.IsInstalled

  # Write dialog caption
  caption = _("Saving Network Configuration")

  sl = 0 # 1000; /* TESTING
  Builtins.sleep(sl)

  step_labels = [
    # Progress stage 2
    _("Write drivers information"),
    # Progress stage 3 - multiple devices may be present,really plural
    _("Write device configuration"),
    # Progress stage 4
    _("Write network configuration"),
    # Progress stage 5
    _("Write routing configuration"),
    # Progress stage 6
    _("Write hostname and DNS configuration"),
    # Progress stage 7
    _("Set up network services")
  ]
  # Progress stage 8
  if fw_is_installed
    step_labels = Builtins.add(step_labels, _("Write firewall settings"))
  end
  # Progress stage 9
  if !@write_only
    step_labels = Builtins.add(step_labels, _("Activate network services"))
  end
  # Progress stage 10
  step_labels = Builtins.add(step_labels, _("Update configuration"))

  Progress.New(
    caption,
    " ",
    Builtins.size(step_labels),
    step_labels,
    [],
    ""
  )


  return false if Abort()
  # Progress step 2
  ProgressNextStage(_("Writing /etc/modprobe.conf..."))
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 3 - multiple devices may be present, really plural
  ProgressNextStage(_("Writing device configuration..."))
  LanItems.write
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 4
  ProgressNextStage(_("Writing network configuration..."))
  NetworkConfig.Write
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 5
  ProgressNextStage(_("Writing routing configuration..."))
  orig = Progress.set(false)
  Routing.Write
  Progress.set(orig)
  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 6
  ProgressNextStage(_("Writing hostname and DNS configuration..."))
  # write resolv.conf after change from dhcp to static (#327074)
  # reload/restart network before this to put correct resolv.conf from dhcp-backup
  orig = Progress.set(false)
  DNS.Write
  Host.EnsureHostnameResolvable
  Host.Write
  Progress.set(orig)

  Builtins.sleep(sl)

  return false if Abort()
  # Progress step 7
  ProgressNextStage(_("Setting up network services..."))
  writeIPv6
  Builtins.sleep(sl)

  #Show this only if SuSEfirewall is installed
  if fw_is_installed
    return false if Abort()
    # Progress step 8
    ProgressNextStage(_("Writing firewall settings..."))
    orig = Progress.set(false)
    SuSEFirewall4Network.Write
    Progress.set(orig)
    Builtins.sleep(sl)
  end

  if !@write_only
    return false if Abort()
    # Progress step 9
    ProgressNextStage(_("Activating network services..."))
    # during installation export sysconfig settings into NetworkManager (bnc#433084)
    if Mode.installation && NetworkService.is_network_manager
      Builtins.y2internal(
        "Export sysconfig settings into NetworkManager %1",
        SCR.Execute(
          path(".target.bash_output"),
          "/usr/lib/NetworkManager/nm-opensuse-sysconfig-merge --connections"
        )
      )
    end

    if LanItems.force_restart
      NetworkService.Restart
    else
      # If the second installation stage has been called by yast.ssh via
      # ssh, we should not restart network cause systemctl
      # hangs in that case. (bnc#885640)
      NetworkService.ReloadOrRestart if !Linuxrc.usessh
    end
    Builtins.sleep(sl)
  end

  return false if Abort()
  # Progress step 10
  ProgressNextStage(_("Updating configuration..."))
  update_mta_config if !@write_only
  Builtins.sleep(sl)

  if NetworkService.is_network_manager
    network = false
    timeout = 15
    while Ops.greater_than(timeout, 0)
      if NetworkService.isNetworkRunning
        network = true
        break
      end
      Builtins.y2milestone("waiting for network ... %1", timeout)
      Builtins.sleep(1000)
      timeout = Ops.subtract(timeout, 1)
    end

    Popup.Error(_("No network running")) unless network
  end

  # Final progress step
  ProgressNextStage(_("Finished"))
  Builtins.sleep(sl)

  Progress.Finish

  return false if Abort()
  true
end

- (Object) writeIPv6



445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
# File '../../src/modules/Lan.rb', line 445

def writeIPv6
  #  SCR::Write(.target.string, "/etc/modprobe.d/ipv6", sformat("%1install ipv6 /bin/true", ipv6?"#":""));
  # uncomment to write to old place (and comment code bellow)
  #  SCR::Write(.target.string, "/etc/modprobe.d/50-ipv6.conf", sformat("%1install ipv6 /bin/true\n", ipv6?"#":""));
  filename = "/etc/sysctl.conf"
  sysctl = Convert.to_string(SCR.Read(path(".target.string"), filename))
  sysctl_row = Builtins.sformat(
    "%1net.ipv6.conf.all.disable_ipv6 = 1",
    @ipv6 ? "# " : ""
  )
  found = false #size(regexptokenize(sysctl, "(net.ipv6.conf.all.disable_ipv6)"))>0;
  file = []
  Builtins.foreach(Builtins.splitstring(sysctl, "\n")) do |row|
    if Ops.greater_than(
        Builtins.size(
          Builtins.regexptokenize(row, "(net.ipv6.conf.all.disable_ipv6)")
        ),
        0
      )
      row = sysctl_row
      found = true
    end
    file = Builtins.add(file, row)
  end
  file = Builtins.add(file, sysctl_row) if !found
  SCR.Write(
    path(".target.string"),
    filename,
    Builtins.mergestring(file, "\n")
  )
  SCR.Execute(
    path(".target.bash"),
    Builtins.sformat(
      "sysctl -w net.ipv6.conf.all.disable_ipv6=%1",
      !@ipv6 ? "1" : "0"
    )
  )
  SCR.Write(
    path(".sysconfig.windowmanager.KDE_USE_IPV6"),
    @ipv6 ? "yes" : "no"
  )

  nil
end

- (Object) WriteOnly

Only write configuration without starting any init scripts and SuSEconfig

Returns:

  • true on success



662
663
664
665
666
667
668
669
# File '../../src/modules/Lan.rb', line 662

def WriteOnly
  @write_only = !Ops.get_boolean(
    LanItems.autoinstall_settings,
    "start_immediately",
    false
  )
  Write()
end