Cisco UCS Manager IP address, username, and password
are passed in as parameters to the instance of the
UcsHandle class that is called HANDLE. Several
methods are available with the UcsHandle class. In this
script only three are used:
HANDLE.login(): This method is used to log in to Cisco UCS
Manager.
HANDLE.query_classid(): This method is used to query the MIT
for objects with a specific class ID.
HANDLE.logout(): This method is used to log out from the Cisco
UCS Manager.
The BLADES variable contains a dictionary of all the
compute blades that are being managed by the
10.10.20.110 instance of Cisco UCS Manager. Within a
for loop, specific information regarding the DN, serial
number, administrative state, model number, and total
amount of memory for each blade is extracted and
displayed to the console. The Python script using the
Cisco UCS Manager SDK that accomplishes all of these
tasks looks as shown in Example 9-11.
Example 9-11 ucsmsdk Python Example
Click here to view code image
#! /usr/bin/env python
from ucsmsdk.ucshandle import UcsHandle
HANDLE = UcsHandle("10.10.20.110", "ucspe",
"ucspe")
# Login into Cisco UCS Manager
HANDLE.login()
# Retrieve all the compute blades
BLADES = HANDLE.query_classid("ComputeBlade")
print('{0:23s}{1:8s}{2:12s}{3:14s}
{4:6s}'.format(
"DN",
"SERIAL",
"ADMIN STATE",
"MODEL",
"TOTAL MEMORY"))
print('-'* 70 )