Class: Yast::FcoeClientClass

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

Constant Summary

FCOE_PKG_NAME =
"fcoe-utils"

Instance Method Summary (collapse)

Instance Method Details

- (Boolean) Abort

Abort function

Returns:

  • (Boolean)

    return true if abort



132
133
134
135
# File '../../src/modules/FcoeClient.rb', line 132

def Abort
  return @AbortFunction.call == true if @AbortFunction != nil
  false
end

- (Object) AddRevertCommand(command)

Add a command to the list of revert commands



212
213
214
215
216
217
# File '../../src/modules/FcoeClient.rb', line 212

def AddRevertCommand(command)
  @revert_list = Builtins.add(@revert_list, command)
  Builtins.y2milestone("Adding revert command: %1", command)

  nil
end

- (Object) AdjustStartStatus

Set status of services



644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
# File '../../src/modules/FcoeClient.rb', line 644

def AdjustStartStatus
  fcoe_start = Ops.get(@service_start, "fcoe", false)
  lldpad_start = Ops.get(@service_start, "lldpad", false)
  Builtins.y2milestone(
    "Setting start of /etc/init.d/boot.fcoe to %1",
    fcoe_start
  )
  Builtins.y2milestone(
    "Setting start of /etc/init.d/lldpad to %1",
    lldpad_start
  )

  if fcoe_start && lldpad_start
    Service.Enable("boot.lldpad") # enable 'lldpad' first
    Service.Enable("boot.fcoe")
  elsif !fcoe_start && lldpad_start
    Service.Disable("boot.fcoe")
    Service.Enable("boot.lldpad")
  elsif !fcoe_start && !lldpad_start
    Service.Disable("boot.fcoe") # disable 'fcoe' first
    Service.Disable("boot.lldpad")
  end 
  # fcoe_start && !lldpad_start isn't possible -> see complex.ycp StoreServicesDialog

  nil
end

- (Hash) AutoPackages

Return packages needed to be installed and removed during Autoinstallation to insure module has all needed software installed.

Returns:

  • (Hash)

    with 2 lists.



1552
1553
1554
1555
# File '../../src/modules/FcoeClient.rb', line 1552

def AutoPackages
  # installation of fcoe-utils required
  { "install" => [FcoeClientClass::FCOE_PKG_NAME], "remove" => [] }
end

- (Object) CheckInstalledPackages

Check whether fcoe-utils is installed and do installation if user agrees (dependencies: 'open-lldp', 'libhbalinux2' and 'libHBAAPI2')



269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
# File '../../src/modules/FcoeClient.rb', line 269

def CheckInstalledPackages
  ret = false

  # don't check interactively for packages (bnc#367300) -> comment from iscsi-client
  # skip it during initial and second stage or when create AY profile
  return true if Stage.cont || Stage.initial || Mode.config
  Builtins.y2milestone("Check whether package %1 is installed",
                       FcoeClientClass::FCOE_PKG_NAME)

  if !Package.InstallMsg(
      FcoeClientClass::FCOE_PKG_NAME,
      _(
        "<p>To continue the FCoE configuration, the <b>%1</b> package must be installed.</p>"
      ) +
        _("<p>Install it now?</p>")
    )
    Popup.Error(Message.CannotContinueWithoutPackagesInstalled)
  else
    ret = true
  end
  ret
end

- (Object) CreateFcoeConfig(vlan_device_name, netcard)

Create /etc/fcoe/cfg-<if> or /etc/fcoe/cfg-<if>.<vlan> (depending on AUTO_VLAN setting)



473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
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
# File '../../src/modules/FcoeClient.rb', line 473

def CreateFcoeConfig(vlan_device_name, netcard)
  netcard = deep_copy(netcard)
  file_name = ""
  device_name = ""
  file_exists = false
  status_map = {}

  # if AUTO_VLAN is set to "yes" or VLAN is set to "0" (means no VLAN created but FCoE started on device)
  if Ops.get_string(netcard, "auto_vlan", "no") == "yes" ||
      Ops.get_string(netcard, "vlan_interface", "") == "0"
    device_name = Ops.get_string(netcard, "dev_name", "")
    # set file name to cfg-<interface>, e.g. /etc/fcoe/cfg-eth3
    file_name = Builtins.sformat("/etc/fcoe/cfg-%1", device_name)
  else
    device_name = vlan_device_name
    # set file name to cfg-<vlan_device_name>, e.g. /etc/fcoe/cfg-eth3.200
    file_name = Builtins.sformat("/etc/fcoe/cfg-%1", vlan_device_name)
  end

  # read default values
  content = Convert.to_string(
    SCR.Read(path(".target.string"), "/etc/fcoe/cfg-ethx")
  )

  # and prepare content
  if content != "" && content != nil
    lines = Builtins.splitstring(content, "\n")
    lines = Builtins.maplist(lines) do |line|
      if !String.StartsWith(line, "#")
        line = Builtins.deletechars(line, " \t")
      end
      if String.StartsWith(line, "AUTO_VLAN")
        next Builtins.sformat(
          "AUTO_VLAN=\"%1\"",
          Ops.get_string(netcard, "auto_vlan", "no")
        )
      elsif String.StartsWith(line, "DCB_REQUIRED")
        next Builtins.sformat(
          "DCB_REQUIRED=\"%1\"",
          Ops.get_string(netcard, "dcb_required", "no")
        )
      elsif String.StartsWith(line, "FCOE_ENABLE")
        next Builtins.sformat(
          "FCOE_ENABLE=\"%1\"",
          Ops.get_string(netcard, "fcoe_enable", "yes")
        )
      else
        next line
      end
    end
    content = Builtins.mergestring(lines, "\n")
    Builtins.y2milestone("Writing content: %1 to %2", content, file_name)

    file_exists = SCR.Write(path(".target.string"), file_name, content)

    if file_exists
      AddRevertCommand(Builtins.sformat("rm %1", file_name))
      # fill status map
      status_map = {
        "FCOE_ENABLE"  => netcard["fcoe_enable"] || "yes",
        "DCB_REQUIRED" => netcard["dcb_required"] || "no",
        "AUTO_VLAN"    => netcard["auto_vlan"] || "no",
        "cfg_device"   => device_name
      }
    else
      Builtins.y2error("Cannot create %1", file_name)
    end
  else
    Builtins.y2error("Cannot read /etc/fcoe/cfg-ethx")
  end

  deep_copy(status_map)
end

- (Object) DCBCapable(netcard)

Check whether the network interface (netcard, e.g. eth0 is DCB capable)



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
# File '../../src/modules/FcoeClient.rb', line 606

def DCBCapable(netcard)
  ret = "no"

  # 'lldpad' must be started to be able to use 'dcbtool'
  # -> is started in ServiceStatus() ( called in Read() before DetectNetworkCards() )
  command = Builtins.sformat("LANG=POSIX dcbtool gc %1 dcb", netcard)
  Builtins.y2milestone("Executing command: %1", command)

  output = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
  Builtins.y2milestone("Output:  %1", output)
  status = ""

  if Ops.get_integer(output, "exit", 255) == 0
    lines = Builtins.splitstring(Ops.get_string(output, "stdout", ""), "\n")
    Builtins.foreach(lines) do |line|
      if String.StartsWith(line, "Status")
        # Status:         Failed		interface not DCB capable
        # Status:         Successful
        line = Builtins.deletechars(line, " \t:")
        status = Builtins.substring(line, 6)
        Builtins.y2milestone("Status: %1", status)
      end
    end
    ret = "yes" if status == "Successful"
  else
    Builtins.y2error(
      "Exit code: %1 Error: %2",
      Ops.get_integer(output, "exit", 255),
      Ops.get_string(output, "stderr", "")
    )
  end

  ret
end

- (Object) DetectNetworkCards(netcards)

list <map> network_interfaces

dev_name mac_addr device vlan_interface fcoe_vlan fcoe_enable dcb_required auto_vlan dcb_capable cfg_device eth3 08:00:... Gigabit... 200 eth3.200 yes/no yes/no yes/no yes/no eth3.200

Get the network cards and check Fcoe status



829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
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
895
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
# File '../../src/modules/FcoeClient.rb', line 829

def DetectNetworkCards(netcards)
  return [] if netcards == nil

  net_devices = []

  netcards.each do |card|
    net_devices = Builtins.add(
      net_devices,
      card["dev_name"] || ""
    )
  end

  # The 'fipvlan' command which is called in GetVlanInterfaces configures the interfaces itself,
  # therefore it's not needed any longer to call 'ifconfig <if> up' here.
  vlan_info = GetVlanInterfaces(net_devices, GetFcoeInfo(net_devices) )
  network_interfaces = []

  netcards.each do |card|
    device = card["dev_name"] || ""
    dcb_capable = DCBCapable(device) # DCB capable

    if Ops.get(vlan_info, device, []).empty?
      # Interface down or FCoE not enabled on the switch - we can't do anything here.
      fcoe_vlan_interface = @NOT_AVAILABLE

      # add infos about the card
      info_map = {
        "dcb_capable"=> dcb_capable,
        "dev_name"   => device, # network card, e.g. eth3
        "mac_addr"   => Ops.get_string(card, ["resource", "hwaddr", 0, "addr"], ""), # MAC address
        "device"     => card["device"] || card["model"] || "",
        "fcoe_vlan"  => fcoe_vlan_interface
      }

      network_interfaces = network_interfaces << info_map
    else
      # add infos about card and VLAN interfaces
      vlans = Ops.get(vlan_info, device, [])

      vlans.each do |vlan|
        info_map = {}
        status_map = {}
        dcb_default = ""
        vlan_if = vlan["vlan"] || ""

        if vlan_if == "0"
          # VLAN interface "0" means start FCoE on network interface itself (there isn't an entry in
          # /proc/net/vlan/config, check config files instead)
          fcoe_vlan_interface = FcoeOnInterface?(device, vlans)?device:""
        else
          # get FCoE VLAN interface from /proc/net/vlan/config
          fcoe_vlan_interface = GetFcoeVlanInterface(device, vlan_if)
        end

        if !fcoe_vlan_interface.empty?
          status_map = GetFcoeStatus(fcoe_vlan_interface, device)
          if status_map == {}
            # warning if no valid configuration found
            Builtins.y2warning(
                               "Cannot read config file for %1 in /etc/fcoe",
                               fcoe_vlan_interface
                               )
            Report.Warning(
              Builtins.sformat(
                _(
                    "Cannot read config file for %1.\n" +
                      "You may edit the settings and recreate the FCoE\n" +
                      "VLAN interface to get a valid configuration."
                  ),
                  fcoe_vlan_interface
                )
              )
            # set interface to NOT_CONFIGURED
            fcoe_vlan_interface = @NOT_CONFIGURED
          end # if status_map == {}
        else
          # FCoE VLAN interface not yet configured (status_map remains empty)
          fcoe_vlan_interface = @NOT_CONFIGURED
        end # if !fcoe_vlan_interface.empty?

        # exception for Broadcom cards: DCB_REQUIRED should be set to "no" (bnc #728658)
        if card["driver"] != "bnx2x" && dcb_capable == "yes"
          dcb_default = "yes"
        else
          dcb_default = "no"
        end

        info_map = {
          "dev_name"       => device, # network card, e.g. eth3
          "mac_addr"       => Ops.get_string(card, ["resource", "hwaddr", 0, "addr"], ""), # MAC address
          "device"         => card["device"] || card["model"] || "",
          "fcoe_vlan"      => fcoe_vlan_interface, # FCoE VLAN interface, e.g. eth3.200
          "fcoe_enable"    => status_map["FCOE_ENABLE"] || "yes",  # default for FCoE enable is yes
          "dcb_required"   => status_map["DCB_REQUIRED"] || dcb_default,
          "auto_vlan"      => status_map["AUTO_VLAN"] || "yes", # default is AUTO_VLAN="yes", see bnc #724563
          "dcb_capable"    => dcb_capable, # DCB capable
          "vlan_interface" => vlan["vlan"] || "", # VLAN interface, e.g. 200
          "cfg_device"     => status_map["cfg_device"] || "" # part of cfg-file name, e.g. eth3.200
        }

        network_interfaces = network_interfaces << info_map
      end # do |vlan|
    end # else
  end # do |card|

  # sort the list of interfaces (eth0, eth1, eth2...)
  network_interfaces = Builtins.sort(network_interfaces) do |a, b|
    Ops.less_than(a["dev_name"] || "", b["dev_name"] || "")
  end

  Builtins.y2milestone("Returning: %1", network_interfaces)
  network_interfaces
end

- (Object) DetectStartStatus

Get status of services



684
685
686
687
688
689
690
691
692
693
694
695
696
# File '../../src/modules/FcoeClient.rb', line 684

def DetectStartStatus
  status = false

  status = Service.Enabled("boot.fcoe")
  Builtins.y2milestone("Start status of fcoe: %1", status)
  @service_start = Builtins.add(@service_start, "fcoe", status)

  status = Service.Enabled("boot.lldpad")
  Builtins.y2milestone("Start status of lldpad: %1", status)
  @service_start = Builtins.add(@service_start, "lldpad", status)

  nil
end

- (Hash) Export

Dump the fcoe-client settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



1465
1466
1467
1468
1469
1470
1471
1472
# File '../../src/modules/FcoeClient.rb', line 1465

def Export
  # return map containing current settings
  {
    "fcoe_cfg"      => @fcoe_general_config,
    "interfaces"    => @network_interfaces,
    "service_start" => @service_start
  }
end

- (Object) FcoeClient

Constructor



119
120
121
122
123
124
125
126
127
128
# File '../../src/modules/FcoeClient.rb', line 119

def FcoeClient
  if Builtins.getenv("FCOE_CLIENT_TEST_MODE") == "1"
    Builtins.y2milestone("Running in test mode")
    @test_mode = true
  else
    @test_mode = false
  end

  nil
end

- (Boolean) FcoeOnInterface?(device, vlans)

Check configuration for VLAN ID = 0

Returns:

  • (Boolean)


946
947
948
949
950
951
952
953
954
955
956
957
# File '../../src/modules/FcoeClient.rb', line 946

def FcoeOnInterface?(device, vlans)
  return false unless FileUtils.Exists("/etc/fcoe/cfg-#{device}")
  ret = true
    vlans.each do |vlan_cfg|
    # no ifcfg-<if>.<vlan> written for vlan = 0 (see WriteSysconfigFiles() )
    if FileUtils.Exists( "/etc/sysconfig/network/ifcfg-#{device}.#{vlan_cfg["vlan"] || ""}" )
      # sysconfig file for an VLAN interface found, i.e. FCoE isn't configured on interface itself
      ret = false
    end
  end
  ret
end

- (Object) GetCurrentNetworkCard

Get currently selected network card



239
240
241
# File '../../src/modules/FcoeClient.rb', line 239

def GetCurrentNetworkCard
  Ops.get(@network_interfaces, @current_card, {})
end

- (Object) GetFcoeConfig

Returns the map containing general FCoE configuration



207
208
209
# File '../../src/modules/FcoeClient.rb', line 207

def GetFcoeConfig
  deep_copy(@fcoe_general_config)
end

- (List) GetFcoeInfo(net_devices)

Check whether/which VLAN interfaces are configured for FCoE on the switch (by calling command 'fipvlan').

Examples:

Parameters:

  • net_devices (List)

    detected network cards

Returns:

  • (List)

    information about FcoE VLAN interfaces



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
# File '../../src/modules/FcoeClient.rb', line 306

def GetFcoeInfo(net_devices)
  # Add option -u (or --link_up): don't shut down interfaces
  # to be able to detect DCB state afterwards (see bnc #737683)
  vlan_cmd = "LANG=POSIX fipvlan -u"

  if !Mode.autoinst
    vlan_cmd = Ops.add(Ops.add(vlan_cmd, " -l "), @number_of_retries)
  end # reduce number of retries

  Builtins.foreach(
    Convert.convert(net_devices, :from => "list", :to => "list <string>")
  ) { |dev| vlan_cmd = Ops.add(Ops.add(vlan_cmd, " "), dev) }

  # call fipvlan command for all interfaces (saves time because is executed in parallel)
  Builtins.y2milestone("Executing command: %1", vlan_cmd)
  output = Convert.to_map(
    SCR.Execute(path(".target.bash_output"), vlan_cmd)
  )
  Builtins.y2milestone("Output: %1", output)

  lines = []
  if !TestMode()
    lines = Builtins.splitstring(output["stdout"] || "", "\n")
  else
    # test data
    lines = Builtins.splitstring(
      "Fibre Channel Forwarders\n" +
        "< Discovered\n" +
        "interface       | VLAN | FCF MAC\n" +
        "< \n" +
        "------------------------------------------\n" +
        "eth1           | 500   |54:7f:ee:09:55:9f\n" +
        "eth15          | 2012  |54:7f:ee:04:55:9f\n" +
        "eth15          | 0     |54:7f:ee:04:55:9f\n" +
        "eth15          | 200   |54:7f:ee:04:55:8f\n" +
        "eth1           | 301   |54:7f:ee:06:55:9f\n" +
        "eth1           | 400   |54:7f:ee:07:55:9f\n" +
        "\n",
      "\n"
    )
  end
end

- (Object) GetFcoeStatus(vlan_device_name, device_name)

Get status of FCoE config from /etc/fcoe/cfg-<if>.<vlan> or /etc/fcoe/cfg-<if>



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
# File '../../src/modules/FcoeClient.rb', line 550

def GetFcoeStatus(vlan_device_name, device_name)
  status_map = {}
  content = ""
  file_name = ""
  device = vlan_device_name

  if vlan_device_name == "" || device_name == ""
    Builtins.y2error("Interface not valid")
    return {}
  end

  Builtins.y2milestone("Checking configuration for %1", vlan_device_name)

  file_name = Builtins.sformat("/etc/fcoe/cfg-%1", vlan_device_name)

  if !FileUtils.Exists(file_name)
    file_name = Builtins.sformat("/etc/fcoe/cfg-%1", device_name)

    if !FileUtils.Exists(file_name)
      # no config file found - return empty status map
      return deep_copy(status_map)
    else
      # check whether there is a sysconfig file for given vlan_device_name
      file_name = "/etc/sysconfig/network/ifcfg-#{vlan_device_name}"
      # configuration in /etc/fcoe/cfg-<device_name> doesn't belong to vlan_device_name
      if !FileUtils.Exists(file_name)
        return deep_copy(status_map)
      end
    end
    device = device_name
  end
  # for debugging purpose, read only needed values later
  values = SCR.Dir(Ops.add(path(".fcoe.cfg-ethx.value"), device))
  Builtins.y2milestone("Available values in %1: %2", file_name, values)

  Builtins.foreach(["FCOE_ENABLE", "DCB_REQUIRED", "AUTO_VLAN"]) do |var|
    value = Convert.to_string(
      SCR.Read(Ops.add(Ops.add(path(".fcoe.cfg-ethx.value"), device), var))
    )
    if value == nil
      Builtins.y2warning("Cannot read %1", var)
      next
    end
    status_map = Builtins.add(status_map, var, value)
  end

  status_map = Builtins.add(status_map, "cfg_device", device)

  Builtins.y2milestone("Returning: %1", status_map)

  deep_copy(status_map)
end

- (String) GetFcoeVlanInterface(interface, vlan_interface)

Check whether the VLAN device is created (check entries in /proc/net/vlan/config)

cat /proc/net/vlan/config

VLAN Dev name | VLAN ID Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD eth3.200 | 200 | eth3

Parameters:

  • interface (String)

    network interface card, e.g. eth3

  • vlan_interface (String)

    Vlan Interface configured for FCoE (on switch)

Returns:

  • (String)

    Vlan device name, e.g. eth3.200



437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
# File '../../src/modules/FcoeClient.rb', line 437

def GetFcoeVlanInterface(interface, vlan_interface)
  vlan_device_name = ""

  if TestMode()
    vlan_device_name = "#{interface}.#{vlan_interface}"
    Builtins.y2milestone("Test mode - Returning: %1", vlan_device_name)
    return vlan_device_name
  end

  command = Builtins.sformat(
    "sed -n 's/\\([^ ]*\\) *.*%1*.*%2/\\1/p' /proc/net/vlan/config",
    vlan_interface,
    interface
  )
  Builtins.y2milestone("Executing command: %1", command)

  output = Convert.to_map(SCR.Execute(path(".target.bash_output"), command))
  Builtins.y2milestone("Output: %1", output)
  # read stdout (remove \n and white spaces)
  vlan_device_name = Builtins.deletechars(
    Ops.get_string(output, "stdout", ""),
    " \n\t"
  )

  if vlan_device_name != ""
    Builtins.y2milestone("Returning: %1", vlan_device_name)
  else
    Builtins.y2error("FCoE VLAN not found in /proc/net/vlan/config")
  end
  vlan_device_name
end

- (Object) GetNetworkCards

Returns the map containing all detected interfaces (possibly including several entries for a network interface if several VLAN interfaces are detected)



234
235
236
# File '../../src/modules/FcoeClient.rb', line 234

def GetNetworkCards
  deep_copy(@network_interfaces)
end

- (Object) GetRevertCommands

Get the list of revert commands



220
221
222
# File '../../src/modules/FcoeClient.rb', line 220

def GetRevertCommands
  deep_copy(@revert_list)
end

- (Object) GetStartStatus



698
699
700
# File '../../src/modules/FcoeClient.rb', line 698

def GetStartStatus
  deep_copy(@service_start)
end

- (Hash) GetVlanInterfaces(net_devices, fcoe_info)

Provide information about FCoE capable VLAN interfaces for each network card

Examples:

Param net_devices:
["eth0", "eth1", "eth2"]
Param fcoe_info:
["eth0     | 200  | 00:0d:ec:a2:ef:00",
 "eth0     | 300  | 00:0d:ec:a2:ef:01",
 "eth2     | 200  | 00:0d:ec:a2:ef:02" ]
Return:
{ "eth0" => [{ "vlan" => "200", "fcf" => "00:0d:ec:a2:ef:00" },
             { "vlan" => "300", "fcf" => "00:0d:ec:a2:ef:01" }],
  "eth2" => [{ "vlan" => "200", "fcf" => "00:0d:ec:a2:ef:02" }]
}

Parameters:

  • net_devices (List)

    network cards

  • fcoe_info (List)

    information about FCoE VLAN interfaces

Returns:

  • (Hash)

    assorted FCoE info per network card



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
423
# File '../../src/modules/FcoeClient.rb', line 369

def GetVlanInterfaces(net_devices, fcoe_info)
  net_devices = deep_copy(net_devices)
  fcoe_info = deep_copy(fcoe_info)
  vlan_info = {}

  Builtins.foreach(
    Convert.convert(net_devices, :from => "list", :to => "list <string>")
  ) { |dev| Builtins.foreach(fcoe_info) do |line|
    # Check whether there is a line for the given interface, e.g.
    # eth3            | 200  | 00:0d:ec:a2:ef:00\n
    # Get VLAN channel from second column and FCF MAC from third.
    line = Builtins.deletechars(line, " \t")
    columns = Builtins.splitstring(line, "|")
    if Ops.get(columns, 0, "") == dev
      # get VLAN and FCF MAC and add it to vlan_info
      vlan_interface = { "vlan" => Ops.get(columns, 1, ""), "fcf" => Ops.get(columns, 2, "") }

      Builtins.y2milestone(
        "Interface: %1 VLAN: %2 FCF: %3",
        dev,
        Ops.get(columns, 1, ""),
        Ops.get(columns, 2, "")
      )

      if Ops.get(vlan_info, dev, []) == []
        vlan_info = Builtins.add(vlan_info, dev, [vlan_interface])
      else
        vlans = Convert.convert(
          Ops.get(vlan_info, dev, []),
          :from => "list",
          :to   => "list <map>"
        )

        # add vlan_interface only if no entry with identical FCF MAC exists
        if Builtins.find(vlans) do |vlan|
            (vlan["fcf"] || "") == (vlan_interface["fcf"] || "")
          end == nil
          vlans = Builtins.add(vlans, vlan_interface)
        elsif (vlan_interface["vlan"] || "") == "0" # for VLAN = 0 replace existing entry
          # VLAN = 0 'wins' (see bnc #813621, comment #4)
          vlans = Builtins.maplist(vlans) do |vlan|
            if (vlan["fcf"] || "") == (vlan_interface["fcf"] || "")
              Builtins.y2milestone("VLAN = 0 is taken")
              Ops.set(vlan, "vlan", "0")
            end
            deep_copy(vlan)
          end
        end
        Ops.set(vlan_info, dev, vlans)
      end
    end
  end }
  Builtins.y2milestone("VLAN info: %1", vlan_info)
  deep_copy(vlan_info)
end

- (Boolean) Import(settings)

Get all fcoe-client settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
# File '../../src/modules/FcoeClient.rb', line 1449

def Import(settings)
  settings = deep_copy(settings)
  # fill variables
  @fcoe_general_config = Ops.get_map(settings, "fcoe_cfg", {})
  @network_interfaces = Ops.get_list(settings, "interfaces", [])
  @service_start = Ops.get_map(settings, "service_start", {})

  SetModified(true)
  Builtins.y2milestone("Configuration has been imported")

  true
end

- (Object) IsConfigured(device_name)

Check whether there are configured FCoE VLANs for the given network interface Return list of configured VLANs



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
# File '../../src/modules/FcoeClient.rb', line 757

def IsConfigured(device_name)
  configured_vlans = []
  interfaces = GetNetworkCards()

  Builtins.foreach(interfaces) do |interface|
    if device_name == Ops.get_string(interface, "dev_name", "") &&
        Ops.get_string(interface, "fcoe_vlan", "") != @NOT_CONFIGURED &&
        Ops.get_string(interface, "fcoe_vlan", "") != @NOT_AVAILABLE
      configured_vlans = Builtins.add(
        configured_vlans,
        Ops.get_string(interface, "vlan_interface", "")
      )
    end
  end
  deep_copy(configured_vlans)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File '../../src/modules/FcoeClient.rb', line 37

def main
  Yast.import "UI"
  textdomain "fcoe-client"

  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "Message"
  Yast.import "Stage"
  Yast.import "Mode"
  Yast.import "Package"
  Yast.import "Popup"
  Yast.import "Service"
  Yast.import "NetworkService"
  Yast.import "String"
  Yast.import "FileUtils"

  # Data

  # data modified?
  @modified = false

  # proposal valid?
  @proposal_valid = false

  # Number of retries for fipvlan (default is 20).
  # The number is reduced to 10 to make detection faster. 10 seconds (10 retries *
  # 1000 ms) should be enough time for most interfaces. If not there is the
  # possibility to retry interface dedection using 'Retry'.
  @number_of_retries = "10"

  # Write only, used during autoinstallation.
  # Don't run services and SuSEconfig, it's all done at one place.
  @write_only = false


  @test_mode = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = fun_ref(method(:Modified), "boolean ()")

  #   from IscsiClientLib.ycp (line 53) - reading output
  #
  #   string from_bios = ((map<string, any>)SCR::Execute(.target.bash_output, "iscsiadm -m fw"))["stdout"]:"";
  #   foreach(string row, splitstring(from_bios, "\n"), {
  #   list<string> key_val=splitstring(row, "=");
  # //   if (size(key_val[0]:"")>0) ibft[key_val[0]:""] = key_val[1]:"";
  #    string kv = String::CutBlanks(key_val[0]:"");
  #    if (size(kv) > 0) ibft[kv] = String::CutBlanks(key_val[1]:"");
  #    });


  # Define all the variables necessary to hold

  @current_card = 0 # currently selected card, means row in list of cards

  @NOT_CONFIGURED = "not configured"
  @NOT_AVAILABLE = "not available"

  @lldpad_started = false # service fcoe was started
  @fcoe_started = false # service lldpad was started


  # Settings: Define all variables needed for configuration of fcoe-client

  # map containing information about values in /etc/fcoe/config
  @fcoe_general_config = { "DEBUG" => "no", "USE_SYSLOG" => "yes" }

  # list containing information about commands to revert changes
  @revert_list = []

  # map containing information about start of services at boot
  @service_start = { "fcoe" => true, "lldpad" => true }

  # list of maps containing information about networks cards and VLAN, FCoE and DCB status
  @network_interfaces = []

  FcoeClient()
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



139
140
141
142
# File '../../src/modules/FcoeClient.rb', line 139

def Modified
  Builtins.y2debug("get modified = %1", @modified)
  @modified
end

- (Object) Overview

Create an overview table with all configured cards

Returns:

  • table items



1543
1544
1545
1546
# File '../../src/modules/FcoeClient.rb', line 1543

def Overview
  # TODO FIXME: your code here...
  []
end

- (Boolean) PollAbort

Checks whether an Abort button has been pressed. If so, calls function to confirm the abort call.

Returns:

  • (Boolean)

    true if abort confirmed



190
191
192
193
194
195
196
197
# File '../../src/modules/FcoeClient.rb', line 190

def PollAbort
  # Do not check UI when running in CommandLine mode
  return false if Mode.commandline

  return Abort() if UI.PollInput == :abort

  false
end

- (Object) ProbeNetcards

Detect network interface cards (hardware probe)



777
778
779
780
781
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
# File '../../src/modules/FcoeClient.rb', line 777

def ProbeNetcards
  if !TestMode()
    netcards = Convert.convert(
      SCR.Read(path(".probe.netcard")),
      :from => "any",
      :to   => "list <map>"
    )
  else  # test data
    netcards = [
      {
        "bus"       => "PCI",
        "bus_hwcfg" => "pci",
        "class_id"  => 2,
        "dev_name"  => "eth1",
        "dev_names" => ["eth1"],
        "device"    => "TEST Ethernet Controller",
        "model"     => "Intel PRO/1000 MT Desktop Adapter",
        "resource"  => { "hwaddr" => [{ "addr" => "08:00:27:11:64:e4" }] }
      },
      {
        "bus"       => "PCI",
        "bus_hwcfg" => "pci",
        "class_id"  => 2,
        "dev_name"  => "eth15",
        "dev_names" => ["eth15"],
        "device"    => "TEST Gigabit Ethernet Controller",
        "model"     => "Intel PRO/1000 MT Desktop Adapter",
        "resource"  => { "hwaddr" => [{ "addr" => "08:23:27:11:64:78" }] }
      },
      {
        "bus"       => "PCI",
        "bus_hwcfg" => "pci",
        "class_id"  => 2,
        "dev_name"  => "eth2",
        "dev_names" => ["eth2"],
        "model"     => "Intel PRO/1000 MT Desktop Adapter",
        "resource"  => { "hwaddr" => [{ "addr" => "08:23:27:99:64:78" }] }
      }
    ]
  end
  Builtins.y2milestone("Detected netcards: %1", netcards)

  netcards
end

- (Object) ProposalValid



152
153
154
# File '../../src/modules/FcoeClient.rb', line 152

def ProposalValid
  @proposal_valid
end

- (Object) Read

Read all fcoe-client settings

Returns:

  • true on success



1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
# File '../../src/modules/FcoeClient.rb', line 1255

def Read
  # FcoeClient read dialog caption
  caption = _("Initializing fcoe-client Configuration")

  # Set the right number of stages
  steps = 4

  sl = 500
  Builtins.sleep(sl)

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/3
      _("Check installed packages"),
      # Progress stage 2/3
      _("Check services"),
      # Progress stage 3/3
      _("Detect network cards"),
      # Progress stage 4/4
      _("Read /etc/fcoe/config")
    ],
    [
      # Progress step 1/3
      _("Checking for installed packages..."),
      # Progress step 2/3
      _("Checking for services..."),
      # Progress step 3/3
      _("Detecting network cards..."),
      # Progress step 4/4
      _("Reading /etc/fcoe/config"),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # a check for running network services doesn't make sense (is not needed), the
  # interfaces are set up in FcoeClient::GetVlanInterfaces()

  return false if PollAbort()
  Progress.NextStage

  # checking whether fcoe-utils is installed (requires lldpad, ...)
  installed = CheckInstalledPackages()

  # Error message
  return false if !installed
  Builtins.sleep(sl)

  # read current settings
  return false if PollAbort()
  Progress.NextStage

  # check whether auto start of daemon fcoemon and lldpad is enabled or not
  DetectStartStatus()
  # check whether fcoe and lldpad are running and start services if required
  start_status = ServiceStatus()

  # Error message
  Report.Error(_("Starting of services failed.")) if !start_status
  Builtins.sleep(sl)

  return false if PollAbort()
  Progress.NextStage

  # detect netcards
  @network_interfaces = DetectNetworkCards(ProbeNetcards())

  # Error message
  Report.Warning(_("Cannot detect devices.")) if @network_interfaces.empty?
  Builtins.sleep(sl)

  return false if PollAbort()
  Progress.NextStage

  # read general FCoE settings
  success = ReadFcoeConfig()

  # Error message
  Report.Error(_("Cannot read /etc/fcoe/config.")) if !success
  Builtins.sleep(sl)

  Progress.Finish

  return false if PollAbort()
  # modified = false is from CWM template
  @modified = false

  true
end

- (Object) ReadFcoeConfig

Read /etc/fcoe/config



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
# File '../../src/modules/FcoeClient.rb', line 962

def ReadFcoeConfig
  options = SCR.Dir(path(".fcoe.config"))
  Builtins.y2milestone("List of options in /etc/fcoe/config: %1", options)

  return false if options == [] || options == nil

  debug_val = Convert.to_string(
    SCR.Read(Builtins.add(path(".fcoe.config"), "DEBUG"))
  )
  @fcoe_general_config = Builtins.add(
    @fcoe_general_config,
    "DEBUG",
    debug_val
  )

  syslog_val = Convert.to_string(
    SCR.Read(Builtins.add(path(".fcoe.config"), "USE_SYSLOG"))
  )
  @fcoe_general_config = Builtins.add(
    @fcoe_general_config,
    "USE_SYSLOG",
    syslog_val
  )

  Builtins.y2milestone(
    "/etc/fcoe/config read: DEBUG: %1, USE_SYSLOG: %2",
    debug_val,
    syslog_val
  )

  true
end

- (Object) ResetNetworkCards

Reset list of detected cards



259
260
261
262
263
# File '../../src/modules/FcoeClient.rb', line 259

def ResetNetworkCards
  @network_interfaces = []

  nil
end

- (Object) ResetRevertCommands

Reset list of revert commands



225
226
227
228
229
# File '../../src/modules/FcoeClient.rb', line 225

def ResetRevertCommands
  @revert_list = []

  nil
end

- (Object) RestartServiceFcoe

restart service fcoe



1244
1245
1246
1247
1248
1249
1250
1251
# File '../../src/modules/FcoeClient.rb', line 1244

def RestartServiceFcoe
  ret = true

  Builtins.y2milestone("Restarting fcoe")
  ret = Service.Restart("boot.fcoe")

  ret
end

- (Object) ServiceStatus

Check status of services 'fcoe' and 'lldpad' and start them if required



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
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
# File '../../src/modules/FcoeClient.rb', line 705

def ServiceStatus
  success = true

  # Loading of modules in Stage::initial() is not required (like in IsciClientLib.ycp, line 523 )
  # see /etc/init.d/fcoe, line 85 (modprobe fcoe > /dev/null 2>&1)
  ret = true

  # first start lldpad
  if Service.Status("boot.lldpad") != 0
    success = Service.Start("boot.lldpad")
    if success
      Builtins.y2milestone("Lldpad started (/etc/init.d/boot.lldpad start)")
      @lldpad_started = true
    else
      Builtins.y2error(
        "Cannot start service lldpad - '/etc/init.d/boot.lldpad start' failed"
      )
      Report.Error(
        "Cannot start service lldpad.\n'/etc/init.d/boot.lldpad start' failed"
      )
      ret = false
    end
  else
    Builtins.y2milestone("Lldpad service is running")
  end

  if Service.Status("boot.fcoe") != 0
    success = Service.Start("boot.fcoe")

    if success
      Builtins.y2milestone("FCoE started (/etc/init.d/boot.fcoe start)")
      @fcoe_started = true
    else
      Builtins.y2error(
        "Cannot start FCoE service - '/etc/init.d/boot.fcoe start' failed"
      )
      Report.Error(
        "Cannot start FCoE service.\n'/etc/init.d/boot.fcoe start' failed"
      )
      ret = false
    end
  else
    Builtins.y2milestone("FCoE service is running")
  end

  ret
end

- (Object) SetAbortFunction(function)



179
180
181
182
183
184
# File '../../src/modules/FcoeClient.rb', line 179

def SetAbortFunction(function)
  function = deep_copy(function)
  @AbortFunction = deep_copy(function)

  nil
end

- (Object) SetFcoeConfigValue(param, value)

Set value in fcoe_general_config



200
201
202
203
204
# File '../../src/modules/FcoeClient.rb', line 200

def SetFcoeConfigValue(param, value)
  Ops.set(@fcoe_general_config, param, value)

  nil
end

- (Object) SetModified(value)

Mark as modified, for Autoyast.



145
146
147
148
149
150
# File '../../src/modules/FcoeClient.rb', line 145

def SetModified(value)
  Builtins.y2debug("set modified to %1", value)
  @modified = value

  nil
end

- (Object) SetNetworkCards(netcards)



251
252
253
254
255
256
# File '../../src/modules/FcoeClient.rb', line 251

def SetNetworkCards(netcards)
  netcards = deep_copy(netcards)
  @network_interfaces = deep_copy(netcards)

  nil
end

- (Object) SetNetworkCardsValue(row, card)

Set network card values for given row



244
245
246
247
248
249
# File '../../src/modules/FcoeClient.rb', line 244

def SetNetworkCardsValue(row, card)
  card = deep_copy(card)
  Ops.set(@network_interfaces, row, card)

  nil
end

- (Object) SetProposalValid(value)



156
157
158
159
160
# File '../../src/modules/FcoeClient.rb', line 156

def SetProposalValid(value)
  @proposal_valid = value

  nil
end

- (Object) SetStartStatus(service, status)

Set status of services



674
675
676
677
678
679
# File '../../src/modules/FcoeClient.rb', line 674

def SetStartStatus(service, status)
  Builtins.y2milestone("Starting service %1 on boot: %2", service, status)
  Ops.set(@service_start, service, status)

  nil
end

- (Object) SetWriteOnly(value)

Set write_only flag (for autoinstallation).



173
174
175
176
177
# File '../../src/modules/FcoeClient.rb', line 173

def SetWriteOnly(value)
  @write_only = value

  nil
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
# File '../../src/modules/FcoeClient.rb', line 1476

def Summary
  summary = ""
  fcoe_config = {}
  netcards = []
  service_start = {}

  # Configuration summary text for autoyast
  summary = Summary.AddLine(summary, _("<b>General FCoE configuration</b>"))
  fcoe_config = GetFcoeConfig()
  # options from config file, not meant for translation
  summary = Summary.AddLine(
    summary,
    Builtins.sformat("DEBUG: %1", Ops.get_string(fcoe_config, "DEBUG", ""))
  )
  summary = Summary.AddLine(
    summary,
    Builtins.sformat(
      "USE_SYSLOG: %1",
      Ops.get_string(fcoe_config, "USE_SYSLOG", "")
    )
  )
  summary = Summary.AddLine(summary, _("<b>Interfaces</b>"))
  netcards = GetNetworkCards()
  Builtins.foreach(netcards) do |card|
    summary = Summary.AddLine(
      summary,
      Builtins.sformat(
        "%1: %2 %3: %4",
        # network card, e.g. eth0
        _("<i>Netcard</i>:"),
        Ops.get_string(card, "dev_name", ""),
        # nothing to translate here (abbreviation for
        # Fibre Channel over Ethernet Virtual LAN interface)
        "<i>FCoE VLAN</i>",
        Ops.get_string(card, "fcoe_vlan", "")
      )
    )
  end
  service_start = GetStartStatus()
  summary = Summary.AddLine(summary, _("<b>Starting of services</b>"))

  # starting of service "fcoe" at boot time is enabled or disabled
  summary = Summary.AddLine(
    summary,
    Builtins.sformat(
      "fcoe: %1",
      Ops.get_boolean(service_start, "fcoe", false) ?
        _("enabled") :
        _("disabled")
    )
  )
  # starting of service "lldpad" at boot time is enabled or disabled
  summary = Summary.AddLine(
    summary,
    Builtins.sformat(
      "lldpad: %1",
      Ops.get_boolean(service_start, "lldpad", false) ?
        _("enabled") :
        _("disabled")
    )
  )

  [summary, []]
end

- (Object) TestMode

Returns true if test mode is set (environment variable FCOE_CLIENT_TEST_MODE)

Returns:

  • true if test mode is set (environment variable FCOE_CLIENT_TEST_MODE)



168
169
170
# File '../../src/modules/FcoeClient.rb', line 168

def TestMode
  @test_mode
end

- (Object) Write

Write all fcoe-client settings

Returns:

  • true on success



1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
# File '../../src/modules/FcoeClient.rb', line 1352

def Write
  # FcoeClient read dialog caption
  caption = _("Saving fcoe-client Configuration")
  Builtins.y2milestone("Saving fcoe-client Configuration")

  # Set the number of stages
  steps = 3

  sl = 500

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/2
      _("Write the settings"),
      # Progress stage 2/3
      _("Restart FCoE service"),
      # Progress stage 3/3
      _("Adjust start of services")
    ],
    [
      # Progress step 1/2
      _("Writing the settings..."),
      # Progress step 2/3
      _("Restarting FCoE service..."),
      # Progress sstep 3/3
      _("Adjusting start of services..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # iscsi-client prepares for AutoYaST in Mode::autoinst()/autoupgrade()
  # (see IscsiClient.ycp, line 236, 241)
  # These things are done in fcoe-client_auto.ycp (should be sufficient there)

  is_running = Progress.IsRunning
  Builtins.y2debug("**** Progress still running: %1", is_running)

  # write settings
  return false if PollAbort()
  Progress.NextStage

  success = WriteFcoeConfig()
  # Error message
  Report.Error(_("Cannot write settings to /etc/fcoe/config.")) if !success
  Builtins.sleep(sl)

  success = WriteCfgFiles()
  if !success
    Report.Error(
      _(
        "Cannot write settings for FCoE interfaces.\nFor details, see /var/log/YaST2/y2log."
      )
    )
  end

  return false if PollAbort()
  Progress.NextStage

  # restart fcoe to enable changes
  success = RestartServiceFcoe()
  # Error message
  Report.Error(_("Restarting of service fcoe failed.")) if !success
  Builtins.sleep(sl)

  # write ifcfg-files in /etc/sysconfig/network
  success = WriteSysconfigFiles()
  # Error message
  if !success
    Report.Error(_("Cannot write /etc/sysconfig/network/ifcfg-files."))
  end
  Builtins.sleep(sl)

  return false if PollAbort()
  Progress.NextStage

  # adjust start status of services lldpad and fcoe
  AdjustStartStatus()

  # Adding additional package (like in IscsiClient.ycp, line 257)
  # is done in inst_fcoe-client.ycp (PackagesProposal::AddResolvables)
  Builtins.sleep(sl)

  return false if PollAbort()

  true
end

- (Object) WriteCfgFiles

Write /etc/fcoe/cfg-ethx files using fcoe_cfg-ethx.scr



1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
# File '../../src/modules/FcoeClient.rb', line 1141

def WriteCfgFiles
  netcards = GetNetworkCards()

  success = false

  Builtins.foreach(netcards) do |card|
    if Ops.get_string(card, "fcoe_vlan", "") != @NOT_AVAILABLE &&
        Ops.get_string(card, "fcoe_vlan", "") != @NOT_CONFIGURED
      command = ""
      output = {}

      Builtins.y2milestone(
        "Writing /etc/fcoe/cfg-%1",
        Ops.get_string(card, "cfg_device", "")
      )
      success = SCR.Write(
        Ops.add(
          Ops.add(
            path(".fcoe.cfg-ethx.value"),
            Ops.get_string(card, "cfg_device", "")
          ),
          "FCOE_ENABLE"
        ),
        Ops.get_string(card, "fcoe_enable", "no")
      )
      if !success
        Builtins.y2error(
          "Writing FCOE_ENABLE=%1 failed",
          Ops.get_string(card, "fcoe_enable", "no")
        )
      end
      success = SCR.Write(
        Ops.add(
          Ops.add(
            path(".fcoe.cfg-ethx.value"),
            Ops.get_string(card, "cfg_device", "")
          ),
          "DCB_REQUIRED"
        ),
        Ops.get_string(card, "dcb_required", "no")
      )
      if !success
        Builtins.y2error(
          "Writing DCB_REQUIRED=%1 failed",
          Ops.get_string(card, "dcb_required", "no")
        )
      end
      success = SCR.Write(
        Ops.add(
          Ops.add(
            path(".fcoe.cfg-ethx.value"),
            Ops.get_string(card, "cfg_device", "")
          ),
          "AUTO_VLAN"
        ),
        Ops.get_string(card, "auto_vlan", "no")
      )
      if !success
        Builtins.y2error(
          "Writing AUTO_VLAN=%1 failed",
          Ops.get_string(card, "auto_vlan", "no")
        )
      end
      if Ops.get_string(card, "dcb_required", "no") == "yes"
        # enable DCB on the interface
        command = Builtins.sformat(
          "dcbtool sc %1 dcb on",
          Ops.get_string(card, "dev_name", "")
        )
        Builtins.y2milestone("Executing command: %1", command)
        output = Convert.to_map(
          SCR.Execute(path(".target.bash_output"), command)
        )
        Builtins.y2milestone("Output: %1", output)
        if Ops.get_integer(output, "exit", 255) != 0
          # only warning, not necessarily an error
          Builtins.y2warning("Command: %1 failed", command)
        end
        # enable App:FCoE on the interface
        command = Builtins.sformat(
          "dcbtool sc %1 app:0 e:1 a:1 w:1",
          Ops.get_string(card, "dev_name", "")
        )
        Builtins.y2milestone("Executing command: %1", command)

        output = Convert.to_map(
          SCR.Execute(path(".target.bash_output"), command)
        )
        Builtins.y2milestone("Output: %1", output)
        if Ops.get_integer(output, "exit", 255) != 0
          # only warning, not necessarily an error
          Builtins.y2warning("Command: %1 failed", command)
        end
      end
    end
  end
  # This is very important- it flushes the cache, and stores the configuration on the disk
  success = SCR.Write(path(".fcoe.cfg-ethx"), nil)

  success
end

- (Object) WriteFcoeConfig

Write /etc/fcoe/config using fcoe_config.scr



998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
# File '../../src/modules/FcoeClient.rb', line 998

def WriteFcoeConfig
  success = SCR.Write(
    Builtins.add(path(".fcoe.config"), "DEBUG"),
    Ops.get(GetFcoeConfig(), "DEBUG", "")
  )
  return false if !success

  success = SCR.Write(
    Builtins.add(path(".fcoe.config"), "USE_SYSLOG"),
    Ops.get(GetFcoeConfig(), "USE_SYSLOG", "")
  )
  return false if !success

  # This is very important- it flushes the cache, and stores the configuration on the disk
  success = SCR.Write(path(".fcoe.config"), nil)

  success
end

- (Object) WriteOnly

Returns true if module is marked as “write only” (don't start services etc…)

Returns:

  • true if module is marked as “write only” (don't start services etc…)



163
164
165
# File '../../src/modules/FcoeClient.rb', line 163

def WriteOnly
  @write_only
end

- (Object) WriteSysconfigFiles

Write ifcfg-files in /etc/sysconfig/network (for FCoE VLAN interface and underlying interface) using network.scr from yast2/library/network



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
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
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
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
# File '../../src/modules/FcoeClient.rb', line 1021

def WriteSysconfigFiles
  netcards = GetNetworkCards()
  success = true

  Builtins.foreach(netcards) do |card|
    if Ops.get_string(card, "fcoe_vlan", "") != @NOT_AVAILABLE &&
        Ops.get_string(card, "fcoe_vlan", "") != @NOT_CONFIGURED
      # write ifcfg-<if>.>VLAN> only if VLAN was created (not for VLAN = 0 which means
      # FCoE is started on the network interface itself)
      if Ops.get_string(card, "vlan_interface", "") != "0"
        Builtins.y2milestone(
          "Writing /etc/sysconfig/network/ifcfg-%1",
          Ops.get_string(card, "fcoe_vlan", "")
        )
        # write /etc/sysconfig/network/ifcfg-<fcoe-vlan-interface>, e.g. ifcfg-eth3.200
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "fcoe_vlan", "")
            ),
            "BOOTPROTO"
          ),
          "static"
        )
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "fcoe_vlan", "")
            ),
            "STARTMODE"
          ),
          "nfsroot"
        )
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "fcoe_vlan", "")
            ),
            "ETHERDEVICE"
          ),
          Ops.get_string(card, "dev_name", "")
        )
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "fcoe_vlan", "")
            ),
            "USERCONTROL"
          ),
          "no"
        )
      end
      ifcfg_file = Builtins.sformat(
        "/etc/sysconfig/network/ifcfg-%1",
        Ops.get_string(card, "dev_name", "")
      )
      Builtins.y2milestone("Writing %1", ifcfg_file)

      # write /etc/sysconfig/network/ifcfg-<interface> (underlying interface), e.g. ifcfg-eth3
      if !FileUtils.Exists(ifcfg_file)
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "dev_name", "")
            ),
            "BOOTPROTO"
          ),
          "static"
        )
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "dev_name", "")
            ),
            "STARTMODE"
          ),
          "nfsroot"
        )
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "dev_name", "")
            ),
            "NAME"
          ),
          Ops.get_string(card, "device", "")
        )
      else
        # don't overwrite BOOTPROTO !!!
        SCR.Write(
          Ops.add(
            Ops.add(
              path(".network.value"),
              Ops.get_string(card, "dev_name", "")
            ),
            "STARTMODE"
          ),
          "nfsroot"
        )
      end
    end
  end
  # This is very important- it flushes the cache, and stores the configuration on the disk
  success = SCR.Write(path(".network"), nil)
  if !success
    Builtins.y2error("Error writing /etc/sysconfig/network/ifcfg-files")
  end
  success
end