-
Notifications
You must be signed in to change notification settings - Fork 4
/
FcoeClient.ycp
1265 lines (1080 loc) · 37.1 KB
/
FcoeClient.ycp
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
/* ------------------------------------------------------------------------------
* 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.
*/
{
module "FcoeClient";
textdomain "fcoe-client";
import "Progress";
import "Report";
import "Summary";
import "Message";
import "Stage";
import "Mode";
import "Package";
import "Popup";
import "Service";
import "NetworkService";
import "String";
import "FileUtils";
/**
* Prototypes
*/
global boolean Modified();
/**
* Data was modified?
*/
boolean modified = false;
/**
*/
boolean proposal_valid = false;
/**
* Write only, used during autoinstallation.
* Don't run services and SuSEconfig, it's all done at one place.
*/
boolean write_only = false;
/**
*/
boolean test_mode = false;
/**
* Constructor
*/
global void FcoeClient()
{
if ( getenv("FCOE_CLIENT_TEST_MODE") == "1" )
{
y2milestone( "Running in test mode" );
test_mode = true;
}
else
{
test_mode = false;
}
}
/**
* Abort function
* return boolean return true if abort
*/
boolean() AbortFunction = Modified;
/**
* Abort function
* @return boolean return true if abort
*/
global define boolean Abort() ``{
if(AbortFunction != nil)
{
return AbortFunction () == true;
}
return false;
}
/**
* Data was modified?
* @return true if modified
*/
global boolean Modified() {
y2debug( "get modified = %1", modified );
return modified;
}
/**
* Mark as modified, for Autoyast.
*/
global void SetModified(boolean value) {
y2debug( "set modified to %1", value );
modified = value;
}
global boolean ProposalValid() {
return proposal_valid;
}
global void SetProposalValid(boolean value) {
proposal_valid = value;
}
/**
* @return true if module is marked as "write only" (don't start services etc...)
*/
global boolean WriteOnly() {
return write_only;
}
/**
* @return true if test mode is set (environment variable FCOE_CLIENT_TEST_MODE)
*/
global boolean TestMode()
{
return test_mode;
}
/**
* Set write_only flag (for autoinstallation).
*/
global void SetWriteOnly(boolean value) {
write_only = value;
}
global void SetAbortFunction(boolean() function) {
AbortFunction = function;
}
/**
* Checks whether an Abort button has been pressed.
* If so, calls function to confirm the abort call.
*
* @return boolean true if abort confirmed
*/
global boolean PollAbort() {
// Do not check UI when running in CommandLine mode
if (Mode::commandline())
return false;
if (UI::PollInput() == `abort)
return Abort();
return false;
}
/*
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
global integer current_card = 0; // currently selected card, means row in list of cards
global string NOT_CONFIGURED = "not configured";
global string NOT_AVAILABLE = "not available";
global boolean lldpad_started = false; // service fcoe was started
global boolean 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
map <string, string> fcoe_general_config = $[ "DEBUG":"no",
"USE_SYSLOG":"yes" ];
// Set value in fcoe_general_config
global void SetFcoeConfigValue( string param, string value )
{
fcoe_general_config[ param ] = value;
}
// Returns the map containing general FCoE configuration
global map <string, string> GetFcoeConfig()
{
return fcoe_general_config;
}
// list containing information about commands to revert changes
list <string> revert_list = [];
// Add a command to the list of revert commands
global void AddRevertCommand( string command )
{
revert_list = add( revert_list, command );
y2milestone( "Adding revert command: %1", command );
}
// Get the list of revert commands
global list GetRevertCommands()
{
return revert_list;
}
// Reset list of revert commands
global void ResetRevertCommands()
{
revert_list = [];
}
// map containing information about start of services at boot
map <string, boolean> service_start = $[ "fcoe":true,
"lldpad":true ];
// map containing information about networks cards and VLAN, FCoE and DCB status
list <map> network_interfaces = [];
// Returns the map containing all detected interfaces including
global list <map> GetNetworkCards()
{
return network_interfaces;
}
// Get currently selected network card
global map GetCurrentNetworkCard()
{
return network_interfaces[current_card]:$[];
}
// Set network card values for given row
global void SetNetworkCardsValue( integer row, map card )
{
network_interfaces[row] = card;
}
global void SetNetworkCards( list<map> netcards )
{
network_interfaces = netcards;
}
// Reset list of detected cards
global void ResetNetworkCards()
{
network_interfaces = [];
}
//
// Check whether open-fcoe is installed and do installation if user agrees
// (dependencies: 'lldpad', 'libhbalinux2' and 'libHBAAPI2')
//
boolean CheckInstalledPackages()
{
boolean 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
if(Stage::cont() || Stage::initial() || Mode::config()) return true;
y2milestone("Check if open-fcoe package installed");
if( !Package::InstallMsg( "open-fcoe",
_("<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;
}
return ret;
}
//
// Check whether VLAN interfaces are configured for FCoE on the switch
//
// Params:
// string interface network interface card, e.g. eth3
// Return:
// string Vlan interface number, e.g. 200
// Example:
// # fipvlan eth0 eth1 eth2 eth3
//Fibre Channel Forwarders Discovered
//interface | VLAN | FCF MAC
//------------------------------------------
//eth0 | 200 | 00:0d:ec:a2:ef:00
//eth3 | 200 | 00:0d:ec:a2:ef:01
//
global map GetVlanInterfaces( list net_devices )
{
// Add option -u (or --link_up): don't shut down interfaces
// to be able to detect DCB state afterwards (see bnc #737683)
string vlan_cmd = "LANG=POSIX fipvlan -u";
map vlan_info = $[];
foreach ( string dev, (list<string>)net_devices, {
vlan_cmd = vlan_cmd + " " + dev;
} );
// call fipvlan command for all interfaces (saves time because is executed in parallel)
y2milestone( "Executing command: %1", vlan_cmd );
map output = (map)SCR::Execute( .target.bash_output, vlan_cmd );
y2milestone( "Output: %1", output );
list <string> lines = [];
if ( !TestMode() )
{
lines = splitstring( output["stdout"]:"", "\n" );
}
else // test data
{
lines = splitstring("Fibre Channel Forwarders
< Discovered\ninterface | VLAN | FCF MAC
< \n------------------------------------------\neth15 | 2011 |54:7f:ee:04:55:9f\neth15 | 0 | 54:7f:ee:04:55:9f\neth15 | 200 | 54:7f:ee:04:55:9f\neth1 | 301 |54:7f:ee:04:55:9f\neth1 | 400 |54:7f:ee:04:55:9f\n\n", "\n");
}
foreach ( string dev, (list<string>)net_devices, {
foreach( string line, (list<string>)lines, {
// check whether there is a line for the given interface, e.g.
// eth3 | 200 | 00:0d:ec:a2:ef:00\n
// and get VLAN channel from second columns.
line = deletechars( line, " \t" );
list<string> columns = splitstring( line, "|" );
if ( columns[0]:"" == dev )
{
string vlan_interface = columns[1]:"";
y2milestone( "Interface: %1 VLAN: %2", dev, vlan_interface );
// overwrite existing entry if VLAN = 0 is found (see bnc #813621)
if ( vlan_info[dev]:"" == "" || vlan_interface == "0" )
{
vlan_info = add( vlan_info, dev, vlan_interface );
}
}
} );
} );
y2milestone( "VLAN info: %1", vlan_info );
return vlan_info;
}
//
// Check whether the VLAN device is created (check entries in /proc/net/vlan/config)
//
// Params:
// string interface network interface card, e.g. eth3
// string vlan_interface Vlan Interface configured for FCoE (on switch)
// Return:
// string Vlan device name, e.g. eth3.200
// Example:
// # cat /proc/net/vlan/config
//VLAN Dev name | VLAN ID
//Name-Type: VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD
//eth3.200 | 200 | eth3
global string GetFcoeVlanInterface ( string interface, string vlan_interface )
{
string vlan_device_name = "";
if ( TestMode() )
return interface + "." + vlan_interface;
string command = sformat( "sed -n 's/\\([^ ]*\\) *.*%1*.*%2/\\1/p' /proc/net/vlan/config",
vlan_interface, interface );
y2milestone( "Executing command: %1", command );
map output = (map)SCR::Execute( .target.bash_output, command );
y2milestone( "Output: %1", output );
// read stdout (remove \n and white spaces)
vlan_device_name = deletechars( output["stdout"]:"", " \n\t" );
if ( vlan_device_name != "" )
{
y2milestone( "Returning: %1", vlan_device_name );
}
else
{
y2error( "FCoE VLAN not found in /proc/net/vlan/config" );
}
return vlan_device_name;
}
//
// Create /etc/fcoe/cfg-<if> or /etc/fcoe/cfg-<if>.<vlan>
// (depending on AUTO_VLAN setting)
//
global void CreateFcoeConfig( string vlan_device_name, map netcard )
{
string file_name = "";
boolean file_exists = false;
// if AUTO_VLAN is set to "yes" or VLAN is set to "0" (means no VLAN created but FCoE started on device)
if ( netcard["auto_vlan"]:"no" == "yes" || netcard["vlan_interface"]:"" == "0" )
{
// set file name to cfg-<interface>, e.g. /etc/fcoe/cfg-eth3
file_name = sformat( "/etc/fcoe/cfg-%1", netcard["dev_name"]:"" );
}
else
{
// set file name to cfg-<vlan_device_name>, e.g. /etc/fcoe/cfg-eth3.200
file_name = sformat( "/etc/fcoe/cfg-%1", vlan_device_name );
}
// read default values
string content = (string)SCR::Read( .target.string, "/etc/fcoe/cfg-ethx" );
// and prepare content
if ( content != "" && content != nil )
{
list <string> lines = (list<string>)splitstring( content, "\n" );
lines = maplist( string line, lines, {
if ( !String::StartsWith( line, "#" ) ) line = deletechars( line, " \t" );
if ( String::StartsWith( line, "AUTO_VLAN" ) )
{
return sformat( "AUTO_VLAN=\"%1\"", netcard["auto_vlan"]:"no" );
}
else if ( String::StartsWith( line, "DCB_REQUIRED" ) )
{
return sformat( "DCB_REQUIRED=\"%1\"", netcard["dcb_required"]:"no" );
}
else if ( String::StartsWith( line, "FCOE_ENABLE" ) )
{
return sformat( "FCOE_ENABLE=\"%1\"", netcard["fcoe_enable"]:"yes" );
}
else
{
return line;
}
});
content = mergestring( lines, "\n" );
y2milestone( "Writing content: %1 to %2", content, file_name );
file_exists = SCR::Write( .target.string, file_name, content );
if ( file_exists )
{
AddRevertCommand( sformat( "rm %1", file_name ) );
}
else
{
y2error( "Cannot create %1", file_name );
}
}
else
{
y2error( "Cannot read /etc/fcoe/cfg-ethx" );
}
}
//
// Get status of FCoE config from /etc/fcoe/cfg-<if>.<vlan> or /etc/fcoe/cfg-<if>
//
global map <string, string> GetFcoeStatus( string vlan_device_name, string device_name )
{
map <string, string> status_map = $[];
string content = "";
boolean file_exists = false;
string file_name = "";
string device = vlan_device_name;
if ( vlan_device_name == "" || device_name == "" )
{
y2error( "Interface not valid" );
return $[];
}
y2milestone( "Checking configuration for %1", vlan_device_name );
file_name = sformat( "/etc/fcoe/cfg-%1", vlan_device_name );
if ( !FileUtils::Exists( file_name ) )
{
file_name = sformat( "/etc/fcoe/cfg-%1", device_name );
if ( !FileUtils::Exists( file_name ) )
{
// no config file found - return empty status map
return status_map;
}
device = device_name;
}
// for debugging purpose, read only needed values later
list values = SCR::Dir( .fcoe.cfg-ethx.value + device );
y2milestone( "Available values in %1: %2", file_name, values );
foreach( string var, ["FCOE_ENABLE", "DCB_REQUIRED", "AUTO_VLAN"], {
string value = (string)SCR::Read(.fcoe.cfg-ethx.value + device + var);
if ( value == nil )
{
y2warning( "Cannot read %1", var );
continue;
}
status_map = add( status_map, var, value );
});
status_map = add( status_map, "cfg_device", device );
y2milestone( "Returning: %1", status_map );
return status_map;
}
//
// Check whether the network interface (netcard, e.g. eth0 is DCB capable)
//
string DCBCapable( string netcard )
{
string ret = "no";
// 'lldpad' must be started to be able to use 'dcbtool'
// -> is started in ServiceStatus() ( called in Read() before DetectNetworkCards() )
string command = sformat( "LANG=POSIX dcbtool gc %1 dcb", netcard );
y2milestone( "Executing command: %1", command );
map output = (map)SCR::Execute( .target.bash_output, command );
y2milestone( "Output: %1", output);
string status = "";
if ( output["exit"]:255 == 0 )
{
list <string> lines = splitstring( output["stdout"]:"", "\n" );
foreach( string line, (list<string>)lines, {
if ( String::StartsWith( line, "Status" ) )
{
// Status: Failed interface not DCB capable
// Status: Successful
line = deletechars ( line, " \t:" );
status = substring( line, 6 );
y2milestone( "Status: %1", status );
} } );
if ( status == "Successful" )
{
ret = "yes";
}
}
else
{
y2error( "Exit code: %1 Error: %2", output["exit"]:255, output["stderr"]:"" );
}
return ret;
}
//
// Set status of services
//
global void AdjustStartStatus( )
{
boolean fcoe_start = service_start["fcoe"]:false;
boolean lldpad_start = service_start["lldpad"]:false;
y2milestone( "Setting start of /etc/init.d/boot.fcoe to %1", fcoe_start );
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");
}
else if ( !fcoe_start && lldpad_start )
{
Service::Disable("boot.fcoe");
Service::Enable("boot.lldpad" );
}
else if ( !fcoe_start && !lldpad_start )
{
Service::Disable("boot.fcoe"); // disable 'fcoe' first
Service::Disable("boot.lldpad");
}
// fcoe_start && !lldpad_start isn't possible -> see complex.ycp StoreServicesDialog
}
//
// Set status of services
//
global void SetStartStatus( string service, boolean status )
{
y2milestone( "Starting service %1 on boot: %2", service, status );
service_start[ service ] = status;
}
//
// Get status of services
//
void DetectStartStatus()
{
boolean status = false;
status = Service::Enabled( "boot.fcoe" );
y2milestone( "Start status of fcoe: %1", status );
service_start = add( service_start, "fcoe", status );
status = Service::Enabled( "boot.lldpad" );
y2milestone( "Start status of lldpad: %1", status );
service_start = add( service_start, "lldpad", status );
}
global map<string, boolean> GetStartStatus()
{
return service_start;
}
//
// Check status of services 'fcoe' and 'lldpad' and start them if required
//
global boolean ServiceStatus()
{
boolean 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)
boolean ret = true;
// first start lldpad
if ( Service::Status( "boot.lldpad" ) != 0 )
{
success = Service::Start( "boot.lldpad" );
if ( success )
{
y2milestone( "Lldpad started (/etc/init.d/boot.lldpad start)");
lldpad_started = true;
}
else
{
y2error( "Cannot start service lldpad - '/etc/init.d/boot.lldpad start' failed" );
Report::Error( "Cannot start service lldpad.
'/etc/init.d/boot.lldpad start' failed" );
ret = false;
}
}
else
{
y2milestone( "Lldpad service is running");
}
if ( Service::Status( "boot.fcoe" ) != 0 )
{
success = Service::Start( "boot.fcoe" );
if ( success )
{
y2milestone( "FCoE started (/etc/init.d/boot.fcoe start)");
fcoe_started = true;;
}
else
{
y2error( "Cannot start FCoE service - '/etc/init.d/boot.fcoe start' failed" );
Report::Error( "Cannot start FCoE service.
'/etc/init.d/boot.fcoe start' failed" );
ret = false;
}
}
else
{
y2milestone( "FCoE service is running");
}
return ret;
}
// list <map> network_interfaces
//
// dev_name mac_addr device fcoe_vlan fcoe_enable dcb_required auto_vlan dcb_capable vlan_interface cfg_file
// eth3 08:00:... Gigabit... eth3.200 yes/no yes/no yes/no yes/no 200 eth3.200
//
// Detect network interface cards (hardware probe) and get status
//
global boolean DetectNetworkCards()
{
list <map> netcards = [];
if ( !TestMode() )
{
netcards = (list<map>)SCR::Read(.probe.netcard);
}
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"]]]] ];
}
y2milestone( "Detected netcards: %1", netcards );
if ( netcards == [] || netcards == nil )
return false;
list net_devices = [];
foreach ( map card, netcards, {
net_devices = add( net_devices, card["dev_name"]:"" );
});
// 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.
map vlan_info = GetVlanInterfaces( net_devices );
foreach ( map card, netcards, {
map info_map = $[];
map <string, string> status_map = $[];
string fcoe_vlan_interface = "";
string dcb_capable = "";
string dcb_default = "";
if ( vlan_info[card["dev_name"]:""]:"" == "" )
{
// Interface down or FCoE not enabled on the switch - we can't do anything here.
fcoe_vlan_interface = NOT_AVAILABLE;
}
else
{
if ( vlan_info[card["dev_name"]:""]:"" == "0" )
{
// for VLAN interface "0" means start FCoE on network interface (without creating a VLAN)
fcoe_vlan_interface = card["dev_name"]:"";
}
else // get FCoE VLAN interface from /proc/net/vlan/config
{
fcoe_vlan_interface = GetFcoeVlanInterface( card["dev_name"]:"", vlan_info[card["dev_name"]:""]:"" );
}
if ( fcoe_vlan_interface != "" )
{
status_map = GetFcoeStatus( fcoe_vlan_interface, card["dev_name"]:"" );
if ( status_map == $[] )
{
if ( vlan_info[card["dev_name"]:""]:"" != "0" )
{
y2warning( "Cannot read config file for %1 in /etc/fcoe", fcoe_vlan_interface );
Report::Warning( sformat(_("Cannot read config file for %1.
You may edit the settings and recreate the FCoE
VLAN interface to get a valid configuration."), fcoe_vlan_interface) );
}
else
{
y2milestone( "FCoE not configured" );
}
// the interface isn't configured
fcoe_vlan_interface = NOT_CONFIGURED;
}
}
else
{
// FCoE VLAN interface not yet configured (status_map remains empty)
fcoe_vlan_interface = NOT_CONFIGURED;
}
}
dcb_capable = DCBCapable( card["dev_name"]:"" );
info_map = add( info_map, "dev_name", card["dev_name"]:""); // network card, e.g. eth3
info_map = add( info_map, "mac_addr", card["resource", "hwaddr", 0, "addr"]:"" ); // MAC address
if ( card["device"]:"" != "" )
{
info_map = add( info_map, "device", card["device"]:""); // device name
}
else
{
info_map = add( info_map, "device", card["model"]:""); // model
}
info_map = add( info_map, "fcoe_vlan", fcoe_vlan_interface ); // FCoE VLAN interface, e.g. eth3.200
if ( fcoe_vlan_interface != NOT_AVAILABLE )
{
// default for FCoE enable is yes
info_map = add( info_map, "fcoe_enable", status_map["FCOE_ENABLE"]:"yes" ); // FCOE_ENABLE
// 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";
}
info_map = add( info_map, "dcb_required", status_map["DCB_REQUIRED"]:dcb_default );
// default is AUTO_VLAN="yes", create /etc/fcoe/cfg-ethx file without VLAN device in name
// (e.g. /etc/fcoe/cfg-eth3), see bnc #724563
info_map = add( info_map, "auto_vlan", status_map["AUTO_VLAN"]:"yes"); // AUTO_VLAN
}
info_map = add( info_map, "dcb_capable", dcb_capable ); // DCB capable
info_map = add( info_map, "vlan_interface", vlan_info[card["dev_name"]:""]:"" ); // VLAN interface, e.g. 200
info_map = add( info_map, "cfg_file", status_map["cfg_device"]:"" ); // part of cfg-file name, e.g. eth3.200
network_interfaces = add( network_interfaces, info_map );
} );
// sort the list of interfaces (eth0, eth1, eth2...)
network_interfaces = sort( map a, map b, network_interfaces, {
return ( a["dev_name"]:"" < b["dev_name"]:"" );
} );
return true;
}
//
// Read /etc/fcoe/config
//
global boolean ReadFcoeConfig()
{
list <string> options = (list<string>) SCR::Dir(.fcoe.config);
y2milestone( "List of options in /etc/fcoe/config: %1", options );
if ( options == [] || options == nil )
return false;
string debug_val = (string)SCR::Read(add(.fcoe.config, "DEBUG"));
fcoe_general_config = add( fcoe_general_config, "DEBUG", debug_val );
string syslog_val = (string)SCR::Read(add(.fcoe.config, "USE_SYSLOG"));
fcoe_general_config = add( fcoe_general_config, "USE_SYSLOG", syslog_val );
y2milestone( "/etc/fcoe/config read: DEBUG: %1, USE_SYSLOG: %2", debug_val, syslog_val );
return true;
}
//
// Write /etc/fcoe/config using fcoe_config.scr
//
global boolean WriteFcoeConfig()
{
boolean success = (boolean)SCR::Write(add(.fcoe.config, "DEBUG"), GetFcoeConfig()["DEBUG"]:"" );
if ( !success )
return false;
success = (boolean)SCR::Write(add(.fcoe.config, "USE_SYSLOG"), GetFcoeConfig()["USE_SYSLOG"]:"" );
if ( !success )
return false;
// This is very important- it flushes the cache, and stores the configuration on the disk
success = SCR::Write(.fcoe.config, nil);
return success;
}
//
// Write ifcfg-files in /etc/sysconfig/network (for FCoE VLAN interface and underlying interface)
// using network.scr from yast2/library/network
//
global boolean WriteSysconfigFiles( )
{
list <map> netcards = GetNetworkCards();
boolean success = true;
foreach ( map card, (list<map>)netcards, {
if ( card["fcoe_vlan"]:"" != FcoeClient::NOT_AVAILABLE && // FCoE VLAN is configured
card["fcoe_vlan"]:"" != FcoeClient::NOT_CONFIGURED )
{
// write ifcfg-<if>.>VLAN> only if VLAN was created
if ( card["vlan_interface"]:"" != "0" )
{
y2milestone( "Writing /etc/sysconfig/network/ifcfg-%1", card["fcoe_vlan"]:"" );
// write /etc/sysconfig/network/ifcfg-<fcoe-vlan-interface>, e.g. ifcfg-eth3.200
SCR::Write(.network.value + card["fcoe_vlan"]:"" + "BOOTPROTO", "static" );
SCR::Write(.network.value + card["fcoe_vlan"]:"" + "STARTMODE", "nfsroot" );
SCR::Write(.network.value + card["fcoe_vlan"]:"" + "ETHERDEVICE", card["dev_name"]:"" );
SCR::Write(.network.value + card["fcoe_vlan"]:"" + "USERCONTROL", "no" );
SCR::Write(.network.value + card["fcoe_vlan"]:"" + "VLAN_ID", card["vlan_interface"]:"" );
}
string ifcfg_file = sformat( "/etc/sysconfig/network/ifcfg-%1", card["dev_name"]:"" );
y2milestone( "Writing %1", ifcfg_file );
// write /etc/sysconfig/network/ifcfg-<interface> (underlying interface), e.g. ifcfg-eth3
if ( !FileUtils::Exists(ifcfg_file) )
{
SCR::Write(.network.value + card["dev_name"]:"" + "BOOTPROTO", "static" );
SCR::Write(.network.value + card["dev_name"]:"" + "STARTMODE", "nfsroot" );
SCR::Write(.network.value + card["dev_name"]:"" + "NAME", card["device"]:"" );
}
else
{
// don't overwrite BOOTPROTO !!!
SCR::Write(.network.value + card["dev_name"]:"" + "STARTMODE", "nfsroot" );
}
}
} );
// This is very important- it flushes the cache, and stores the configuration on the disk
success = SCR::Write( .network, nil );
if ( !success )
{
y2error( "Error writing /etc/sysconfig/network/ifcfg-files" );
}
return success;
}
//
// Write /etc/fcoe/cfg-ethx files using fcoe_cfg-ethx.scr
//
global boolean WriteCfgFiles()
{
list <map> netcards = GetNetworkCards();
boolean success = false;
foreach ( map card, (list<map>)netcards, {
if ( card["fcoe_vlan"]:"" != FcoeClient::NOT_AVAILABLE && // FCoE VLAN is configured
card["fcoe_vlan"]:"" != FcoeClient::NOT_CONFIGURED )
{
string command = "";
map output = $[];
y2milestone( "Writing /etc/fcoe/cfg-%1", card["cfg_file"]:"" );
success = SCR::Write(.fcoe.cfg-ethx.value + card["cfg_file"]:"" + "FCOE_ENABLE", card[ "fcoe_enable"]:"no" );
if ( !success )
{
y2error( "Writing FCOE_ENABLE=%1 failed", card[ "fcoe_enable"]:"no" );
}
success = SCR::Write(.fcoe.cfg-ethx.value + card["cfg_file"]:"" + "DCB_REQUIRED", card["dcb_required"]:"no" );
if ( !success )
{
y2error( "Writing DCB_REQUIRED=%1 failed", card["dcb_required"]:"no" );
}
success = SCR::Write(.fcoe.cfg-ethx.value + card["cfg_file"]:"" + "AUTO_VLAN", card["auto_vlan"]:"no" );
if ( !success )
{
y2error( "Writing AUTO_VLAN=%1 failed", card["auto_vlan"]:"no" );
}
if ( card["dcb_required"]:"no" == "yes" )
{
// enable DCB on the interface
command = sformat( "dcbtool sc %1 dcb on", card["dev_name"]:"" );
y2milestone( "Executing command: %1", command );
output = (map)SCR::Execute( .target.bash_output, command );
y2milestone( "Output: %1", output );
if ( output["exit"]:255 != 0 )
{
// only warning, not necessarily an error
y2warning( "Command: %1 failed", command);
}
// enable App:FCoE on the interface
command = sformat( "dcbtool sc %1 app:0 e:1 a:1 w:1", card["dev_name"]:"" );
y2milestone( "Executing command: %1", command );
output = (map)SCR::Execute( .target.bash_output, command );
y2milestone( "Output: %1", output );
if ( output["exit"]:255 != 0 )
{
// only warning, not necessarily an error
y2warning( "Command: %1 failed", command);
}
}
}
} );
// This is very important- it flushes the cache, and stores the configuration on the disk
success = SCR::Write( .fcoe.cfg-ethx, nil );
return success;
}
// restart service fcoe
global boolean RestartServiceFcoe()
{
boolean ret = true;
y2milestone( "Restarting fcoe");
ret = Service::Restart("boot.fcoe");
return ret;
}
/**
* Read all fcoe-client settings
* @return true on success
*/
global boolean Read()
{
/* FcoeClient read dialog caption */
string caption = _("Initializing fcoe-client Configuration");
// Set the right number of stages
integer steps = 4;