This
program parses the output of up to two Igroup Files from NetApp 7-Mode systems
(i.e. an HA-pair), and forms a CSV, with all the data, and additionally CDOT
commands for igroup create and igroup add (the use case is for 7 to C
transitions).
The
igroup files are either the INITIATOR-GROUPS file from ASUP, or can be
constructed from the output of the 7-mode command> igroup show -v
Note: If there are igroups in the second file
with the same name, but different settings, the data from the 1st might be
overwritten (they shouldn't be different).
Examples:
.\igroup_parser.ps1
-IgroupFile NODE1-INITIATOR-GROUPS
.\igroup_parser.ps1
-IgroupFile NODE1-INITIATOR-GROUPS -IgroupFile2 NODE2-INITIATOR-GROUPS
The Script
Note: I didn’t use export-csv to create the
CSV, instead strings of comma separated values and set file content with this.
I’d be curious if using export-csv would have improved/streamlined the code.
<#
This program parses the
output of up to two Igroup Files from NetApp 7-Mode systems (i.e. an HA-pair),
and forms a CSV, with all the data, and additionally CDOT commands for igroup
create and igroup add (use case for 7 to C transitions).
The igroup files are either
the INITIATOR-GROUPS file from ASUP, or can be constructed from the output of
the 7-mode command> igroup show -v
Note: If there are igroups
in the second file with the same name, but different settings, the data from
the 1st might be overwritten (they shouldn't be different).
Examples:
.\igroup_parser.ps1
-IgroupFile NODE1-INITIATOR-GROUPS
.\igroup_parser.ps1
-IgroupFile NODE1-INITIATOR-GROUPS -IgroupFile2 NODE2-INITIATOR-GROUPS
#>
Param(
[Parameter(Mandatory=$True)][String]$IgroupFile,
[String]$IgroupFile2,
[String]$Vserver = "VSERVERNAME",
[String]$SaveFile = "FCP_IGROUPS"
)
## THIS SECTION GETS THE
DATA ##
[System.Array]$IgroupFileContent
= Get-Content $IgroupFile
If($IgroupFile2){
$IgroupFileContent += Get-Content $IgroupFile2}
## THIS SECTION PROCESSES
THE DATA ##
[String ]$IgroupName = ""
[System.Object]$Igroups = @{}
[System.Array ]$IgroupList =
@()
$IgroupFileContent | Foreach
{
$_ = $_.Trim(" ","`t")
If($_.Contains("(FCP):")){
$IgroupName = $_.Split(" ")[0]
If( !($IgroupList -Contains $IgroupName) ){
$IgroupList += $IgroupName
[System.Object]$Igroups.$IgroupName = @{}
[String ]$Igroups.$IgroupName.OSType = ""
[String ]$Igroups.$IgroupName.MPIO = ""
[System.Array ]$Igroups.$IgroupName.Members = @()
[String ]$Igroups.$IgroupName.UUID = ""
[String ]$Igroups.$IgroupName.ALUA = ""
[String ]$Igroups.$IgroupName.ReportName =
""
}
} elseif ($_.StartsWith("OS
Type:")){
$Igroups.$IgroupName.OSType =
$_.Split(" ")[2].Trim(" ","`t")
} elseif ($_.StartsWith("Host
Multipathing Software:")){
$Igroups.$IgroupName.MPIO = $_.Split("
")[3].Trim(" ","`t")
} elseif ($_.StartsWith("Member:")){
[String]$MemberName = $_.Split("
")[1].Trim(" ","`t")
If( !($Igroups.$IgroupName.Members
-Contains $MemberName) ){
$Igroups.$IgroupName.Members +=
$MemberName
}
} elseif ($_.StartsWith("UUID:")){
$Igroups.$IgroupName.UUID = $_.Split("
")[1].Trim(" ","`t")
} elseif ($_.StartsWith("ALUA:")){
$Igroups.$IgroupName.ALUA = $_.Split("
")[1].Trim(" ","`t")
} elseif ($_.StartsWith("Report SCSI
Name in Inquiry Descriptor:")){
$Igroups.$IgroupName.ReportName =
$_.Split(" ")[6].Trim(" ","`t")
}
}
## THIS SECTION CREATES THE
OUTPUT ##
[Int]$Row = 2
[System.Array]$Output = @()
$Output +=
"IgroupName,#,OS Type,#,MPIO S/W,#,Member,#,UUID,#,ALUA,#,Report
SCSI,#,VserverName,#,igroup create,#,igroup add"
$IgroupList | Foreach {
[String
]$OSType =
$Igroups.$_.OSType
[String
]$MPIO =
$Igroups.$_.MPIO
[System.Array]$Members = $Igroups.$_.Members
[String
]$UUID =
$Igroups.$_.UUID
[String
]$ALUA =
$Igroups.$_.ALUA
[String
]$ReportName = $Igroups.$_.ReportName
Foreach ($Member in $Members){
[String]$OutLine =
"$_,#,$OSType,#,$MPIO,#,$Member,#,$UUID,#,$ALUA,#,$ReportName,#,$Vserver,#,"
$OutLine += ('="igroup create -vserver
"&O' + $Row + '&" -igroup ' + $_ + ' -protocol fcp -ostype
"&C' + $Row)
$OutLine += ",#,"
$OutLine += ('="igroup add -vserver
"&O' + $Row + '&" -igroup ' + $_ + ' -initiator ' + $Member +
'"')
$Output
+= $OutLine
$Row++
}
}
## THIS SECTION SAVES THE
OUTPUT ##
$Output | Set-Content
($SaveFile + ".CSV")
Comments
Post a Comment