Cisco UCS Manager PowerTool – Sample Script

With the following script I want to give you a starting point to work with the Cisco UCS Manager PowerTool to configure and install Cisco UCS fabric interconnects. The script is based on experience and created with the PowerTool record function. You can find details on that in one of my previous posts.

Please keep in mind that no warranty is provided with the script below. Be always careful when working on production systems.

#Login to UCS
$user = "ucspe"
$password = "ucspe" | ConvertTo-SecureString -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential($user, $password)
$servers = "192.168.200.2"
Connect-Ucs $servers -Credential $cred 

#Change FC Uplink Ports on Interconnect A ATTENTION: Reboot required
Start-UcsTransaction
Get-UcsFiSanCloud -Id "A" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 45 -SlotId 1 -UsrLbl ""
Get-UcsFiSanCloud -Id "A" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 46 -SlotId 1 -UsrLbl ""
Get-UcsFiSanCloud -Id "A" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 47 -SlotId 1 -UsrLbl ""
Get-UcsFiSanCloud -Id "A" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 48 -SlotId 1 -UsrLbl ""
Complete-UcsTransaction

#Change FC Uplink Ports on Interconnect A ATTENTION: Reboot required
Start-UcsTransaction
Get-UcsFiSanCloud -Id "B" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 45 -SlotId 1 -UsrLbl ""
Get-UcsFiSanCloud -Id "B" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 46 -SlotId 1 -UsrLbl ""
Get-UcsFiSanCloud -Id "B" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 47 -SlotId 1 -UsrLbl ""
Get-UcsFiSanCloud -Id "B" | Add-UcsFcUplinkPort -ModifyPresent  -AdminState "enabled" -FillPattern "arbff" -Name "" -PortId 48 -SlotId 1 -UsrLbl ""
Complete-UcsTransaction

#################Reboot#################

#Setting the default Maintanance Policy to user-ack
Get-UcsOrg -Level root | Get-UcsMaintenancePolicy -Name "default" -LimitScope | Set-UcsMaintenancePolicy -Descr "" -PolicyOwner "local" -SchedName "" -UptimeDisr "user-ack" -force

#Add DNS Server 
Add-UcsDnsServer -Descr "" -Name "192.168.200.10"

#Add Timeserver 
Add-UcsNtpServer -Descr "" -Name "192.168.200.10"

#Change Timezone 
Get-UcsTimezone | Set-UcsTimezone -AdminState "enabled" -Descr "" -PolicyOwner "local" -Port 0 -Timezone "Europe/Berlin" -Force

#Creation of UCS Portchannel to Chassis and change Power Policy to Grid
Start-UcsTransaction
Get-UcsOrg -Level root | Get-UcsPowerControlPolicy | Set-UcsPowerControlPolicy -Descr "" -PolicyOwner "local" -Redundancy "grid"
Get-UcsOrg -Level root | Get-UcsChassisDiscoveryPolicy | Set-UcsChassisDiscoveryPolicy -Action "4-link" -Descr "" -LinkAggregationPref "port-channel" -Name "" -PolicyOwner "local" -Rebalance "user-acknowledged"
Complete-UcsTransaction

#Creation of vSANs
Get-UcsFiSanCloud -Id "A" | Add-UcsVsan -FcZoneSharingMode "coalesce" -FcoeVlan 3002 -Id 3001 -Name "<VSANNAME>" -PolicyOwner "local" -ZoningState "disabled"
Get-UcsFiSanCloud -Id "B" | Add-UcsVsan -FcZoneSharingMode "coalesce" -FcoeVlan 3004 -Id 3003 -Name "<VSANNAME>" -PolicyOwner "local" -ZoningState "disabled"
Get-UcsFiSanCloud -Id "A" | Get-UcsVsan -Name "<VSANNAME>" | Add-UcsVsanMemberFcPort -ModifyPresent -AdminState "enabled" -Name "" -PortId 32 -SlotId 1 -SwitchId "A"
Get-UcsFiSanCloud -Id "B" | Get-UcsVsan -Name "<VSANNAME>" | Add-UcsVsanMemberFcPort -ModifyPresent -AdminState "enabled" -Name "" -PortId 32 -SlotId 1 -SwitchId "B"

#Setting Ports 1-4 per Interconnect to Server Port for Chassis
Get-UcsFabricServerCloud -Id "A" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 1 -SlotId 1 -UsrLbl ""
Get-UcsFabricServerCloud -Id "A" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 2 -SlotId 1 -UsrLbl ""
Get-UcsFabricServerCloud -Id "A" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 3 -SlotId 1 -UsrLbl ""
Get-UcsFabricServerCloud -Id "A" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 4 -SlotId 1 -UsrLbl ""
Get-UcsFabricServerCloud -Id "B" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 1 -SlotId 1 -UsrLbl ""
Get-UcsFabricServerCloud -Id "B" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 2 -SlotId 1 -UsrLbl ""
Get-UcsFabricServerCloud -Id "B" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 3 -SlotId 1 -UsrLbl ""
Get-UcsFabricServerCloud -Id "B" | Add-UcsServerPort -AdminState "enabled" -Name "" -PortId 4 -SlotId 1 -UsrLbl ""

#UplinkPorts LAN
Get-UcsFiLanCloud -Id "A" | Add-UcsUplinkPort -AdminSpeed "10gbps" -AdminState "enabled" -FlowCtrlPolicy "default" -Name "" -PortId 43 -SlotId 1 -UsrLbl ""
Get-UcsFiLanCloud -Id "A" | Add-UcsUplinkPort -AdminSpeed "10gbps" -AdminState "enabled" -FlowCtrlPolicy "default" -Name "" -PortId 44 -SlotId 1 -UsrLbl ""
Get-UcsFiLanCloud -Id "B" | Add-UcsUplinkPort -AdminSpeed "10gbps" -AdminState "enabled" -FlowCtrlPolicy "default" -Name "" -PortId 43 -SlotId 1 -UsrLbl ""
Get-UcsFiLanCloud -Id "B" | Add-UcsUplinkPort -AdminSpeed "10gbps" -AdminState "enabled" -FlowCtrlPolicy "default" -Name "" -PortId 44 -SlotId 1 -UsrLbl ""

#Creating LAN PortChannel
Start-UcsTransaction
$mo = Get-UcsFiLanCloud -Id "A" | Add-UcsUplinkPortChannel -AdminSpeed "10gbps" -AdminState "enabled" -FlowCtrlPolicy "default" -Name "toN5K-A" -OperSpeed "10gbps" -PortId 1
$mo_1 = $mo | Add-UcsUplinkPortChannelMember -ModifyPresent -AdminState "enabled" -Name "" -PortId 43 -SlotId 1
$mo_2 = $mo | Add-UcsUplinkPortChannelMember -ModifyPresent -AdminState "enabled" -Name "" -PortId 44 -SlotId 1
Complete-UcsTransaction

Start-UcsTransaction
$mo = Get-UcsFiLanCloud -Id "B" | Add-UcsUplinkPortChannel -AdminSpeed "10gbps" -AdminState "enabled" -FlowCtrlPolicy "default" -Name "toN5K-B" -OperSpeed "10gbps" -PortId 1
$mo_1 = $mo | Add-UcsUplinkPortChannelMember -ModifyPresent -AdminState "enabled" -Name "" -PortId 43 -SlotId 1
$mo_2 = $mo | Add-UcsUplinkPortChannelMember -ModifyPresent -AdminState "enabled" -Name "" -PortId 44 -SlotId 1
Complete-UcsTransaction

#Deleting the Default Pools
Get-UcsOrg -Level root | Get-UcsUuidSuffixPool -Name "default" -LimitScope | Remove-UcsUuidSuffixPool -Force
Get-UcsOrg -Level root | Get-UcsServerPool -Name "default" -LimitScope | Remove-UcsServerPool -Force
Get-UcsOrg -Level root | Get-UcsMacPool -Name "default" -LimitScope | Remove-UcsMacPool -Force
Get-UcsOrg -Level root | Get-UcsIqnPoolPool -Name "default" -LimitScope | Remove-UcsIqnPoolPool -Force
Get-UcsOrg -Level root | Get-UcsWwnPool -Name "node-default" -LimitScope | Remove-UcsWwnPool -Force
Get-UcsOrg -Level root | Get-UcsWwnPool -Name "default" -LimitScope | Remove-UcsWwnPool -Force

#Changing the default iscsi Pool
Get-UcsOrg -Level root | Get-UcsIpPool -Name "iscsi-initiator-pool" -LimitScope | Add-UcsIpPoolBlock -From "1.1.1.1" -To "1.1.1.1"

#Creation of VLANs
Get-UcsLanCloud | Add-UcsVlan -Name LAN -Id 11
Get-UcsLanCloud | Add-UcsVlan -Name DMZ -Id 20


##############Creation of Pools##############
#Creation of ext-MGMT Pool
Get-UcsOrg -Level root | Get-UcsIpPool -Name "ext-mgmt" -LimitScope | Add-UcsIpPoolBlock -DefGw "192.168.175.254" -From "192.168.175.170" -PrimDns "192.168.200.10" -To "192.168.175.185"

#Creation of UUID Pool
Start-UcsTransaction
$mo = Get-UcsOrg -Level root | Get-UcsOrg -Name "<NAME>" -LimitScope | Add-UcsUuidSuffixPool -AssignmentOrder "default" -Descr "" -Name "<NAME>" -PolicyOwner "local" -Prefix "derived"
$mo_1 = $mo | Add-UcsUuidSuffixBlock -From "0002-000000000001" -To "0002-00000000003C"
Complete-UcsTransaction

#Creation of MAC-Pool
Start-UcsTransaction
$mo = Get-UcsOrg -Level root | Get-UcsOrg -Name "<NAME>" -LimitScope | Add-UcsMacPool -AssignmentOrder "default" -Descr "" -Name "<NAME>" -PolicyOwner "local"
$mo_1 = $mo | Add-UcsMacMemberBlock -From "00:25:B5:21:00:00" -To "00:25:B5:21:00:C8"
Complete-UcsTransaction
Advertisements

2 thoughts on “Cisco UCS Manager PowerTool – Sample Script

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s