Src/Private/Get-AbrOntapVserverFcpDiagram.ps1
|
function Get-AbrOntapVserverFcpDiagram { <# .SYNOPSIS Used by As Built Report to build a NetApp ONTAP Vserver FCP diagram #> [CmdletBinding()] param ( [Parameter ( Position = 0, Mandatory)] [string] $Vserver ) begin { Write-PScriboMessage "Generating FCP Diagram for $Vserver." $RootPath = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent [System.IO.FileInfo]$IconPath = Join-Path $RootPath 'icons' $IconDebug = [bool]$Options.EnableDiagramDebug if ($Options.DiagramTheme -eq 'Black') { $Edgecolor = 'White' $FontColor = 'White' } elseif ($Options.DiagramTheme -eq 'Neon') { $Edgecolor = 'gold2' $FontColor = 'gold2' } else { $Edgecolor = '#71797E' $FontColor = '#111827' } $IconStyles = @{ Port = @{ IconType = 'Ontap_Network_Port'; Background = '#F1F5F9'; Border = '#64748B' } Lif = @{ IconType = 'Ontap_Network_Nic'; Background = '#DBEAFE'; Border = '#2563EB' } Volume = @{ IconType = 'Ontap_Volume'; Background = '#DCFCE7'; Border = '#16A34A' } Lun = @{ IconType = 'Ontap_Lun'; Background = '#FEF3C7'; Border = '#D97706' } Igroup = @{ IconType = 'Ontap_Igroup'; Background = '#F3E8FF'; Border = '#9333EA' } } if ($Options.DiagramTheme -eq 'Black') { foreach ($Style in $IconStyles.Values) { $Style.Background = '#1F2937' } } elseif ($Options.DiagramTheme -eq 'Neon') { foreach ($Style in $IconStyles.Values) { $Style.Background = 'grey14' $Style.Border = 'gold2' } } } process { try { $FcpInterfaces = @(Get-NcFcpInterface -VserverContext $Vserver -Controller $Array) $Igroups = @(Get-NcIgroup -VserverContext $Vserver -Controller $Array | Where-Object { $_.Protocol -in @('fcp', 'mixed') }) if (-not $FcpInterfaces -and -not $Igroups) { return } $LunMaps = @(Get-NcLunMap -VserverContext $Vserver -Controller $Array | Where-Object { $_.InitiatorGroup -in $Igroups.Name }) $Luns = @(Get-NcLun -VserverContext $Vserver -Controller $Array) $ReportingNodes = @($LunMaps | ForEach-Object { $_.ReportingNodes } | Where-Object { $_ } | Select-Object -Unique) $FcpInterfaces = @($FcpInterfaces | Where-Object { $_.CurrentNode -in $ReportingNodes }) $FcpPortKeys = @($FcpInterfaces | ForEach-Object { "$($_.CurrentNode)|$($_.CurrentPort)" }) $FcpAdapters = @(Get-NcFcpAdapter -Controller $Array | Where-Object { $_.PhysicalProtocol -ne 'ethernet' -and "$($_.Node)|$($_.Adapter)" -in $FcpPortKeys }) $FcpDiagramSummary = "FCP diagram inputs for ${Vserver}: " + "$($FcpInterfaces.Count) LIFs, $($Igroups.Count) FCP/mixed igroups, " + "$($LunMaps.Count) mapped LUNs." Write-PScriboMessage $FcpDiagramSummary if (-not $LunMaps) { $NoFcpMapsMessage = "No FCP LUN maps found for ${Vserver}; volume and LUN cards " + 'require a map to an FCP or mixed igroup.' Write-PScriboMessage $NoFcpMapsMessage } $EdgeParams = @{ EdgeColor = $Edgecolor Arrowhead = 'normal' Arrowtail = 'none' EdgeLength = 2 GraphvizAttributes = @{ style = 'filled' } } $LegendItems = @( @{ Label = 'Port'; Style = $IconStyles.Port } @{ Label = 'LIF'; Style = $IconStyles.Lif } @{ Label = 'Volume'; Style = $IconStyles.Volume } @{ Label = 'LUN'; Style = $IconStyles.Lun } @{ Label = 'Igroup'; Style = $IconStyles.Igroup } ) $LegendCells = foreach ($Item in $LegendItems) { '<TD BGCOLOR="{0}"><FONT COLOR="{1}">■</FONT> <B>{2}</B></TD>' -f ` $Item.Style.Background, $Item.Style.Border, $Item.Label } $HTMLLegend = '<TABLE BORDER="0" CELLBORDER="0" CELLSPACING="4"><TR>' + ($LegendCells -join '') + '</TR></TABLE>' SubGraph FcpDiagram -Attributes @{ Label = $HTMLLegend fontsize = 14 labelloc = 't' labeljust = 'c' style = 'invis' color = 'transparent' } { $AdapterNodes = @{} $PortNodeNames = @() $AdapterIndex = 0 foreach ($Adapter in $FcpAdapters) { $AdapterKey = "$($Adapter.Node)|$($Adapter.Adapter)" $AdapterNodeName = "FcpPort$AdapterIndex" $AdapterNodes[$AdapterKey] = $AdapterNodeName $PortNodeNames += $AdapterNodeName $PortInfo = [ordered]@{ Protocol = $Adapter.PhysicalProtocol Speed = $Adapter.Speed Status = $Adapter.State } Add-NodeIcon -Name $AdapterNodeName -LabelName $Adapter.Adapter -ImagesObj $Images ` -IconType $IconStyles.Port.IconType -Align 'Center' -IconDebug $IconDebug ` -AditionalInfo $PortInfo -IconPath $IconPath -ImageSizePercent 55 -FontSize 14 ` -FontColor $FontColor -TableBorder 1 -TableBorderColor $IconStyles.Port.Border ` -TableBackgroundColor $IconStyles.Port.Background ` -CellBackgroundColor $IconStyles.Port.Background ` -NodeObject $AdapterIndex++ } $LifIndex = 0 $LifNodeNames = @() $LifReportingNodes = @{} foreach ($Interface in $FcpInterfaces) { $LifNodeName = "FcpLif$LifIndex" $LifNodeNames += $LifNodeName $LifReportingNodes[$LifNodeName] = $Interface.CurrentNode $LifInfo = [ordered]@{ WWPN = $Interface.PortName Location = "$($Interface.CurrentNode):$($Interface.CurrentPort)" } Add-NodeIcon -Name $LifNodeName -LabelName $Interface.InterfaceName -ImagesObj $Images ` -IconType $IconStyles.Lif.IconType -Align 'Center' -IconDebug $IconDebug ` -AditionalInfo $LifInfo -IconPath $IconPath -ImageSizePercent 55 -FontSize 14 ` -FontColor $FontColor -TableBorder 1 -TableBorderColor $IconStyles.Lif.Border ` -TableBackgroundColor $IconStyles.Lif.Background ` -CellBackgroundColor $IconStyles.Lif.Background ` -NodeObject $AdapterKey = "$($Interface.CurrentNode)|$($Interface.CurrentPort)" if ($AdapterNodes.ContainsKey($AdapterKey)) { Add-NodeEdge -From $AdapterNodes[$AdapterKey] -To $LifNodeName ` -EdgeLabel 'hosts' @EdgeParams } $LifIndex++ } $IgroupNodes = @{} $IgroupNodeNames = @() $IgroupIndex = 0 foreach ($Igroup in $Igroups) { $IgroupNodeName = "FcpIgroup$IgroupIndex" $IgroupNodes[$Igroup.Name] = $IgroupNodeName $IgroupNodeNames += $IgroupNodeName Add-NodeIcon -Name $IgroupNodeName -LabelName $Igroup.Name -ImagesObj $Images ` -IconType $IconStyles.Igroup.IconType -Align 'Center' -IconDebug $IconDebug ` -AditionalInfo @{ Protocol = $Igroup.Protocol } -FontSize 14 -FontColor $FontColor ` -TableBorder 1 -TableBorderColor $IconStyles.Igroup.Border ` -TableBackgroundColor $IconStyles.Igroup.Background ` -CellBackgroundColor $IconStyles.Igroup.Background ` -NodeObject $IgroupIndex++ } $VolumeNodes = @{} $VolumeReportingNodes = @{} $VolumeNodeNames = @() $LunNodes = @{} $LunNodeNames = @() $LunIndex = 0 foreach ($LunMap in $LunMaps) { $LunPath = $LunMap.Path $Lun = $Luns | Where-Object { $_.Path -eq $LunPath } | Select-Object -First 1 $VolumeName = if ($Lun.Volume) { $Lun.Volume } else { ($LunPath -split '/')[2] } if (-not $VolumeReportingNodes.ContainsKey($VolumeName)) { $VolumeReportingNodes[$VolumeName] = @{} } foreach ($ReportingNode in @($LunMap.ReportingNodes)) { if ($ReportingNode) { $VolumeReportingNodes[$VolumeName][[string]$ReportingNode] = $true } } if (-not $VolumeNodes.ContainsKey($VolumeName)) { $VolumeNodeName = "FcpVolume$($VolumeNodes.Count)" $VolumeNodes[$VolumeName] = $VolumeNodeName $VolumeNodeNames += $VolumeNodeName Add-NodeIcon -Name $VolumeNodeName -LabelName $VolumeName -ImagesObj $Images ` -IconType $IconStyles.Volume.IconType -Align 'Center' -IconDebug $IconDebug ` -IconPath $IconPath -ImageSizePercent 55 -FontSize 14 -FontColor $FontColor ` -TableBorder 1 -TableBorderColor $IconStyles.Volume.Border ` -TableBackgroundColor $IconStyles.Volume.Background ` -CellBackgroundColor $IconStyles.Volume.Background ` -NodeObject } if (-not $LunNodes.ContainsKey($LunPath)) { $LunName = ($LunPath -split '/')[-1] $LunStatus = switch ([string]$Lun.Online) { 'True' { 'Online' } 'False' { 'Offline' } default { 'Unknown' } } $LunNodeName = "FcpLun$LunIndex" $LunNodes[$LunPath] = $LunNodeName $LunNodeNames += $LunNodeName Add-NodeIcon -Name $LunNodeName -LabelName $LunName -ImagesObj $Images ` -IconType $IconStyles.Lun.IconType -Align 'Center' -IconDebug $IconDebug ` -AditionalInfo @{ Status = $LunStatus } -FontSize 14 -FontColor $FontColor ` -TableBorder 1 -TableBorderColor $IconStyles.Lun.Border ` -TableBackgroundColor $IconStyles.Lun.Background ` -CellBackgroundColor $IconStyles.Lun.Background ` -NodeObject Add-NodeEdge -From $VolumeNodes[$VolumeName] -To $LunNodeName ` -EdgeLabel 'contains' @EdgeParams $LunIndex++ } if ($IgroupNodes.ContainsKey($LunMap.InitiatorGroup)) { Add-NodeEdge -From $LunNodes[$LunPath] ` -To $IgroupNodes[$LunMap.InitiatorGroup] -EdgeLabel 'mapped to' @EdgeParams } } foreach ($LifNodeName in $LifNodeNames) { foreach ($VolumeName in $VolumeNodes.Keys) { if ($VolumeReportingNodes[$VolumeName].ContainsKey( [string]$LifReportingNodes[$LifNodeName] )) { Add-NodeEdge -From $LifNodeName -To $VolumeNodes[$VolumeName] ` -EdgeLabel 'accesses' @EdgeParams } } } if ($PortNodeNames) { Rank -Nodes $PortNodeNames } if ($LifNodeNames) { Rank -Nodes $LifNodeNames } if ($VolumeNodeNames) { Rank -Nodes $VolumeNodeNames } if ($LunNodeNames) { Rank -Nodes $LunNodeNames } if ($IgroupNodeNames) { Rank -Nodes $IgroupNodeNames } } } catch { Write-PScriboMessage -IsWarning ` "Unable to generate the FCP diagram for ${Vserver}: $($_.Exception.Message)" } } end {} } |