Skip to content

Instantly share code, notes, and snippets.

@Mierdin
Last active November 2, 2018 19:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Mierdin/7094271 to your computer and use it in GitHub Desktop.
Save Mierdin/7094271 to your computer and use it in GitHub Desktop.
Reaches into a Cisco UCS Instance, and iterates through every service profile, creating Netapp initiator groups and 10g boot LUNs for each one, and then putting each service profile's vHBA's WWPNs in the respective initiator groups. Each igroup that is created by this script will be mapped to the respective boot LUN. Currently tested with NetApp…
<#
Name: AutoBFS.ps1
Author: Matthew Oswalt
Created: 10/20/2013
Description: Reaches into a Cisco UCS Instance, and iterates through every service profile, creating Netapp initiator groups
and 10g boot LUNs for each one, and then putting each service profile's vHBA's WWPNs in the respective initiator groups.
Each igroup that is created by this script will be mapped to the respective boot LUN.
Currently only tested with NetApp Release 8.2P2 Cluster-Mode and Cisco UCSM 2.1(3a)
#>
Import-Module CiscoUcsPs
Import-Module DataONTAP
#region VARs
$NAipAddr = "1.1.1.20"
$NAusername = "admin"
$NApassword = "password"
$NAportset = "fcoe_pset_1"
$NAvserver = "FC_VS1"
$NAbootVol = "/vol/FC_BootVol1/" #Needs to be of this format, including the forward slashes. LUN will be appended without any slashes
$UCSipAddr = "1.1.1.50"
$UCSusername = "admin"
$UCSpassword = "password"
$organization = "root"
#endregion
#region Establish Connections
#Connect to Netapp, suppressing prompt
$NASecPass = ConvertTo-SecureString $NApassword -AsPlainText -Force
$NAcred = New-Object System.Management.Automation.PSCredential($NAusername, $NASecPass)
Connect-NcController $NAipAddr -credential $NAcred
#Connect to UCSM, suppressing prompt
$UCSSecPass = ConvertTo-SecureString $UCSpassword -AsPlainText -Force
$ucsmCreds = New-Object System.Management.Automation.PSCredential($UCSusername, $UCSSecPass)
Disconnect-Ucs
Connect-Ucs $UCSipAddr -Credential $ucsmCreds
#endregion
#region Create igroups
#We only want Service Profile Instances, not Templates
$serviceProfiles = Get-UcsServiceProfile -Type instance -Org $organization
#Iterate through Service Profiles, creating boot luns and igroups, mapping as you go
foreach ($SP in $serviceProfiles) {
#create path to LUN
$LUNPath = $NAbootVol + $SP.name + "_boot"
#check to see if lun by this path already exists
if (Get-NcLun -path $LUNPath -Vserver $NAvserver) {
Write-Host "LUN already exists: " $SP.Name
} Else {
#Need to finish flushing out this line
New-NcLun -path $LUNPath -Size 10g -OsType vmware -Unreserved
}
#Populate array with existing vHBAs on this service profile
$vHBAs = $SP | Get-UcsVhba
#check to see if igroup by this name already exists
if (Get-NcIgroup -name $SP.Name) {
Write-Host "igroup already exists: " $SP.Name
} Else {
#Create the igroup first
Write-Host "Creating igroup named " + $SP.Name
$newIgroup = New-NcIgroup -name $sp.Name -protocol fcp -portset $NAportset -type VMware -vserver $NAvserver
#Iterate through each vHBA, and add each WWPN to this igroup
foreach ($vHBA in $vHBAs) {
Write-Host "Adding WWPN " $vHBA.Addr
Add-NcIgroupInitiator -Initiator $vHBA.Addr -Name $SP.Name -VserverContext $NAvserver
}
#Adds the mapping at the tail end. Kept inside this if statement so it only ran on igroups that were created by this script, not existing ones
Add-NcLunMap -Path $LUNPath -InitiatorGroup $newIgroup.Name
}
}
#endregion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment