New UCS Domain Config

Version 1

    UCS Power Scripting Submission Form

     

    UCS Communities Login ID: alberto.yanes

    Twitter handle (optional): <Name>

    Have you read the Official Rules of the Contest and do you accept the terms and conditions     Yes  [ x ]    No  [   ]

    Are you a Cisco employee                                                                                                                          Yes  [  ]    No  [ x ]

    Does the script run on an emulator -                                                                                                          Yes [ x ]    No  [   ]

              If yes which version? ____2.1.1f____

     

     

    Include your script here:

    Script was created as a Company need to configure a new Domain with no FC connectivity in this case.

    Pre-requisites.

    All required chassis and blades have to be previously discovered.

    Desired Firmware version uploaded to UCSM (I am using 2.1.1f)

    LAN Uplinks previously configured.

    Used .csv file attached.


    #VARIABLES

    $UCSMIP = "x.x.x.x"

     

     

    $Timezone = "America/New_York (Eastern Time)"

    $SyslogServer = "x.x.x.x"

    $SNMPString = "string"

    $SubOrganization = "Contest"

    $DestinationOrg = "org-root/org-Contest"

     

     

    $SP_Template_FAB_A = "Fabric_A"

    $SP_Template_FAB_B = "Fabric_B"

     

     

    $vNICTemplateFAB_A = "vNIC_Fabric_A"

    $vNICTemplateFAB_B = "vNIC_Fabric_B"

     

     

    #POOLS VARIABLES

    $MACPoolName_FabricA = "MAC-A"

    $MACPoolName_FabricB = "MAC-B"

     

     

    $MACPoolFrom_FabricA = "00:25:B5:XX:XX:XX"

    $MACPoolTo_FabricA = "00:25:B5:XX:XX:XX"

    $MACPoolFrom_FabricB = "00:25:B5:XX:XX:XX"

    $MACPoolTo_FabricB = "00:25:B5:XX:XX:XX"

     

     

    $MGMTIP_Gateway = "x.x.x.x"

    $MGMTIP_From = "x.x.x.x" #size 80

    $MGMTIP_TO = "x.x.x.x"

    $Subnet = "255.255.255.0"

     

     

    #POLICIES VARIABLES

    $BIOSPolicy_Standard = "Standard"

    $BootPolicy_PXE = "PXE"

    $LD_Policy = "RAID1"

    $ScrubPolicy = "NO_SCRUB"

    $HostFirmware = "2.1.1f"

    $BundleVersion = "2.1(1f)B"

     

     

    #VLANS VARIABLES

    $VLANname = "VLAN_X"

    $VLANID = "X"

     

     

    #Browse Input file path

    Function get-filename ($initialDirectory)

    {  

    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null

    $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog

    $OpenFileDialog.initialDirectory = $initialDirectory

    $OpenFileDialog.filter = "All files (*.*)| *.*"

    $OpenFileDialog.ShowDialog() | Out-Null

    $OpenFileDialog.filename

    $OpenFileDialog.ShowHelp = $true

    } #end function Get-FileName

     

     

    $CSV = Get-FileName -initialDirectory "c:\Scripts"

    $ImportCSV = Import-Csv $CSV

     

     

    #################################### END OF VARIABLES #####################################

     

     

    #CONNECT TO UCSM

    $Password = cat "C:\ucs-admin-pwd.txt" | convertto-securestring

    $Credentials = New-Object System.Management.Automation.PSCredential -argumentlist "admin", $Password

    Connect-Ucs $UCSMIP -Credential $Credentials

     

     

    #Add Suborganization

    Add-UcsOrg -Name $SubOrganization

     

     

    #Syslog Server

    Get-UcsSyslogClient -Name "primary" | Set-UcsSyslogClient -AdminState "enabled" -ForwardingFacility "local7" -Hostname $SyslogServer -Severity "information" -Force

     

     

    #Set NTP Server

    Add-UcsNtpServer -Descr "" -Name "ntp1"

    Add-UcsNtpServer -Descr "" -Name "ntp2"

     

     

    #Set UCS DNS servers

    Add-UcsDnsServer -Descr "" -Name "x.x.x.x"

    Add-UcsDnsServer -Descr "" -Name "x.x.x.x"

     

     

    #Set Timezone########################

    Get-UcsTimezone | Set-UcsTimezone -AdminState enabled -Descr "" -Port 0 -Timezone $Timezone -Force

     

     

    #Set SNMP############################

    Set-UcsSnmp -AdminState enabled -Community $SNMPString -SysContact "24x7" -Force

     

     

    #Set SNMP Traps######################

    Add-UcsSnmpTrap -Community "name" -Hostname "x.x.x.x" -NotificationType "traps" -Port 162 -V3Privilege "noauth" -Version "v3"

    Add-UcsSnmpTrap -Community "name" -Hostname "x.x.x.x" -NotificationType "traps" -Port 162 -V3Privilege "noauth" -Version "v3"

    Add-UcsSnmpTrap -Community "name" -Hostname "x.x.x.x" -NotificationType "traps" -Port 162 -V3Privilege "noauth" -Version "v3"

     

     

    #Call Home 24x7 profile

    Start-UcsTransaction

    $mo = Add-UcsCallhomeProfile -AlertGroups "diagnostic","environmental" -Descr "" -Format "shortTxt" -Level "warning" -MaxSize 1000000 -Name "24x7"

    $mo_1 = $mo | Add-UcsCallhomeRecipient -Email "email01@domain.com"

    Complete-UcsTransaction

     

     

    #Call Home NSM profile

    Start-UcsTransaction

    $mo = Add-UcsCallhomeProfile -AlertGroups "diagnostic","environmental" -Descr "" -Format "shortTxt" -Level "warning" -MaxSize 1000000 -Name "other"

    $mo_1 = $mo | Add-UcsCallhomeRecipient -Email "email02@domain.com"

    Complete-UcsTransaction

     

     

    #Edit Existing Call Home profiles

    Get-UcsCallhomeProfile -Name "CiscoTAC-1" | Add-UcsCallhomeRecipient -Email "callhome@cisco.com"

    Get-UcsCallhomeProfile -Name "full_txt" | Add-UcsCallhomeRecipient -Email "email03@domain.com"

     

     

    #Enable Call Home System Inventory

    Start-UcsTransaction

    $mo = Get-UcsCallhome | Set-UcsCallhome -AdminState "off" -AlertThrottlingAdminState "on" -Descr "" -Name "" -PolicyOwner "local" -Force

    $mo_1 = Get-UcsCallhomePeriodicSystemInventory | Set-UcsCallhomePeriodicSystemInventory -AdminState "on" -IntervalDays 15 -MaximumRetryCount 1 -MinimumSendNowIntervalSeconds 5 -PollIntervalSeconds 300 -RetryDelayMinutes 10 -SendNow "no" -TimeOfDayHour 21 -TimeOfDayMinute 30 -Force

    $mo_2 = Get-UcsCallhomeSmtp | Set-UcsCallhomeSmtp -Host "x.x.x.x" -Port 25 -Force

    $mo_3 = Get-UcsCallhomeSource | Set-UcsCallhomeSource -Addr "address" -Contact "24x7" -Contract "1111111" -Customer "1111111" -Email "email01@domain.com" -From "ucs@domain.com" -Phone "+1-000-000-0000" -ReplyTo "24x7@domain.com" -Site "111111111" -Urgency "info" -Force

    Complete-UcsTransaction

     

     

    #Create global VLAN##################

    Get-UcsLanCloud | Add-UcsVlan -DefaultNet no -Id $VLANID -Name $VLANname -PubNwName "" -Sharing none

     

     

    #Create MGMT IP Pool#################

    Get-UcsOrg -Level root | Get-UcsIpPool -Name ext-mgmt -LimitScope | Add-UcsIpPoolBlock -DefGw $MGMTIP_Gateway -From $MGMTIP_From -To $MGMTIP_TO -Subnet $Subnet

     

     

    #Create iSCSI IP Pool################

    Get-UcsOrg -Level root | Get-UcsIpPool -Name iscsi-initiator-pool -LimitScope | Add-UcsIpPoolBlock -DefGw 1.1.1.1 -From 1.1.1.10 -To 1.1.1.10

     

     

    #BOOT POLICY#########################

    Start-UcsTransaction

    $mo = Get-UcsOrg -Level root  | Add-UcsBootPolicy -Descr "" -EnforceVnicName "no" -Name $BootPolicy_PXE -PolicyOwner "local" -RebootOnUpdate "no"

    $mo_1 = $mo | Add-UcsLsbootLan -ModifyPresent -Order "1" -Prot "pxe"

    $mo_1_1 = $mo_1 | Add-UcsLsbootLanImagePath -BootIpPolicyName "" -ISCSIVnicName "" -ImgPolicyName "" -ImgSecPolicyName "" -ProvSrvPolicyName "" -Type "primary" -VnicName "eth0"

    $mo_2 = $mo | Add-UcsLsbootVirtualMedia -Access "read-only" -Order "2"

    $mo_3 = $mo | Add-UcsLsbootStorage -Order "3"

    $mo_3_1 = $mo_3 | Add-UcsLsbootLocalStorage

    Complete-UcsTransaction

     

     

    #Host Firmware Package###############

    Get-UcsOrg -Level root  | Add-UcsFirmwareComputeHostPack -BladeBundleVersion $BundleVersion -Descr "" -IgnoreCompCheck "yes" -Mode "staged" -Name $HostFirmware -PolicyOwner "local" -RackBundleVersion "" -StageSize 0 -UpdateTrigger "immediate"

     

     

    #LOCAL DISK POLICY###################

    Get-UcsOrg -Level root -LimitScope | Add-UcsLocalDiskConfigPolicy -Descr "Local Disk Policy" -Mode raid-mirrored -Name $LD_Policy -ProtectConfig yes

     

     

    #Scrub policy########################

    Get-UcsOrg -Level root -LimitScope | Add-UcsScrubPolicy -BiosSettingsScrub no -Descr "Scrub Policy" -DiskScrub no -Name $ScrubPolicy

     

     

    #BIOS Policy Standard#################

    Get-UcsOrg -Level root  | Add-UcsBiosPolicy -Descr "" -Name $BIOSPolicy_Standard -PolicyOwner "local" -RebootOnUpdate "no"

     

     

    #Pre-login Banner#################

    Add-UcsPreLoginBanner -Descr "" -Message @'

     

     

    BANNER GOES HERE

     

     

    Unauthorized access....

     

     

    1)

    2)

     

     

    '@ -PolicyOwner "local"

     

     

    #Remove Default Pools################

    Get-UcsServerPool | where {$_.name -like "*default*"} | Remove-UcsServerPool -Force -Confirm:$false

    Get-UcsMacPool | where {$_.name -like "*default*"} | Remove-UcsMacPool -Force -Confirm:$false

     

     

    #Change Default MGMT Policy to User-Ack

    Get-UcsOrg -Level root | Get-UcsMaintenancePolicy -Name "default" -LimitScope | Set-UcsMaintenancePolicy -Descr "" -PolicyOwner "local" -SchedName "" -UptimeDisr "user-ack" -Force

     

     

    #UUID Pool

    Get-UcsOrg -Level root | Get-UcsUuidSuffixPool -Name "default" -LimitScope | Add-UcsUuidSuffixBlock -From "0000-000000000001" -To "0000-000000000100"

     

     

    #MAC Pool FABRIC A

    Start-UcsTransaction

    $mo = Get-UcsOrg -Level root  | Add-UcsMacPool -AssignmentOrder "default" -Descr "" -Name $MACPoolName_FabricA -PolicyOwner "local"

    $mo_1 = $mo | Add-UcsMacMemberBlock -From $MACPoolFrom_FabricA -To $MACPoolTo_FabricA

    Complete-UcsTransaction

     

     

    #MAC Pool FABRIC B

    Start-UcsTransaction

    $mo = Get-UcsOrg -Level root  | Add-UcsMacPool -AssignmentOrder "default" -Descr "" -Name $MACPoolName_FabricB -PolicyOwner "local"

    $mo_1 = $mo | Add-UcsMacMemberBlock -From $MACPoolFrom_FabricB -To $MACPoolTo_FabricB

    Complete-UcsTransaction

     

     

    #WWNN Pool

    Get-UcsOrg -Level root | Get-UcsWwnPool -Name "node-default" -LimitScope | Add-UcsWwnMemberBlock -From "20:00:00:25:B5:00:00:00" -To "20:00:00:25:B5:00:00:00"

     

     

    #WWPN Pool

    Get-UcsOrg -Level root | Get-UcsWwnPool -Name "default" -LimitScope | Add-UcsWwnMemberBlock -From "20:00:00:25:B5:00:00:00" -To "20:00:00:25:B5:00:00:00"

     

     

    #IQN Pool

    Get-UcsOrg -Level root | Get-UcsIqnPoolPool -Name "default" -LimitScope | Add-UcsIqnPoolBlock -From 0 -Suffix "IQN" -To 0

     

     

    #vNIC Templates A/B Side

    Get-UcsOrg -Level root | Get-UcsOrg -Name $SubOrganization -LimitScope | Add-UcsVnicTemplate -Descr "" -IdentPoolName $MACPoolName_FabricA -Mtu 1500 -Name $vNICTemplateFAB_A -NwCtrlPolicyName "" -PinToGroupName "" -QosPolicyName "" -StatsPolicyName default -SwitchId A-B -Target adaptor -TemplType updating-template

    Get-UcsOrg -Level root | Get-UcsOrg -Name $SubOrganization -LimitScope | Add-UcsVnicTemplate -Descr "" -IdentPoolName $MACPoolName_FabricB -Mtu 1500 -Name $vNICTemplateFAB_B -NwCtrlPolicyName "" -PinToGroupName "" -QosPolicyName "" -StatsPolicyName default -SwitchId B-A -Target adaptor -TemplType updating-template

     

     

    #Add VLAN to vNIC Templates

    Get-UcsVnicTemplate -Name $vNICTemplateFAB_A | Add-UcsVnicInterface -ModifyPresent -Name $VLANname -DefaultNet yes

    Get-UcsVnicTemplate -Name $vNICTemplateFAB_B | Add-UcsVnicInterface -ModifyPresent -Name $VLANname -DefaultNet yes

     

     

    #Create Service Profile TEMPLATE FAB A

    Start-UcsTransaction

    $mo = Get-UcsOrg -Level root | Get-UcsOrg -Name $SubOrganization -LimitScope | Add-UcsServiceProfile -AgentPolicyName "" -BiosProfileName $BIOSPolicy_Standard -BootPolicyName $BootPolicy_PXE -Descr "" -DynamicConPolicyName "" -ExtIPState none -HostFwPolicyName $HostFirmware -IdentPoolName "default" -LocalDiskPolicyName $LD_Policy -MaintPolicyName "default" -MgmtAccessPolicyName "" -MgmtFwPolicyName "" -Name $SP_Template_FAB_A -PowerPolicyName default -ScrubPolicyName $ScrubPolicy -SolPolicyName "" -SrcTemplName "" -StatsPolicyName default -Type updating-template -UsrLbl "" -Uuid 0 -VconProfileName ""

    $mo_1 = $mo | Add-UcsVnicDefBeh -ModifyPresent -Action none -NwTemplName "" -Type vhba

    $mo_2 = $mo | Add-UcsVnic -AdaptorProfileName Linux -Addr derived -AdminVcon any -IdentPoolName "" -Mtu 1500 -Name eth0 -NwCtrlPolicyName "" -NwTemplName $vNICTemplateFAB_A -Order 1 -PinToGroupName "" -QosPolicyName "" -StatsPolicyName default -SwitchId A-B

    $mo_3 = $mo | Add-UcsVnicFcNode -ModifyPresent -Addr pool-derived -IdentPoolName "node-default"

    $mo_4 = $mo | Set-UcsServerPower -State up -Force

    Complete-UcsTransaction

    Start-UcsTransaction

    $mo = Get-UcsOrg -Level root | Get-UcsOrg -Name $SubOrganization -LimitScope | Get-UcsServiceProfile -Name $SP_Template_FAB_A

    $mo_1 = $mo | Add-UcsVnicFcNode -ModifyPresent -Addr pool-derived -IdentPoolName "node-default"

    Complete-UcsTransaction

     

     

    #Create Service Profile TEMPLATE FAB B

    Start-UcsTransaction

    $mo = Get-UcsOrg -Level root | Get-UcsOrg -Name $SubOrganization -LimitScope | Add-UcsServiceProfile -AgentPolicyName "" -BiosProfileName $BIOSPolicy_Standard -BootPolicyName $BootPolicy_PXE -Descr "" -DynamicConPolicyName "" -ExtIPState none -HostFwPolicyName $HostFirmware -IdentPoolName "default" -LocalDiskPolicyName $LD_Policy -MaintPolicyName "default" -MgmtAccessPolicyName "" -MgmtFwPolicyName "" -Name $SP_Template_FAB_B -PowerPolicyName default -ScrubPolicyName $ScrubPolicy -SolPolicyName "" -SrcTemplName "" -StatsPolicyName default -Type updating-template -UsrLbl "" -Uuid 0 -VconProfileName ""

    $mo_1 = $mo | Add-UcsVnicDefBeh -ModifyPresent -Action none -NwTemplName "" -Type vhba

    $mo_2 = $mo | Add-UcsVnic -AdaptorProfileName Linux -Addr derived -AdminVcon any -IdentPoolName "" -Mtu 1500 -Name eth0 -NwCtrlPolicyName "" -NwTemplName $vNICTemplateFAB_B -Order 1 -PinToGroupName "" -QosPolicyName "" -StatsPolicyName default -SwitchId B-A

    $mo_3 = $mo | Add-UcsVnicFcNode -ModifyPresent -Addr pool-derived -IdentPoolName "node-default"

    $mo_4 = $mo | Set-UcsServerPower -State up -Force

    Complete-UcsTransaction

    Start-UcsTransaction

    $mo = Get-UcsOrg -Level root | Get-UcsOrg -Name $SubOrganization -LimitScope | Get-UcsServiceProfile -Name $SP_Template_FAB_B

    $mo_1 = $mo | Add-UcsVnicFcNode -ModifyPresent -Addr pool-derived -IdentPoolName "node-default"

    Complete-UcsTransaction

     

     

    #Create Service Profiles from Template

    foreach ($SP in $ImportCSV)

    {

     

     

      if (($SubOrganization -like "VMware") -or ($SubOrganization -like "Corp") -or ($SubOrganization -like "MGMT"))

      {

      Write-Host “Creating Service Profile $($SP.NewServiceProfile)” -BackgroundColor Yellow -ForegroundColor Black

      Get-UcsServiceProfile -Name $SP.SourceTemplate | Add-UcsServiceProfileFromTemplate -NewName $SP.NewServiceProfile -DestinationOrg ($DestinationOrg + "/org-" + $SP.Cluster)

     

      Write-Host “Associating Service Profile $($SP.NewServiceProfile) to Chassis $($SP.ChassisID) Slot $($SP.BladeID)” -BackgroundColor Yellow -ForegroundColor Black

      $blade = Get-UcsBlade -ChassisId $SP.ChassisID -SlotId $SP.BladeID

      Get-UcsServiceProfile -Name $SP.NewServiceProfile | Connect-UcsServiceProfile -Blade $blade -Force

     

      }

     

     

     

      else

      {

      Write-Host “Creating Service Profile $($SP.NewServiceProfile)” -BackgroundColor Yellow -ForegroundColor Black

      Get-UcsServiceProfile -Name $SP.SourceTemplate | Add-UcsServiceProfileFromTemplate -NewName $SP.NewServiceProfile -DestinationOrg ($DestinationOrg)

     

      Write-Host “Associating Service Profile $($SP.NewServiceProfile) to Chassis $($SP.ChassisID) Slot $($SP.BladeID)” -BackgroundColor Yellow -ForegroundColor Black

      $blade = Get-UcsBlade -ChassisId $SP.ChassisID -SlotId $SP.BladeID

      Get-UcsServiceProfile -Name $SP.NewServiceProfile | Connect-UcsServiceProfile -Blade $blade -Force

     

      }

     

     

     

     

    }

     

     

     

     

     

     

    Disconnect-Ucs