Resolving UCS Director’s Issues with Associating UCS Central Global Service Profiles to UCS C-Series

Forgive the long winded title, but I really struggled on how to put all of that information up there.

First and foremost, let’s describe the program I ran into while trying to associate a Global Service Profile (I’ll refer to this as GSP for the rest of the blog post) created in UCS Central, to a UCS C-Series device (In this case, a C220 M4) using the pre-built UCS Director task called Associate Global Service Profile.  When trying to apply a GSP to a UCS C-Series server, you will receive the following message:

UCSD Java Error

Java/Cloupia Error: java.lang.ClassCastException: com.cloupia.lib.cIaaS.ucs.model.generated.ComputeRackUnit cannot be cast to com.cloupia.lib.cIaaS.ucs.model.generated.ComputeBlade

Even if you do not know much about Java (and I’m certainly no expert on Java), you can get the idea of what the problem is, based on this error message.  This task seems to be hard coded to only apply GSPs to blade servers (or Cisco’s UCS B-Series).  A UCS C-Series is still listed as a “rack server”, when you look at the details in UCS Central.  The big oddity about this task is that even though you get this error message (and yes, it will stop your workflow), technically the GSP does get applied onto the c-Series device.

I logged a Cisco TAC case related to the issue and the main issue I was told was that the underlying code of the UCS Director task was based on a previous version of UCS Central that had not yet included c-Series/rack servers into it’s support matrix.  Like many TAC cases that end up this way, I was asked about putting forth an enhancement request to get this fixed.  Of course, I responded that I would like for it to happen, however, I’ve yet to see a fix to this yet (as of this blog post, UCS Director is up to with the 5.4 platform release coming out of beta testing soon).

That left me with a problem.  I had all these UCS c-Series servers and no way of using pre-built tasks to solve the problem.  My solution to turn to?  The UCS Central PowerTool.  This is Cisco’s PowerShell library for administering UCS Central.  It’s very similar to the UCS PowerTool that many UCS administrators have used in the past to automate UCS Manager related tasks.

The UCS Central PowerTool Saves the Day

First things first, you need to ensure the UCS Central PowerTool has been installed onto one of your UCS Director PowerShell Agent devices.  We will not go through the specifics of how you need to set one of those servers up, nor will we walk through the installation process of the UCS Central PowerTool.  Refer to the respective online resources on Cisco’s website for that information.

Let’s go through my script I created for associating a global service profile to a UCS c-Series:

Import-Module CiscoUcsCentralPs

# Examples of how the UCS Director variables actually look, as strings

#$ucsd_service_profile = "1;org-root/org-0000000-LE;org-root/org-0000000-LE/ls-JonWinTest1"
#$ucsd_ucsc_server = "1;compute/sys-1015/chassis-1/blade-6"

$ucsc_sp = ($args[0].Split(";"))[2] # UCS Director object for the Service Profile
$ucsc_server = ($args[1].Split(";"))[1] # UCS Director object for the UCS device

$ucsc_username = "INSERT USERNAME"
$ucsc_password = ConvertTo-SecureString -String "" -AsPlainText -Force
$ucsc_credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ucsc_username, $ucsc_password
$ucsc_conn = Connect-UcsCentral -Name -Credential $ucsc_credential

if ($ucsc_server -match "rack-unit-") # UCS device is a C-Series
$command_1 = Connect-UcsCentralServiceProfile -ServiceProfile (Get-UcsCentralServiceProfile -Dn $ucsc_sp) -RackUnit (Get-UcsCentralRackUnit -Dn $ucsc_server) -Force
else # UCS device is a B-Series
$command_1 = Connect-UcsCentralServiceProfile -ServiceProfile (Get-UcsCentralServiceProfile -Dn $ucsc_sp) -Blade (Get-UcsCentralBlade -Dn $ucsc_server) -Force

# Wait for the service profile to be completely associated with the hardware AND in either a Powered On or Powered Off state
do {Start-Sleep 10;$sp = Get-UcsCentralServiceProfile -Dn $ucsc_sp} while ($sp.AssocState -ne "associated" -and (($sp.OperState -ne "ok") -or ($sp.OperState -ne "power-off")))

# Determines which UCS domain in UCS Central the physical device is located
$ucs_instance = (Get-UcsCentralComputeInstance -PhysDn (Get-UcsCentralServiceProfile -Dn $ucsc_sp).PnDn).SystemName

# Disconnect from UCS Central
Disconnect-UcsCentral -UcsCentral $ucsc_conn

# Craft a return string for use in UCS Director as a variable for future tasks in the workflow - In this case, the UCS (not UCS Central) Service Profile, so it can be assigned to a UCS Director group, so it appears in their Physical Resources inventory

$str_return = $ucs_instance + ";" + $ucsc_org + ";" + $ucsc_sp

# Return the string to the task
return $str_return

The main cmdlets that were of great use in this were Get-UcsCentralServiceProfileConnect-UcsCentralServiceProfile, Get-UcsCentralRackUnit/Get-UcsCentralBlade and Get-UcsCentralComputeInstance (although, that last cmdlet isn’t actually key to associating the service profile).

The Get-UcsCentralServiceProfile cmdlet performs exactly how the cmdlet name describes.  With this cmdlet, we can get the information on a UCS Central service profile.  The return of this cmdlet is what we will use with the next cmdlet, Connect-UcsCentralServiceProfile, since one of the parameters of that cmdlet is a service profile object.

Notice in the If…Else block for determining whether UCS device is a blade server (B-Series) or a rack server (C-Series).  The key parameter for the Connect-UcsCentralServiceProfile cmdlet that changes is the parameter for either -Blade or -RackUnit.  We can then use either Get-UcsCentralRackUnit (to return the C-Series device) or Get-UcsCentralBlade (to return a B-Series device) and use the returned object as the value of the parameter.

Since the cmdlet parameters are different from blade to rack server, you can see why I figured the original Java error message had to do with the fact that UCS Director task had to be hard coded to just a blade server.

Once I implemented this PowerShell script to associate UCS Central service profiles in my environment, I no longer have to worry about whether I’m going to be using a UCS B-Series device or a UCS C-Series device.

I’d also like to recommend that for rolling back in a workflow, that you take a look at the following custom UCS Director task that is available on the Cisco communities site: UCSD PowerShell Tasks with Rollback.  This custom task has helped me immensely in using PowerShell with UCS Director.  Unfortunately, you do have to write your own rollback scripts (and I’ll publish my rollback script for this task in the very near future).  However, I do highly recommend using this custom task for many of your PowerShell script launching needs in Cisco UCS Director.

Hopefully this post was helpful in realizing that there are more than one way to accomplish functions/tasks in Cisco UCS Director and that PowerShell is one great way to perform them!

Edit:  I’m adding my Disassociate script as well.  For the record, the rollback feature (disassociate service profile) on the UCS Director task also presents the same error message as above.  If you plan to use the script I wrote above, consider the custom task I wrote about and borrow this rollback script.  Enjoy!

Import-Module CiscoUcsCentralPs

$ucsc_sp = ($args[0].Split(";"))[2]
$ucsc_server = ($args[1].Split(";"))[1]

$ucsc_username = "UCS Central Account"
$ucsc_password = ConvertTo-SecureString -String "UCS Central Account Password" -AsPlainText -Force
$ucsc_credential = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $ucsc_username, $ucsc_password
$ucsc_conn = Connect-UcsCentral -Name "UCS Central IP/Name" -Credential $ucsc_credential

# Start the Global Service Profile Disassociation Process
$command_1 = Disconnect-UcsCentralServiceProfile -ServiceProfile (Get-UcsCentralServiceProfile -Dn $ucsc_sp) -Force -Confirm:$false

# Keep an eye on the UCS device to ensure we have full disassociation and server is set to "Unassociated"

if ($ucsc_server -match "rack-unit")  # for a UCS C-Series
    do {Start-Sleep 10;$sp = Get-UcsCentralRackUnit -Dn $ucsc_server} while ($sp.OperState -ne "unassociated")
else   # for a UCS B-Series
    do {Start-Sleep 10;$sp = Get-UcsCentralBlade -Dn $ucsc_server} while ($sp.OperState -ne "unassociated")

Disconnect-UcsCentral -UcsCentral $ucsc_conn

About snoopj

vExpert 2014/2015/2016/2017, Cisco Champion 2015/2016/2017, NetApp United 2017. Virtualization and data center enthusiast. Working too long and too hard in the technology field since college graduation in 2000.
This entry was posted in Technical and tagged , , , . Bookmark the permalink.

2 Responses to Resolving UCS Director’s Issues with Associating UCS Central Global Service Profiles to UCS C-Series

  1. Conor C says:

    Thanks a million Snoop, this got me out of a bind this evening and I much appreciate it! You should post it to the community site on, I’m sure others could use it too.
    Again, thanks for sharing this.


Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s