January 24, 2017 · ucspython ucsmsdk

Inventory Ucs Managed servers via ucsmsdk

ucsmsdk 0.9.3.0 will add support for inventory APIs.
This allows for multi-host multi-component inventory in multiple formats(enough of multiple? :-D ).

The inventory APIs support inventorying,

- fabric interconnects
- cpus
- disks
- dimms
- storage controller
- VIC
- vNICs
- vHBAs
- PSUs

The supported output formats for the report are,

- csv
- html
- json

we recommend using the html format, as it has inbuilt javascript based filtering. It can quickly help narrow down a certain component on a certain host.

from ucsmsdk.utils.inventory import get_inventory

# Gets inventory of all components in JSON format
get_inventory(handle=handle)

# Gets inventory for all servers all components in JSON format
get_inventory(handle=[handle1, handle2, handle3])

# Gets inventory of one server all components in JSON format
get_inventory(handle=handle, component="all")

# Gets disks inventory of one server in JSON format
get_inventory(handle=handle, component="disks")

# Gets cpu and disks inventory for one server in JSON format
get_inventory(handle=handle, component=["cpu", "disks"])

# Gets cpu and disks inventory for one server in JSON format and writes to inventory.json file
get_inventory(handle=handle, component=["cpu", "disks"], file_format="json", file_name="inventory.json")

# Gets cpu and disks inventory for one server in CSV format and writes to inventory.csv fie
get_inventory(handle=handle, component=["cpu", "disks"], file_format="csv", file_name="inventory.csv")

# Gets cpu and disks inventory for one server in HTML format and writes to inventory.html
get_inventory(handle=handle, component=["cpu", "disks"], file_format="html", file_name="inventory.html")  

This can be tried out today via the code available at https://github.com/ciscoucs/ucsmsdk

complete code to run it,

#! /usr/bin/env python

from ucsmsdk.ucshandle import UcsHandle
from ucsmsdk.utils.inventory import get_inventory

handle = UcsHandle("192.168.1.1", "username", "password")
handle.login()

# This would create inventory.html in the same directory where the script is run from
get_inventory(handle=handle, component="all", file_format="html", file_name="inventory.html")

handle.logout()
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket