-
Notifications
You must be signed in to change notification settings - Fork 4
/
FcoeClient.rb
1733 lines (1497 loc) · 54.4 KB
/
FcoeClient.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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
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
213
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
260
261
262
263
264
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
423
424
425
426
427
428
429
430
431
432
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
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
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
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
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
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
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
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
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
821
822
823
824
825
826
827
828
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
942
943
944
945
946
947
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
# encoding: utf-8
# ------------------------------------------------------------------------------
# Copyright (c) 2006 Novell, Inc. All Rights Reserved.
#
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of version 2 of the GNU General Public License as published by the
# Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, contact Novell, Inc.
#
# To contact Novell about this file by physical or electronic mail, you may find
# current contact information at www.novell.com.
# ------------------------------------------------------------------------------
# File: modules/FcoeClient.ycp
# Package: Configuration of fcoe-client
# Summary: FcoeClient settings, input and output functions
# Authors: Gabriele Mohr <gs@suse.de>
#
#
# Representation of the configuration of fcoe-client.
# Input and output routines.
require "shellwords"
require "yast"
require "yast2/systemd/socket"
require "y2network/fcoe_conn_generator"
module Yast
class FcoeClientClass < Module
include Yast::Logger
FCOE_PKG_NAME = "fcoe-utils"
# Used by FcoeClientClass to keep data about an individual network interface
# (Not a real class; documents the structure of a Hash)
class Interface < Hash
# @!method [](k)
# I am not sure when the keys are present/absent :-/
# @option k [String] 'fcoe_vlan'
# "eth1.500-fcoe" or "not configured" or "not available"
# @option k [String] 'vlan_interface'
# "500", or "0" for no VLAN used; yes, the name is nonsense, should be "vid"
# @option k [String] 'dev_name' "eth1"
# @option k [String] 'auto_vlan' "yes" or "no"
# @option k [String] 'mac_addr' "00:11:22:33:44:55"
# @option k [String] 'fcoe_enable' "yes" or "no"
# @option k [String] 'dcb_required' "yes" or "no"
# @option k [String] 'dcb_capable' "yes" or "no"
# @option k [String] 'cfg_device' "eth1.500" or "" ???
# @option k [Boolean] 'fcoe_flag' fcoe offload
# @option k [Boolean] 'iscsi_flag' scsi offload
# @option k [Boolean] 'storage_only'
end
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"
Yast.import "Lan"
# 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 ()")
# 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 lldpad was started
@fcoe_started = false # service fcoe 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 = []
# systemd sockets
@fcoemon_socket = nil
@lldpad_socket = nil
FcoeClient()
end
# Constructor
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
def fcoemonSocketActive?
if @fcoemon_socket
@fcoemon_socket.active?
else
log.error("fcoemon.socket not found")
false
end
end
def fcoemonSocketStart
if @fcoemon_socket
@fcoemon_socket.start
else
log.error("fcoemon.socket not found")
false
end
end
def fcoemonSocketStop
if @fcoemon_socket
@fcoemon_socket.stop
else
log.error("fcoemon.socket not found")
false
end
end
def fcoemonSocketEnabled?
if @fcoemon_socket
@fcoemon_socket.enabled?
else
log.error("fcoemon.socket not found")
false
end
end
def fcoemonSocketDisabled?
if @fcoemon_socket
@fcoemon_socket.disabled?
else
log.error("fcoemon.socket not found")
false
end
end
def fcoemonSocketEnable
if @fcoemon_socket
@fcoemon_socket.enable
else
log.error("fcoemon.socket not found")
false
end
end
def fcoemonSocketDisable
if @fcoemon_socket
@fcoemon_socket.disable
else
log.error("fcoemon.socket not found")
false
end
end
def lldpadSocketActive?
if @lldpad_socket
@lldpad_socket.active?
else
log.error("lldpad.socket not found")
false
end
end
def lldpadSocketStart
if @lldpad_socket
@lldpad_socket.start
else
log.error("lldpad.socket not found")
false
end
end
def lldpadSocketStop
if @lldpad_socket
@lldpad_socket.stop
else
log.error("lldpad.socket not found")
false
end
end
def lldpadSocketEnabled?
if @lldpad_socket
@lldpad_socket.enabled?
else
log.error("lldpad.socket not found")
false
end
end
def lldpadSocketDisabled?
if @lldpad_socket
@lldpad_socket.disabled?
else
log.error("lldpad.socket not found")
false
end
end
def lldpadSocketEnable
if @lldpad_socket
@lldpad_socket.enable
else
log.error("lldpad.socket not found")
false
end
end
def lldpadSocketDisable
if @lldpad_socket
@lldpad_socket.disable
else
log.error("lldpad.socket not found")
false
end
end
# Abort function
# @return [Boolean] return true if abort
def Abort
return @AbortFunction.call == true if @AbortFunction != nil
false
end
# Data was modified?
# @return true if modified
def Modified
Builtins.y2debug("get modified = %1", @modified)
@modified
end
# Mark as modified, for Autoyast.
def SetModified(value)
Builtins.y2debug("set modified to %1", value)
@modified = value
nil
end
def ProposalValid
@proposal_valid
end
def SetProposalValid(value)
@proposal_valid = value
nil
end
# @return true if module is marked as "write only" (don't start services etc...)
def WriteOnly
@write_only
end
# @return true if test mode is set (environment variable FCOE_CLIENT_TEST_MODE)
def TestMode
@test_mode
end
# Set write_only flag (for autoinstallation).
def SetWriteOnly(value)
@write_only = value
nil
end
def SetAbortFunction(function)
function = deep_copy(function)
@AbortFunction = deep_copy(function)
nil
end
# Checks whether an Abort button has been pressed.
# If so, calls function to confirm the abort call.
#
# @return [Boolean] true if abort confirmed
def PollAbort
# Do not check UI when running in CommandLine mode
return false if Mode.commandline
return Abort() if UI.PollInput == :abort
false
end
# Set value in fcoe_general_config
def SetFcoeConfigValue(param, value)
Ops.set(@fcoe_general_config, param, value)
nil
end
# Returns the map containing general FCoE configuration
def GetFcoeConfig
deep_copy(@fcoe_general_config)
end
# Add a command to the list of revert commands
def AddRevertCommand(command)
@revert_list = Builtins.add(@revert_list, command)
Builtins.y2milestone("Adding revert command: %1", command)
nil
end
# Get the list of revert commands
def GetRevertCommands
deep_copy(@revert_list)
end
# Reset list of revert commands
def ResetRevertCommands
@revert_list = []
nil
end
# Returns the map containing all detected interfaces (possibly including
# several entries for a network interface if several VLAN interfaces are
# detected)
def GetNetworkCards
deep_copy(@network_interfaces)
end
# Get currently selected network card
# @return [Interface]
def GetCurrentNetworkCard
Ops.get(@network_interfaces, @current_card, {})
end
# Set network card values for given row
def SetNetworkCardsValue(row, card)
card = deep_copy(card)
Ops.set(@network_interfaces, row, card)
nil
end
def SetNetworkCards(netcards)
netcards = deep_copy(netcards)
@network_interfaces = deep_copy(netcards)
nil
end
# Reset list of detected cards
def ResetNetworkCards
@network_interfaces = []
nil
end
#
# Check whether fcoe-utils is installed and do installation if user agrees
# (dependencies: 'open-lldp', 'libhbalinux2' and 'libHBAAPI2')
#
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
#
# Check whether/which VLAN interfaces are configured for FCoE on the switch
# (by calling command 'fipvlan').
# @example
# $ fipvlan eth0 eth1 eth2 eth3
# Fibre Channel Forwarders Discovered\n
# interface | VLAN | FCF MAC\n
# ------------------------------------------\n
# eth0 | 200 | 00:0d:ec:a2:ef:00\n
# eth3 | 200 | 00:0d:ec:a2:ef:01\n
#
# @param [List] net_devices detected network cards
# @return [List] information about FcoE VLAN interfaces
#
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 /usr/sbin/fipvlan -u"
if !Mode.autoinst
vlan_cmd << " -l #{@number_of_retries.to_s.shellescape}"
end # reduce number of retries
Builtins.foreach(net_devices) { |dev| vlan_cmd << " #{dev.shellescape}" }
# 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" +
"eth1 | 500 |57:9f:ea:08:34:78\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
#
# Provide information about FCoE capable VLAN interfaces for each network card
#
# @param [List] net_devices network cards
# @param [List] fcoe_info information about FCoE VLAN interfaces
# @return [Hash] assorted FCoE info per network card
#
# @example
# 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" }]
# }
#
def GetVlanInterfaces(net_devices, fcoe_info)
vlan_info = {}
net_devices.each { |dev| fcoe_info.each do |line|
# Check whether there is a line for the given interface, e.g.
# eth3 | 200 | 00:0d:ec:a2:ef:00\n
line.delete!(" \t")
columns = line.split("|")
if columns[0] == dev
vlan_interface = {"vlan" => columns[1] || "", "fcf" => columns[2] || ""}
log.info "Interface: #{dev} VLAN: #{columns[1]} FCF: #{columns[2]}"
vlans = vlan_info[dev] || []
# Do not add entries with identical VLAN IDs (bsc#988050).
# The FCF MAC adress might be identical. It's the address which
# can be reached via the FCoE interface and it's possible to
# reach same FCF MAC address from different VLANs.
if vlans.find_index do |vlan|
(vlan["vlan"] || "") == (vlan_interface["vlan"] || "")
end == nil
vlans << vlan_interface
end
# Check for VLAN ID "0" which is treated special:
# if there are other VLANs with the same FCF MAC address,
# only the "0" ID should be in the list (bnc #813621, comment #4)
fcf_zero = ""
vlans.each do |vlan|
if vlan["vlan"] == "0"
fcf_zero = vlan["fcf"] || ""
end
end
if !fcf_zero.empty?
vlans.delete_if { |vlan| (vlan["fcf"] == fcf_zero) &&
(vlan["vlan"] != "0") }
end
vlan_info[dev] = vlans
end
end }
log.info "VLAN info: #{vlan_info}"
vlan_info
end
#
# Check whether the VLAN device is created (check entries in /proc/net/vlan/config)
#
# @param [String] interface network interface card, e.g. eth3
# @param [String] vlan_interface Vlan Interface configured for FCoE (on switch)
# @return [String] Vlan device name, e.g. eth3.200
#
# # cat /proc/net/vlan/config
#VLAN Dev name | VLAN ID
#Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
#eth3.200 | 200 | eth3
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(
"/usr/bin/sed -n 's/\\([^ ]*\\) *.*'%1'*.*'%2'/\\1/p' /proc/net/vlan/config",
vlan_interface.shellescape,
interface.shellescape
)
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
#
# Create /etc/fcoe/cfg-<if> or /etc/fcoe/cfg-<if>.<vlan>
# (depending on AUTO_VLAN setting)
#
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("/usr/bin/rm %1", file_name.shellescape))
# 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
#
# Get status of FCoE config from /etc/fcoe/cfg-<if>.<vlan> or /etc/fcoe/cfg-<if>
#
def GetFcoeStatus(vlan_device_name, device_name)
status_map = {}
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
#
# Check whether the network interface (netcard, e.g. eth0 is DCB capable)
#
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 /usr/sbin/dcbtool gc %1 dcb", netcard.shellescape)
Builtins.y2milestone("Executing command: %1", command)
output = 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
#
# Set start status of 'fcoemon' and 'lldpad' sockets
#
# 'Service' tab is only shown in installed system where
# sockets (and systemd) are available.
#
def AdjustStartStatus
fcoe_start = Ops.get(@service_start, "fcoe", false)
lldpad_start = Ops.get(@service_start, "lldpad", false)
Builtins.y2milestone(
"Setting start of fcoe to %1",
fcoe_start
)
Builtins.y2milestone(
"Setting start of lldpad to %1",
lldpad_start
)
# enable/disable services and sockets as required
if fcoe_start && lldpad_start
lldpadSocketEnable # enable 'lldpad' first
Service.Enable("lldpad")
fcoemonSocketEnable
Service.Enable("fcoe")
elsif !fcoe_start && lldpad_start
fcoemonSocketDisable
Service.Disable("fcoe")
lldpadSocketEnable
Service.Enable("lldpad")
elsif !fcoe_start && !lldpad_start
fcoemonSocketDisable # disable 'fcoe' first
Service.Disable("fcoe")
lldpadSocketDisable
Service.Disable("lldpad")
end
# fcoe_start && !lldpad_start isn't possible -> see complex.ycp StoreServicesDialog
nil
end
#
# Set status of services
#
def SetStartStatus(service, status)
Builtins.y2milestone("Starting service %1 on boot: %2", service, status)
Ops.set(@service_start, service, status)
nil
end
#
# Get status of services
#
def DetectStartStatus
status = false
status = fcoemonSocketEnabled?
Builtins.y2milestone("Start status of fcoe: %1", status)
@service_start = Builtins.add(@service_start, "fcoe", status)
status = lldpadSocketEnabled?
Builtins.y2milestone("Start status of lldpad: %1", status)
@service_start = Builtins.add(@service_start, "lldpad", status)
nil
end
def GetStartStatus
deep_copy(@service_start)
end
#
# Check status of services 'fcoe' and 'lldpad' and start them if required
#
def ServiceStatus
success = true
# Loading of modules in Stage::initial() is not required
# (like done in IscsiClientLib)
# SLES11 SP3: /etc/init.d/boot.fcoe, line 86
# (modprobe $SUPPORTED_DRIVERS > /dev/null 2>&1)
# SUPPORTED_DRIVERS from /etc/fcoe/config
# SLES12: Service.Start in inst-sys uses '/bin/service_start' to run
# commands from /usr/lib/systemd/system/fcoe.service
# (including modprobe)
ret = true
# start services during installation
if Stage.initial
# start service lldpad first
@lldpad_started = Service.Start("lldpad")
if @lldpad_started
log.info("Service lldpad started")
else
log.error("Cannot start service lldpad")
Report.Error(_("Cannot start service 'lldpad'"))
ret = false
end
@fcoe_started = Service.Start("fcoe")
if @fcoe_started
log.info("Service fcoe started")
else
log.error("Cannot start service fcoe")
Report.Error(_("Cannot start service 'fcoe'"))
ret = false
end
return ret
end
# start sockets in installed system
# throw exception if sockets not found
@fcoemon_socket = Yast2::Systemd::Socket.find!("fcoemon")
@lldpad_socket = Yast2::Systemd::Socket.find!("lldpad")
# first start lldpad
if !lldpadSocketActive?
success = lldpadSocketStart
if success
log.info("lldpad.socket started")
@lldpad_started = true
else
log.error("Cannot start lldpad.socket")
Report.Error(_("Cannot start lldpad systemd socket"))
ret = false
end
else
log.info("lldpad.socket is already active")
end
if lldpadSocketActive? && (Service.Status("lldpad") != 0)
success = Service.Start("lldpad")
if success
log.info("lldpad service started")
else
log.error( "Cannot start lldpad service")
Report.Error(_("Cannot start lldpad service."))
ret = false
end
end
if !fcoemonSocketActive?
success = fcoemonSocketStart
if success
log.info("fcoemon.socket started")
@fcoe_started = true
else
log.error( "Cannot start fcoemon.socket")
Report.Error(_("Cannot start fcoemon systemd socket."))
ret = false
end
else
log.info("fcoemon.socket is already active")
end
if fcoemonSocketActive? && (Service.Status("fcoe") != 0)
success = Service.Start("fcoe")
if success
log.info("fcoe service started")
else
log.error( "Cannot start fcoe service")
Report.Error(_("Cannot start fcoe service."))
ret = false
end
end
ret
end
#
# Check whether there are configured FCoE VLANs for the given network interface
# Return list of configured VLANs
# @param device_name [String] "eth1"
# @return [Array<String>] ["200", "300"]
def IsConfigured(device_name)
configured_vlans = []
interfaces = GetNetworkCards()
Builtins.foreach(interfaces) do |interface|
if device_name == interface.fetch("dev_name", "") && fcoe_vlan?(interface)
configured_vlans = Builtins.add(
configured_vlans,
Ops.get_string(interface, "vlan_interface", "")
)
end
end
deep_copy(configured_vlans)
end
# Detect network interface cards (hardware probe)
# @return [Array<Hash>] .probe.netcard output
# (except the items without dev_name)
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" }] },
"driver" => "bnx2x",
"fcoeoffload" => true,
"iscsioffload" => false,
"storageonly" => true
},
{
"bus" => "PCI",
"bus_hwcfg" => "pci",
"class_id" => 2,
"dev_name" => "eth15",
"dev_names" => ["eth15"],
"driver" => "bnx2x",
"fcoeoffload" => false,