Avatar

Cisco UCS supports many compute nodes, in a data center there most likely will be more than one UCS system, managing hundreds of compute nodes. These UCS domains will probably have very similar requirements for VLANs, VSANs, vNIC and vHBA templates, Service Profiles templates, boot polices and etc.

Are you tired of cutting and pasting, or clicking until your fingers are calloused over? Are you trying to duplicate or synchronize settings across all your UCS domains? Do you lose track of the changes you made and where? Not to worry UCS PowerTool to the rescue. UCS PowerTool is the Cisco UCS PowerShell Cmdlet library. UCS PowerTool 1.0.1.0 has just been released, download it and make sure to get the release notes and the user guide.

UCS Components and configuration are defined by an XML schema and this schema is used to generate the majority of the UCS PowerTool Cmdlets. However there are a several special Cmdlets that take UCS PowerTool from a great set of cmdlets to a must have cmdlet library for all UCS administrators. The cmdlets I’m focusing on today are Sync-UcsManagedObject and Compare-UcsManagedObject.

There are several ways to synchronize or duplicate objects across UCS domains, manually, configuration export and import, CLI cut and paste, UCS PowerTool, etc. Obviously I picked UCS PowerTool for the job and want to share the script, the process and point out a caveat or two.

From the user guide here is an example of Sync-UcsManagedObject and embedded within the example a call to Compare-UcsManagedObject. This is the example;

Sync-UcsManagedObject -Ucs SYSB (Compare-UcsManagedObject (Get-UcsOrg -Ucs SYSB) (Get-UcsOrg -Ucs SYSA)) -Force

The command is going to get the Orgs from SYSB (the target) and the Orgs from SYSA (the source) and compare them,

  • Orgs on SYSA that are not on SYSB will be created on SYSB
  • Orgs on SYSA that are on SYSB will be modified on SYSB to match SYSA
  • Orgs on SYSB that do not exist on SYSA will NOT be created on SYSA

The “sync” is a one-way sync and the sync is a full object create or modify such that the objects on the target UCS match completely with the objects on the source UCS. The compare is not just a compare on the name of the object but an attribute by attribute compare of the source and target object. Whatever objects that are not on the target that are on the source are going to be created on the target. Whatever objects that are on the target that are on the source are going to be modified on the target.
Caveats

  • This command is not going to create Orgs are on the Source that are on the Target.
  • This command is not going to create supporting objects, for example Service Profiles can be organized in Orgs. For a service profile to be created on a target UCS the Org needs to already exist on the target.

I took the example from the user guide wrapped it in a script to login to both the source and target UCS Domains, provided options for the WhatIf and Force switches. I also extended the command a little by making the UCS object to sync a parameter. The object to sync is the noun part of the respective UCS PowerTool Get cmdlet for that UCS object. From the example above the Get-UcsOrg cmdlet is used to get the Org objects from each UCS. In my script the UcsObject parameter value would be Org.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<#

.SYNOPSIS
Ucs-Object-Sync, synchronize objects from Source UCS to Target UCS

.DESCRIPTION
Ucs-Object-Sync, synchronize objects from Source UCS to Target UCS

.NOTES
John McDonough, Cisco Systems, Inc. (jomcdono)

.PARAMETER SourceUcs
The Source UCS hostame or IP address

.PARAMETER TargetUcs
The Target UCS hostame or IP address

.PARAMETER UcsUser
A UCS user name 

.PARAMETER UcsPass
The user's password

.PARAMETER UcsObject
The Ucs Object to sync

.PARAMETER ExecuteChanges
Switch to execute changes, otherwise changes can be exectued one by one, with a variety of execution choices 

.PARAMETER ProposedChanges
Switch to show proposed changes but not execute them

.EXAMPLE
Ucs-Object-Sync.ps1 -SourceUcs 10.10.20.30 -TargetUcs 10.10.20.40 -UcsUser admin -UcsPass admin123 -UcsObject Vlan -ProposedChanges
Ucs-Object-Sync.ps1 -SourceUcs 10.10.20.30 -TargetUcs 10.10.20.40 -UcsUser admin -UcsPass admin123 -UcsObject Vlan -ExecuteChanges
Ucs-Object-Sync.ps1 -SourceUcs 10.10.20.30 -TargetUcs 10.10.20.40 -UcsUser admin -UcsPass admin123 -UcsObject Vlan

#>
param(
  [Parameter(Mandatory=$true,HelpMessage="Enter a Source UCS hostname or IP address")]
    [string] $SourceUcs,

  [Parameter(Mandatory=$true,HelpMessage="Enter a Target UCS hostname or IP address")]
    [string] $TargetUcs,      

  [Parameter(Mandatory=$true,HelpMessage="Enter UCS user")]
    [string] $UcsUser,

  [Parameter(Mandatory=$true,HelpMessage="Enter UCS user's Password")]
    [string] $UcsPass,

  [Parameter(Mandatory=$true,HelpMessage="Enter a UCS Object, the noun part of the UCS PowerTool Cmdlet")]
    [string] $UcsObject,

    [switch] $ExecuteChanges,        

    [switch] $ProposedChanges
);

  Import-Module CiscoUCSPS -ErrorAction SilentlyContinue

  $password    = ConvertTo-SecureString -Force -AsPlainText $UcsPass
  $credentials = New-Object -TypeName System.Management.Automation.PSCredential -ArgumentList $UcsUser,$password;
  $ucsSource   = Connect-Ucs $SourceUcs -Credential $credentials -NotDefault;
  $ucsTarget   = Connect-Ucs $TargetUcs -Credential $credentials -NotDefault;

  $params = @{Confirm = $true};
  if ($ProposedChanges) {
    $params = @{WhatIf = $true};
  } elseif ($ExecuteChanges) {
    $params = @{Force = $true};
  }

  Sync-UcsManagedObject -Ucs $ucsTarget (Compare-UcsManagedObject (&$("Get-Ucs" + $UcsObject) -Ucs $ucsTarget) (&$("Get-Ucs" + $UcsObject) -Ucs $ucsSource)) @params 

  Disconnect-Ucs -Ucs $ucsSource
  Disconnect-Ucs -Ucs $ucsTarget

 

As always I hope that helps your automation needs.