Wednesday, March 29, 2017

WFA Command to check vserver iscsi

For a customer I'm currently writing a pretty advanced workflow to double check the entire iscsi environment.  One part is check if the vserver is running ISCSI and if it has enough iSCSI ip addresses.  I'm also checking the iscsi ip's against a network address.

download the dar file

    [Parameter(Mandatory=$true,HelpMessage="Cluster name or ip")]

    [Parameter(Mandatory=$true,HelpMessage="Vserver name")]

    [Parameter(Mandatory=$true,HelpMessage="Network adddress")]

    [Parameter(Mandatory=$true,HelpMessage="Subnet mask")]

    [Parameter(Mandatory=$false,HelpMessage="Number of required iSCSI addresses")]
    [int]$RequiredIscsiAddresses = 2

# helper functions to work with ipaddresses
function Get-NetworkAddress {
    param (
    $IpAddressBytes = $ip.GetAddressBytes()
    $SubnetMaskBytes = $Mask.GetAddressBytes()
    if ($IpAddressBytes.Length -ne $SubnetMaskBytes.Length) {
        throw "Lengths of IP address and subnet mask do not match."
        exit 0
    $NetworkAddressParts = @()
    for ($i=0;$i -le 3;$i++) {
        $NetworkAddressParts += $ipAddressBytes[$i]-band $subnetMaskBytes[$i]
    $NetworkAddressString = $NetworkAddressParts -Join "."
    return [IpAddress]$NetworkAddressString
function Test-IsInSameSubnet {
    param (
    $Network1 = Get-NetworkAddress -ip $ip1 -mask $mask1
    $Network2 = Get-NetworkAddress -ip $ip2 -mask $mask2
    return $Network1.Equals($Network2)

$ErrorActionPreference = "stop"

# connect to cluster
$cltr = Connect-WfaCluster $Cluster

# set counter
$counter = 0

# get vserver iqn
Get-WfaLogger -info -message  "[vserver] checking iscsi service"
$iscsiService = Get-NcIscsiService -VserverContext $VserverName
    $vserverIqn = $iscsiService.NodeName
    Get-WfaLogger -info -message  "[vserver] iscsi service found [$vserverIqn]"
    if(Test-nciscsi -VserverContext $VserverName){
        Get-WfaLogger -info -message  "[vserver] service is up"
         throw "[vserver] iSCSI service is created but is down for $VserverName"
    throw "[vserver] iSCSI service is not created for $VserverName"

# get vserver iscsi lifs
$lifs = Get-NcNetInterface -Vserver $VserverName -DataProtocols iscsi
foreach($l in $lifs){
    if(Test-IsInSameSubnet -ip1 $l.Address -ip2 $NetworkAddress -mask1 $l.Netmask -mask2 $SubnetMask){
        Get-WfaLogger -info -message  "[vserver] IP [$($l.Address)][$($l.Netmask)] is an iscsi address"
        Get-WfaLogger -warn -message  "[vserver] IP [$($l.Address)][$($l.Netmask)] is an iscsi address, but not in the correct iscsi network"
if($counter -ne $RequiredIscsiAddresses){
    throw "Expected $RequiredIscsiAddresses iscsi IpAddresses on host.  Found $counter"        
    Get-WfaLogger -info -message  "[Vserver] iscsi IpAddress count correct [$RequiredIscsiAddresses]"

No comments :

Post a Comment