Cisco UCSMSDK Intro
UCSMSDK is a Python SDK from Cisco for the configuration of UCS managers. The modules are supports in both Python 2 and 3, my testing has been with Python 3.6 and everything has been going well.
Why Use UCSMSDK
Cisco has a number of CLI options to interact with UCS Manager, depending on you circumstances some are more appropriate than others. In the work I have been doing UCSMSDK was a better fit.
PowerTool was not a good fit as local development environment is a Mac and Cisco only provides PowerTool as an MSI installer.
The USCM Ansible modules where considered however, key features such as service profiles were not implemented.
Python is readily available across platform and staff within the BU I’m working within have skillsets in this language.
The SDK is installed either through pip or the by cloning the github repo and building.
The modules are well documented in that a lot of data is available. But, it can be difficult to navigate and find which module you want to use.
The github repository contains a large number of samples which will cover many use cases. These are an excellent starting place to understand how to consume the SDK.
Consuming the SDK
The first step to using the SDK is to connect to a USC manager using the object UscHandle.
Interaction with the UCS Manager is achieved through the use of managed objects. Objects have attributes with values to modify. UscHandle is used to stage and commit the change.
From the above connection example handle is the UcsHandle object connected to our UCS Manager.
Retrieve: handle.query_dn(), handle.query_classid(), handle .query_dns(), handle .query_classids()
If I wanted to add an IP block to an existing IP pool, I would use the following
One of the main challenges faced is finding the module to import for your specific tasks. The first place to look is within the samples as there’s a good change that it’ll be in there.
When the samples do not provide the information needed, I perform the action required using the UCS HTML UI and use Postman to capture the API calls.
Below is the body from the action of creating a LAN Convexity policy with vNICs assigned.
Creating the LAN Connection Policy
The element name from the line above shows that you need to use the module “vnicLanConnPolicy” to create the policy.
Searching the docs will lead you to the class “ucsmsdk.mometa.vnic.VnicLanConnPolicy.VnicLanConnPolicy”
To add the vNIC to the policy.
Within the vnicLanConnPolicy element there is a nested element vnicEther. Again, search the docs to find that it’s the class “ucsmsdk.mometa.vnic.VnicEther.VnicEther”
Putting it together gives the code
The UCSMSDK is a feature rich SDK for interacting with a UCS manager. Settings within the UCS manager are classes defined as ‘managed objects’
The GitHub repo has an excellent of samples which will help you get up an running with the SDK quickly.
The documentation is data rich, but can be hard to get your head around at the start. Using a tool such as Postman to see the API calls through UI can prove valuable.