Зарегистрируйтесь сейчас для лучшей персонализированной цитаты!

Synchronize UCS Objects

Aug, 09, 2013 Hi-network.com

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-UcsSYSB(Compare-UcsManagedObject(Get-UcsOrg-UcsSYSB)(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 theUcsObject parameter value would be Org.

1 2 3 4 5 6 7 8 91011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
<#.SYNOPSISUcs-Object-Sync, synchronize objects from Source UCS to Target UCS.DESCRIPTIONUcs-Object-Sync, synchronize objects from Source UCS to Target UCS.NOTESJohn McDonough, Cisco Systems, Inc. (jomcdono).PARAMETERSourceUcsThe Source UCS hostame or IP address.PARAMETERTargetUcsThe Target UCS hostame or IP address.PARAMETERUcsUserA UCS user name.PARAMETERUcsPassThe user's password.PARAMETER UcsObjectThe Ucs Object to sync.PARAMETERExecuteChangesSwitch to execute changes, otherwise changes can be exectued one by one, with a variety of execution choices.PARAMETERProposedChangesSwitch to show proposed changes but not execute them.EXAMPLEUcs-Object-Sync.ps1 -SourceUcs 10.10.20.30 -TargetUcs 10.10.20.40 -UcsUser admin -UcsPass admin123 -UcsObject Vlan -ProposedChangesUcs-Object-Sync.ps1 -SourceUcs 10.10.20.30 -TargetUcs 10.10.20.40 -UcsUser admin -UcsPass admin123 -UcsObject Vlan -ExecuteChangesUcs-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.

follow @johnamcdonough


tag-icon Горячие метки:

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.