APIC-EM – inventoryCollect

I’m continuing my voyage into the world of Python programming, having been reluctant to stray from my beloved Java which I began learning some 20 years ago!

Using the Cisco devnet uniq python package, I run a query against APIC-EM to retrieve a list of all network devices. This information is used to build a list of instances representing platform model, specific platform and software version:

It produces the following output which I have found useful for auditing:

Platform C2960 has 5 models.
    12.2(50)SE5 used by 6 devices
    12.2(55)SE5 used by 2 devices
    12.2(50)SE5 used by 3 devices
    12.2(44)SE6 used by 2 devices
    12.2(50)SE5 used by 1 devices
Platform C3750X has 4 models.
    12.2(55)SE5 used by 2 devices
    12.2(58)SE2 used by 6 devices
    15.2(4)E4 used by 1 devices
    12.2(55)SE5 used by 4 devices
    12.2(58)SE2 used by 2 devices
    15.2(4)E4 used by 3 devices
    12.2(58)SE2 used by 2 devices
Platform C6509 has 1 models.
    15.1(2)SY6 used by 2 devices
    15.1(2)SY used by 2 devices
It has been written for the Python3 interpreter.
The full source code can be found here:


Whilst reading through the Cisco Devnet site I came across a similar script to mine, which I must admit has a much more succinct way of building a data structure to represent the switch inventory. Take a look: https://github.com/CiscoDevNet/python_code_samples_network/tree/master/apic-em_get_inventory_stats

However my script offers the following benefits (of course it does!):

  • Splits out the individual switches in a stack, instead of recording a platform as a stack. Allowing switch model totals to be easily obtained.
  • Hostname is stored against software version, so you know which switch is running 12.2(40) in your estate.
  • Switches are grouped by family, ie C6500, N7k-7000, etc. Although I do like the sorting used in the devnet script.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: