Quick post regarding an annoying but avoidable issue I encountered when utilizing Cisco UCS PowerTool today. I have been developing some SMA runbooks to take care of some common tasks with UCS such as deploying Service Profiles from Template. I am of course utilizing Cisco’s UCS PowerShell Module: UCS PowerTool to accomplish this task. When utilizing PowerTool your connection to the UCS is considered a “handle” in Cisco documentation. When doing anything with PowerTool you first build a handle to the UCS and then reference the handle in the Cmdlets. Here is an example of this:

Import-Module ciscoUcsPs  
$UCSCredential = Get-Credential
$UCSHandle = Connect-Ucs -Name ucs1c -NotDefault -Credential $UCSCredential Get-UcsOrg -Level root -Ucs $UCSHandle

So I have this sort of code at the beginning of my runbooks when I am doing work against a UCS in my environment. Everything was going well until one day I was greeted with this error:

Connect-Ucs : Connect-Ucs: Connection to ucs1c Failed. At line:1 char:1 + Connect-Ucs -Name ucs1c -Credential $cred + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Connect-Ucs], Exception + FullyQualifiedErrorId : Cisco.Ucs.Cmdlets.ConnectUcs

There is not much detail on exactly what is happening here but when I went to log into UCSM using the same user account it was apparent what was going on here:

2015-01-06_10-25-24

The user is by default capped at 32 sessions and those handles I was building in my scripts were leaving a web session opened on the UCS. The only way to clear this out for this user since its my one admin user (lab scenario) was to go into the UCS via the CLI to clear this out.

Here is how you can see the open sessions in the UCS via the CLI:

UCS1C-A# scope security UCS1C-A /security # show user-sessions local  

Sure enough these servers which left all of the open sessions are my SMA runbook worker nodes:
2015-01-06_10-26-29

Here is how we can go about clearing out these sessions that were left open on the UCS:

UCS1C-A /security # clear-user-sessions web  

You will be prompted to confirm this action.

Now to keep this from happening again we need to be sure we add Disconnect-UCS to the end of our script to close out the handle to the UCS. Here is how you can do this:

#Import PowerTool module
Import-Module ciscoUcsPs  
#Prompt for UCS Credential
$UCSCredential = Get-Credential
#Build Cisco UCS Handle
$UCSHandle = Connect-Ucs -Name ucs1c -NotDefault -Credential $UCSCredential
#Get some data from UCS
$RootOrg = Get-UcsOrg -Level root -Ucs $UCSHandle
#Disconnect UCS Handle
Disconnect-Ucs  

This will close out that web session to the UCS at the end of the script and keep these sessions from piling up on you.

© 2017. All Rights Reserved.