Script to Automate Registering HBAs with the Array.

by New Contributor on ‎2012-09-04 03:53 PM

Background;

     So the request was, how do I deploy a script that lets me deploy a set of between 5 and 10 Data Mining servers that each rip a copy of a database from the most recent hourly backup. I want each server to automatically create the clone from the last snapshot, then mount the LUN. I didn't want to write 10 scripts, and I didn't want to troubleshoot problems with non-existant iGroups, or mislabeled WWPNs.

This script assumes;

     You have either have a wide open fabric or have already previously zoned your switches.

     You have used the Connect-naController to connect to your target device.

What this script does;

     It will find your hostname, and put into a var called $hostname

     It will use the array to find the WWPN from your servers WWNN.

     It will Look for that WWPN in the Igroups, and if one doesnt exist it will create one using your $hostname and set the var $igroupname to be the hostname

     If an iGroup already exists, it will populate the var $igroupname with that name

     This script will run on all HBAs found in the system

Error conditions;

     If No HBAs are found, or if the WWPNs are not found on the array, the array will error out and tell you in either case.

$hostname=(Get-WmiObject -Class Win32_ComputerSystem).name
Write-host "Your Computer hostname is "$hostname

# The following piece of code will look for your local HBAs WWNs.
$foundHBA=$false; $igroupname=$false
foreach ($FCHBA in get-nahostfcadapter)
{      Write-host "Found HBA "$FCHBA.model" with WWNN of "$FCHBA.NodeWWN
      $foundHBA = $true
      # Since the Host only knows is WWNN, we need the WWPN, so we use the array to look for it.
      # Once we detect that WWNN, we know its WWPN.
      foreach($arrayport in get-nafcpinitiator)
      { foreach ($connection in $arrayport.fcpconnectedinitiators)
            { if ($connection.NodeName -like $fchba.nodewwn)
                  { Write-host "Found this WWNN on Array. Relates to WWPN "$connection.portname
                   # We also look to see it that WWPN is already in an iGroup. if not we create one
                   if ($connection.initiatorgrouplist)
                        { $igroupname = $connection.initiatorgrouplist
                         write-host "iGroup for this is named "$igroupname
                        }
                   else
                        { write-host "This WWPN is not in an iGroup, creating one now"
                         new-naigroup $hostname fcp windows
                         add-naigroupinitiator $hostname $connection.portname
                         $igroupname = $hostname
                        }
                  }
           }
        }
}

if ($iGroupName) # This means I found an HBA and a Target device
{      #Replace Parent Flexvol name, we use hostname embedded in lun names too...
      $parentvol1="vol_Log_SRC_master"

      #These are the LUNs
      $lunname1="SRC_Log"
      #Set clone volume Names
      $clonevol1="clone_vol_Log_SRC_GMOPRDFBISQL02"+$hostname

      #CloneLunPath
      $Clonepath1="/vol/"+$clonevol1+"/"+$lunname1

      #Set the Snapshot Names, this example always gets the 1 hour only snapshot.
      $snapname1="hourly.1"

      # Set the Mount Point Locations, and delete directorys if they exist
      $drive1="U:\Logs" | del; $drive2="V:\Logs" | del
      new-navolclone $clonevol1 $parentvol1 -Spacereserve none -parentsnapshot $snapname1

      Add-nalunmap $Clonepath1 $igroupname; Add-nalunmap $Clonepath2 $igroupname
     start-nahostdiskrescan
      wait-nahost -controllerlunpath $clonepath1 | mount-nahostvol -mountpoint $drive1
      #Attaching SQL DBs
      & sqlcmd -E -S $hostname -d master -i "c:\scripts\attach_sql.sql"
}
else
{      if ($foundHBA)
      {      Write-Host "I Was able to find an $HBA, but not able to detect that HBA on the Target Device."
            Write-Host "Please Check zoning and cabling to ensure that this host can see the target array."
      }

else
      {      Write-host "I was not able to find and HBAs in this system."
      }
}

Warning!

This NetApp Community is public and open website that is indexed by search engines such as Google. Participation in the NetApp Community is voluntary. All content posted on the NetApp Community is publicly viewable and available. This includes the rich text editor which is not encrypted for https.

In accordance to our Code of Conduct and Community Terms of Use DO NOT post or attach the following:

  • Software files (compressed or uncompressed)
  • Files that require an End User License Agreement (EULA)
  • Confidential information
  • Personal data you do not want publicly available
  • Another’s personally identifiable information
  • Copyrighted materials without the permission of the copyright owner

Files and content that do not abide by the Community Terms of Use or Code of Conduct will be removed. Continued non-compliance may result in NetApp Community account restrictions or termination.