-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfc-migrate.pl
166 lines (152 loc) · 5.67 KB
/
fc-migrate.pl
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
#!/usr/bin/perl
BEGIN { $^W = 1; }
use strict;
my $version = '0.3';
print "Qlogic Sanbox to Brocade DCX Zoning Migration\n";
print "Release $version\n";
print "(c) 2017 Unilogic B.V.\n\n";
unless ($ARGV[0] and $ARGV[1]) {
die "fc-migrate.pl <INPUT FILE> <OUTPUT FILE> (<CFG_NAME>)\n";
}
# Source Tested on Sanbox 5602 Software Version: V7.4.0.16.0
# Destination Tested on Brocade DCX-4 Software Version V7.1
# Configuration Variables
my $fabric_name = 'MYBROCADECFG';
my $debug = 0;
# Initialize Variables
my(%wwnAlias, %zoneSetDB);
my @zoneDB;
my @zoneTypeDB;
my @zoneMemberDB;
my $fabric_created = 0;
my $row;
sub convertWWN {
my($wwn) = @_;
my $outputWWN;
if ($wwn =~ /^([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})([0-9a-z]{2})/) {
$outputWWN = "$1:$2:$3:$4:$5:$6:$7:$8";
return $outputWWN;
}
return '00:00:00:00:00:00:00';
}
sub returnWWNorAlias {
my($WWNMember) = @_;
my $applicable_alias = 0;
if ($wwnAlias{$WWNMember}) {
$applicable_alias = $wwnAlias{$WWNMember};
$applicable_alias =~ s/-/_/g;
}
else {
$applicable_alias = convertWWN($WWNMember);
}
return $applicable_alias;
}
my $source_file = $ARGV[0];
my $output_file = $ARGV[1];
if (defined $ARGV[2]) {
$fabric_name = $ARGV[2];
}
print " - Opening configuration file $source_file\n";
die "Could not open file '${source_file}' $!" unless open CONFIG_FILE, "<$source_file";
print " - Opening output file $output_file\n";
die "Could not open file '${output_file}' $!" unless open my $outputhandle, '>', $output_file;
while (defined($_ = <CONFIG_FILE>)) {
if ($_ =~ /^NAME=Default.Snmp.SysDescr,TYPE=STRING,VAL=(.*$)/) {
my $sourcePlatform = $1;
print " - Migrating from $sourcePlatform\n";
}
if ($_ =~ /^NAME=Global.Nicknames.NumberOfNicknames,TYPE=UINT,VAL=(\d+)/) {
my $NumberOfNicknames = $1;
print " - Total number of WWN Nicknames is $NumberOfNicknames\n";
}
if ($_ =~ /^NAME=Global.Nicknames.(\d+),TYPE=STRING,VAL=\[(\S+)\]\[(\w+)\]\[WWN\]\[(\d+)\]\[(\d+)\]/) {
my $nickNameId = $1;
my $nickNameName = $2;
my $nickNameWWN = $3;
if ($debug) {
print " - WWN $nickNameId Host $nickNameName has WWN $nickNameWWN \n";
}
$wwnAlias{$nickNameWWN} = $nickNameName;
$nickNameName =~ s/-/_/g;
print $outputhandle qq[alicreate "$nickNameName", "] . convertWWN($nickNameWWN) . qq[" \n];
}
if ($_ =~ /^NAME=Global.Zoning.NumberOfZones,TYPE=UINT,VAL=(\d+)/) {
my $NumberOfZones = $1;
print " - Total number of Zones is $NumberOfZones (including orphaned zones)\n";
}
if ($_ =~ /^NAME=Global.Zoning.ZoneList.(\d+),TYPE=STRING,VAL=(\S+)/) {
my $zoneId = $1;
my $zoneName = $2;
if ($debug) {
print " - Zone $zoneId is $zoneName \n";
}
$zoneDB[$zoneId] = $zoneName;
}
if ($_ =~ /^NAME=Global.Zoning.Zone.(\d+).ZoneType,TYPE=STRING,VAL=(\S+)/) {
my $zoneTypeId = $1;
my $zoneTypeType = $2;
if ($debug) {
print " - Zone $zoneDB[$zoneTypeId] is $zoneTypeType Zoned\n";
}
$zoneTypeDB[$zoneTypeId] = $zoneTypeType;
}
if ($debug and $_ =~ /^NAME=Global.Zoning.Zone.(\d+).NumberOfZoneMembers,TYPE=UINT,VAL=(\d+)/) {
my $zoneCountId = $1;
my $zoneCountNum = $2;
print " - Zone $zoneDB[$zoneCountId] has $zoneCountNum members\n";
}
if ($_ =~ /^NAME=Global.Zoning.Zone.(\d+).ZoneMemberList.(\d+),TYPE=STRING,VAL=1(\S+)/) {
my $zoneMemberZone = $1;
my $zoneMemberId = $2;
my $zoneMemberWWN = $3;
if ($debug) {
print " - Zone $zoneDB[$zoneMemberZone] Member $zoneMemberId has WWN " . $wwnAlias{$zoneMemberWWN} . "($zoneMemberWWN)\n";
}
push @{$zoneMemberDB[$zoneMemberZone];}, $zoneMemberWWN;
}
if ($debug and $_ =~ /^NAME=Global.Zoning.ZoneSet.(\d+).ZoneIndex.(\d+),TYPE=UINT,VAL=(\d+)/) {
my $zoneSetId = $1;
my $zoneSetIndex = $2;
my $zoneSetZoneId = $3;
print " - ZoneSet $zoneSetId has $zoneSetZoneId on index $zoneSetIndex\n";
}
if ($_ =~ /^NAME=Global.Zoning.ZoneSet.(\d+).ZoneList.(\d+),TYPE=STRING,VAL=(\S+)/) {
my $zoneSetListId = $1;
my $zoneSetListListId = $2;
my $zoneSetListListName = $3;
if ($debug) {
print " - ZoneSet $zoneSetListId has $zoneSetListListName on $zoneSetListListId\n";
}
$zoneSetDB{$zoneSetListListName} = $zoneSetListListId;
}
}
print " - Generating Fabric Config $fabric_name\n";
print " - Writing brocade zoning configuration to $output_file \n";
foreach $row (0 .. @zoneMemberDB - 1) {
if ($debug) {
print "D: $zoneDB[$row] \n";
}
if (defined $zoneSetDB{$zoneDB[$row]}) {
my $applicable_zone = $zoneDB[$row];
my $command_output;
$applicable_zone =~ s/-/_/g;
$command_output = qq[zonecreate "$applicable_zone","];
my $column;
foreach $column (0 .. @{$zoneMemberDB[$row];} - 1) {
$command_output .= ' ' . returnWWNorAlias($zoneMemberDB[$row][$column]) . ';';
if ($debug) {
print "Zone $zoneDB[$row] has member $wwnAlias{$zoneMemberDB[$row][$column]} ($zoneMemberDB[$row][$column])\n";
}
}
$command_output =~ s/\;+$//;
print $outputhandle qq[$command_output"\n];
if ($fabric_created < 1) {
print $outputhandle qq[cfgcreate "$fabric_name", "$applicable_zone"\n];
$fabric_created = 1;
}
else {
print $outputhandle qq[cfgadd "$fabric_name", "$applicable_zone"\n];
}
}
}
close $outputhandle;