Wednesday, October 26, 2016

Automated UCS PowerTool - provision by service profile name - create DHCP & DNS

Install Cisco IMC PowerTool 2.0.2.2+
Save as .PS1

#region Load the UCS PowerTool
Write-Output "Checking Cisco PowerTool"
$PowerToolLoaded = $null
$Modules = Get-Module
$PowerToolLoaded = $modules.name
if ( -not ($Modules -like "Cisco.UCS.Core"))
{
Write-Output " Loading Module: Cisco UCS PowerTool Module"
Import-Module Cisco.UCS.Core
$Modules = Get-Module
if ( -not ($Modules -like "Cisco.UCS.Core"))
{
Write-Output ""
Write-Output "Cisco UCS PowerTool Module did not load.  Please correct his issue and try again"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Output " PowerTool is Loaded"
}
}
else
{
Write-Output " PowerTool is Loaded"
}
#endregion
#region UCS Login
#Define UCS Domain(s)
Write-Output ""
Write-Output "Connecting to UCSM"
if (!([string]::IsNullOrEmpty($UCSM)))
{
$myucs = $UCSM
}
else
{
$myucs = Read-Host "Enter UCS system IP or Hostname"
}
if (($myucs -eq "") -or ($myucs -eq $null) -or ($Error[0] -match "PromptingException"))
{
Write-Output ""
Write-Output "You have provided invalid input."
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Disconnect-Ucs
}

#Test that UCSM is IP Reachable via Ping
Write-Output ""
Write-Output "Testing reachability to UCSM"
$ping = new-object system.net.networkinformation.ping
$results = $ping.send($myucs)
if ($results.Status -ne "Success")
{
Write-Output " Can not access UCSM $myucs by Ping"
Write-Output ""
Write-Output "It is possible that a firewall is blocking ICMP (PING) Access."
if ($SKIPERROR)
{
$Try = "y"
}
else
{
$Try = Read-Host "Would you like to try to log in anyway? (Y/N)"
}
if ($Try -ieq "y")
{
Write-Output ""
Write-Output "Trying to log in anyway!"
}
elseif ($Try -ieq "n")
{
Write-Output ""
Write-Output "You have chosen to exit"
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
Write-Output ""
Write-Output "You have provided invalid input.  Please enter (Y/N) only."
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
}
else
{
Write-Output " Successfully pinged UCSM: $myucs"
}

#Allow Logins to single or multiple UCSM systems
$multilogin = Set-UcsPowerToolConfiguration -SupportMultipleDefaultUcs $false

#Log into UCSM
Write-Output ""
Write-Output "Logging into UCSM"

#Verify PowerShell Version to pick prompt type
if (!$UCREDENTIALS)
{
if (!$USAVEDCRED)
{
Write-Output " Enter your UCSM credentials"
$credu = Get-Credential -Message "UCSM(s) Login Credentials" -UserName "network"

}
else
{
$CredFile = import-csv $USAVEDCRED
$Username = $credfile.UserName
$Password = $credfile.EncryptedPassword
$credu = New-Object System.Management.Automation.PsCredential $Username,(ConvertTo-SecureString $Password)
}
}
#Log into UCSM
$myCon = Connect-Ucs $myucs -Credential $credu

#Check to see if log in was successful
if (($myucs | Measure-Object).count -ne ($myCon | Measure-Object).count)
{
Write-Output " Error Logging into UCS."
Write-Output " Make sure your user has login rights the UCS system and has the"
Write-Output " proper role/privledges to use this tool..."
Write-Output " Exiting..."
Disconnect-Ucs
exit
}
else
{
if (!$UCREDENTIALS)
{
Write-Output " Login Successful"
}
else
{
Write-Output " Login Successful"
}
}

#endregion
#region Functions
function New-IPRange {
[cmdletbinding()]
param (
    [parameter( Mandatory = $true,
                Position = 0 )]
    [System.Net.IPAddress]$Start,

    [parameter( Mandatory = $true,
                Position = 1)]
    [System.Net.IPAddress]$End,

    [int[]]$Exclude = @( 0, 1, 255 )
)
    $ip1 = $start.GetAddressBytes()
    [Array]::Reverse($ip1)
    $ip1 = ([System.Net.IPAddress]($ip1 -join '.')).Address

    $ip2 = ($end).GetAddressBytes()
    [Array]::Reverse($ip2)
    $ip2 = ([System.Net.IPAddress]($ip2 -join '.')).Address

    for ($x=$ip1; $x -le $ip2; $x++)
    {
        $ip = ([System.Net.IPAddress]$x).GetAddressBytes()
        [Array]::Reverse($ip)
        if($Exclude -notcontains $ip[3])
        {
            $ip -join '.'
        }
    }
}
Function Add-DHCP ($script:scope, $script:ReservedIP, $script:MAC, $script:ReservedName){
Write-Output "Adding $script:ReservedIP with $script:ReservedName and $script:MAC to DHCP"
netsh dhcp server "$($script:DHCPServer)" scope $script:scope add reservedip $script:ReservedIP $script:MAC $script:ReservedName

}
Function Add-DNS ($script:SPName, $script:ReservedIP){
$script:SPNamePTR = "$(($script:SPName).ToUpper()).$(($script:domain).ToUpper())"
#$script:addr = $script:ReservedIP -split "\."
#$script:rzone = "$($addr[2]).$($addr[1]).$($addr[0]).in-addr.arpa"

#Create Dns entries
Write-Output "Adding $ReservedIP with $SPNamePTR to DNS"
dnscmd $script:DNSServer /recordadd $script:domain "$($script:SPName)" A "$($script:ReservedIP)"

#Create reverse DNS
#dnscmd $script:DNSServer /recordadd $rzone "$($addr[3])" PTR $SPNamePTR

}

#endregion
#region Select ServiceProfiles
$FullListNICs=Get-UcsServiceProfile | Get-UcsVnic |where {$_.Dn -like "org-root/org-VDi-UCS/ls-BTPESX*/ether-vNIC-A"}
$selectionList=($FullListNICs|%{($_.dn).Split("/")[2].trimstart("ls-")})

$Script:SelectedObjects = @()
$Script:Exit = 'n'

[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing")

$objForm = New-Object System.Windows.Forms.Form
$objForm.Text = "Service Profiles"
$objForm.Size = New-Object System.Drawing.Size(300,600)
$objForm.StartPosition = "CenterScreen"

$objForm.KeyPreview = $True

$objForm.Add_KeyDown({if ($_.KeyCode -eq "Enter")
    {
        foreach ($objItem in $objListbox.SelectedItems)
        {$Script:SelectedObjects += $objItem}
$objForm.Close()
}
})

$objForm.Add_KeyDown({if ($_.KeyCode -eq "Escape")
{$objForm.Close(); Write-Output "" ; Write-Output "You pressed Escape"; Write-Output " exiting..."; Disconnect-Ucs; $Script:Exit = "y"}})

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(75,500)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"

$OKButton.Add_Click(
    {
        foreach ($objItem in $objListbox.SelectedItems)
            {$Script:SelectedObjects += $objItem}
        $objForm.Close()
    })

$objForm.Controls.Add($OKButton)

$CancelButton = New-Object System.Windows.Forms.Button
$CancelButton.Location = New-Object System.Drawing.Size(150,500)
$CancelButton.Size = New-Object System.Drawing.Size(75,23)
$CancelButton.Text = "Cancel"
$CancelButton.Add_Click({$objForm.Close(); Write-Output ""; Write-Output "You pressed Cancel"; Disconnect-Ucs; $Script:Exit = "y"})
$objForm.Controls.Add($CancelButton)

$objLabel = New-Object System.Windows.Forms.Label
$objLabel.Location = New-Object System.Drawing.Size(10,20)
$objLabel.Size = New-Object System.Drawing.Size(280,20)
$objLabel.Text = "Select from below. SHIFT or CNTRL for multi-select:"
$objForm.Controls.Add($objLabel)

$objListbox = New-Object System.Windows.Forms.Listbox
$objListbox.Location = New-Object System.Drawing.Size(10,40)
$objListbox.Size = New-Object System.Drawing.Size(260,20)
$objListBox.Sorted = $True

$objListbox.SelectionMode = "MultiExtended"
if ($selectionList.count -le 1)
{
[void] $objListbox.Items.Add("--ALL--")
}
foreach ($Selection in $selectionList)
{
[void] $objListbox.Items.Add($Selection)
}

$objListbox.Height = 450
$objForm.Controls.Add($objListbox)
$objForm.Topmost = $True

$objForm.Add_Shown({$objForm.Activate()})
[void] $objForm.ShowDialog()
#endregion
#region Variables
$script:DNSServer = "10.1.21.99"
$script:DHCPServer= "10.1.21.109"
$script:domain = "$((Get-ADDomain).forest)"
$script:IPSub= Read-Host 'What is the Subnet? (default = "10.1.14.")'
if([string]::IsNullOrEmpty($script:IPSub)){$script:IPSub = "10.1.14."}
$script:IPOct= Read-Host 'What is the Starting Octet? ("50")'
$script:IPCount= $Script:SelectedObjects.count
$startIP= $script:IPSub+$script:IPOct
$endIP=$script:IPSub+([int]($script:IPOct)+[int]($script:IPCount))
$script:IParray=@()
$script:resultsCount=0
$script:outip=""
#endregion

#region Create IP List
New-IPRange -Start $startIP -End $endIP|%{$IParray+=$_}
            foreach ($IP in $IParray){
            $Results=Test-Connection $ip -count 2 -quiet
            If($results -eq $true){$script:resultsCount++;$script:OutIP+="`n$($ip) Is Responding!!"}
            If($script:resultsCount -ge "1"){Write-host "$($script:outip)";break}
                                }
#endregion

#region Process the
$serviceProfiles=$FullListNICs|where{$Script:SelectedObjects -contains (($_.dn).Split("/")[2].trimstart("ls-"))}
$script:SPcount
$Nextip=0
        foreach($serviceProfile in $serviceProfiles){

                $script:SPName = (($serviceProfile.Dn).Split("/")[2].trimstart("ls-"))
                $script:ReservedName= "$(($SPName).ToUpper()).$(($script:domain).ToUpper())"
                $script:MAC = (($serviceprofile.addr).Replace(":","")).tolower()
                $script:scope=("$($script:IPSub)0")
                $script:ReservedIP = $IParray[$Nextip]

                Add-DNS $script:SPName $script:ReservedIP
                Add-DHCP $script:scope $script:ReservedIP $script:MAC $script:ReservedName
                $Nextip++
                    }
#endregion

Changing UCS IP addresses

Changing UCS IP addresses

I have a UCS lab machine that I sometimes take to different locations for proof of concept work.  One of the things I regularly have to do is change the password and hostname.  Here’s how you do it on the command line:
KCTest-A# scope fabric-interconnect a
KCTest-A /fabric-interconnect # set out-of-band ip 10.1.1.23 netmask 255.255.255.0 gw 10.1.1.1
Warning: When committed, this change may disconnect the current CLI session
KCTest-A /fabric-interconnect* # scope fabric-interconnect b
KCTest-A /fabric-interconnect* # set out-of-band ip 10.1.1.24 netmask 255.255.255.0 gw 10.1.1.1
Warning: When committed, this change may disconnect the current CLI session
KCTest-A /fabric-interconnect* # scope system
KCTest-A /system* # set virtual-ip 10.1.1.25
KCTest-A /system* # set name ccielab
KCTest-A /system* # commit-buffer

Monday, October 24, 2016

UCS CONVERTTO-UCSCMDLET PROCEDURE:

  1. Load  Manager PowerTool. 
  2. Connect to a UCSM cluster IP (or emulator) by typing “Connect-Ucs <UCSM-IP address> or <hostname>” command. Enter the UCSM login details when prompted.
  3. After successful login, execute the cmdlet “Start-UcsGuiSession -LogAllXml” in Powertool to kick off the UCSM GUI.
  4. Once GUI has launched, type “ConvertTo-UcsCmdlet” in the PowerTool window prompt.
  5. To get the commands for an action within UCSM, perform the steps as you would want within UCS GUI. e.g. Create a VLAN or Add a VLAN to vNIC template. If you are familiar with Excel Micros then this step would be something similar.
  6. After few seconds, UCS Powertool will spit out the cmdlets for the action you just performed in UCSM GUI.
If you have a long list of VLANS to add then best to stick it in an Excel spreadsheet and do what I did below and then save full commands as filename.ps1:

Excel UCS concatenate cmdlets

In some cases, where you already have bunch of VLANs within UCS and you wish to add some of it to VLAN Groups, then it’s easier to export the names to a CSV from the screen below and do what I did with Excel above to concatenate.

UCSM VLAN Export CSV
Some other common cmdlets in UCS Powertool are:
  • Get-Ucsblade
  • Get-UcsServiceProfile
  • Connect-UcsServiceProfile -ServiceProfile ServiceProfileName -Blade ServerID
  • Full reference list of Reference guide for Powertool can be found here for version 1.x.
You can check the operational status of the cluster and Fabric Interconnects using “Get-ucsfimodule ¦ select descr,operstate“.

Cisco UCS Powertool status


UCS POWERTOOL SCRIPTS EXAMPLE

Download instruction at end of this table!
1Power OFF unassociated UCS BladesThis script will enable you to power down un-associated blades by creating temporary service profiles. You’ll be surprised how much power you can save in a large server estate if you have unused UCS blades.
2UCS AD Authentication IntegrationPowershell script to automate LDAP / Active Directory integration of UCSM.
3UCS Inventory ToolPopulates spreadsheet with extracted hardware information from UCS as an inventory.
4Quick Launch UCSM GUI PowerShell ScriptConnect to UCSM GUI without asking for login prompt. This creates a secure credential file so it bypasses default login process.
5Multi-Domain UCS Backup ScriptLogin multiple UCS domains and take all 4 types of back ups.
6Set User Labels for ServersCreate user labels for rack and blade servers for better inventory.
7UCS WWPN Collector ScriptPowershell script to output WWPN and vHBA details for each service profiles. Usually handy if you need to pass this information to SAN administrator for Zoning.
8UCS Serial Number Export Script Useful tool to if you need all the serial numbers to register with SmartNet.
9Generate SAN Zones for Brocade or MDS Collect Aliases, Zones and Zone Sets for Cisco MDS/Nexus or Brocade.
10Checks the current bandwidth of all adapters Displays details of bandwidth on all the vNIC adapters.
 Download these and more powershell scripts Powershell script samples
Let us know if you are trying to script a task using this tool.

Cisco SAN Manager + UCS message of no traps fix

Cisco SAN Manager displays UCS annoying FI's no traps status?

Resolve by setting up the UCS SNMP trap configuration to the IP of the DCNM server

Configure a trap destination of the IP address for DCNM.
Use version 2C, community public, udp-port 2162
Enable SNMP and save the config.
It will take a short while for DCNM to turn off the "no traps" warning.


Monday, October 17, 2016

UCS Fabric Interconnect factory reset or services

pmon stop
pmon start




This article will show you how to clear and erase the configuration of a Cisco UCS 6200 Fabric Interconnect Switch.
To start log in to the switch using a serial cable via the console port,
Once connected type connect local-mgmt

Type erase configuration

Once done wait a few minutes for the switch to restart

Now you can start configuring the switch.






How to force a Cisco UCS 6100 series fabric interconnect to become the primary node in a cluster
I ran into an extremely annoying problem today while setting up a new UCS B series infrastructure cluster for a client where a newly configured 6120 would get stuck in an election progress and seemingly never promotes itself to become the primary fabric interconnect even though the other node is down.  The following is what the command show cluster state outputs:
A: UP, ELECTION IN PROGRESS (Management services: UP)
B: UNRESPONSIVE, INAPPLICABLE, (Management services: UNRESPONSIVE)

The reason why this problem was annoying was because as long as this fabric is stuck in this state, I was not able to log into UCS Manager to work with the GUI.  I know enough to get around within the CLI but tasks such as reviewing the logs to troubleshoot was much easier to do with the GUI.  To get around this, you can use the following command to force the fabric interconnect that is stuck in limbo to become primary node:
connect local-mgmt
cluster force primary


Once you’ve successfully forced the fabric interconnect to become the primary node, you will be able to connect to UCS Manager via the cluster IP.

Wednesday, October 5, 2016

Update the server VM Tools without a reboot:

Update the server VM Tools without a reboot:
Under the Advanced Options during the VM Tools install enter the string       /S /v"/qn REBOOT=R

Vmware NSX SSL creation 

Using OpenSSL for NSX Manager SSL import: Creates CSR and 4096 bit KEY Creating NSX 6.4.2 SSL    openssl req -out nsxcert.csr -newkey rsa:40...