Cisco Intersight – Reporting with Python

You might have heard of Cisco Intersight, Cisco’s software-as-a-service platform for hardware and cloud management. I had a friend reaching out asking for a report to discover all servers (they have 2500 UCS server) that have SD-Card controllers as well as storage controllers.

Since Intersight can combine all UCS Rack/Blade server as well as their UCS Manager/Central connections it is the perfect API to reach out to.

Cisco provides a simple Python SDK as well as some automation modules for RedHat Ansible and Hashicorp Terraform that can be found here: https://www.intersight.com/apidocs/downloads/

If you want to skip the read and get the code, here it is: https://github.com/cjohannsen81/intersight-reporting

First of all you have to create an Intersight account (which is free) and claim devices if you haven’t used Intersight before. To connect to the Intersight API it’s best to use API Keys which can be created and managed in the “Settings” section of your Intersight account. Hit the “Generate API Key” and pick Schema Version 3 (we will use some newer Intersight features).

As soon as you have exported the keys as:

INTERSIGHT_API_PRIVATE_KEY=/folder/key.txt
INTERSIGHT_API_KEY_ID=01234567890

you will be able to clone and run the script.

With the challenge to export all the reported data into a CSV file it felt best to start with the Python SDK and get all flex flash controllers: https://www.intersight.com/apidocs/apirefs/api/v1/storage/FlexFlashControllers/get/ which ends up in a really long JSON output. The script gathers these using:

flash_controllers = api_instance.get_storage_flex_flash_controller_list(top=top,skip=skip)

Please note that top and skip have to be changed in case you have more than 1000 objects (rate limiting in the API). The challenge is to get the server the flash card is attached to as well as the storage controllers to allow remediation to another storage system if possible.

The JSON output showed another object called compute.Unit which delivers the storage.Controller as part of a list with objects.

compute_board = fcontroller["compute_board"]["moid"]

The compute.Unit also references the compute.Rack object to gather more data like the server type: Rack or Blade.

summary = api_instance.get_compute_board_by_moid(compute_unit)

This allows to call the name of the server in the physical.Summary reference.

if summary["compute_rack_unit"]:

  rack_unit = summary["compute_rack_unit"]["moid"]

  mapping = api_instance.get_compute_physical_summary_by_moid(rack_unit)

All the data needs to be written into a CSV file so it gets added to a list named data while the script is running. Some attributes can be empty which leads to some “None” replacements if there’s no additional storage controller for example.

You can run the script calling: python3 get_report.py and some of the data will be shown in the console:

The CSV file can be imported into Microsoft Excel using the comma as the delimiter to have fixed columns.

Feel free to reach out if you have question or just contribute on GitHub!

2 Comments

Mike F 01/31/2022 Reply

Nice write up and thanks for sharing. This is exactly what I was looking for. We have lots of ESXi servers that are installed on SD card. Your script and process will save us lots of time.
Thank you!

cjohannsen 01/31/2022 Reply

That’s great! Glad you like it!

Leave a Reply