cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
2835
Views
4
Helpful
4
Replies

Getting started with Cisco RADKit Scripting

RichardAtkin
Level 3
Level 3

You've heard about Cisco RADKit and want to get started with scripting things yourself. Maybe you're struggling to get started? Here's a little example code that introduces some key concepts to get you going.

In this example we will;

  • Authenticate to the Cisco RADKit
  • Connect to a specific Cisco RADKit Service
  • Create a filtered view of an inventory
  • Execute the same command on all items in the inventory
  • Convert the human-reading results from that command to structured data
  • Print an output on the screen

To help keep things simple and relatable, we'll use the scenario of wanting to get the hostname, partcode and serial number from some devices that run IOS.

I am going to assume you've already downloaded and installed Cisco RADKit, by visiting https://radkit.cisco.com and that you have Python installed, so I'm going to jump straight in to it.

Step one - run 'radkit-client'.  As we are going to use the Genie Parsers in this example, you need to run RADKit from a Linux-type environment.  I use WSL2 (Ubuntu) inside Windows 11.

Once you're inside the radkit-client REPL, work your way though the script below.

# Authenticate your RADKit Client against the RADKit infrastructure.  Be sure to insert the email assocaited with your cisco.com account.
client = sso_login("user@email.com")

# Connect to the environment where you already have RADKit service setup and running.  Be sure to insert the real service id here.  A service ID is typically in the format xxxx-xxxx-xxxx
service = client.service("Service-ID-Here")


# import the genie parser, we'll use this later to help us convert human-readable results from a "Show" command in to structure data.
import radkit_genie

# Create an object, 'inv', and populate it with devices from the inventory (service.inventory) where device_type == "IOS".  By default, service.inventory returns all items in the inventory, but using the filter allows us to focus in on just a subset of the devices.
inv = service.inventory.filter("device_type","IOS")

# For all items within our filtered inventory, inv, run the command "show ver".  wait() makes this a blocking function, so the program will halt here until the command has been run on all devices in the inventory.  When "show ver" has been run against all devices in our filtered inventory, assign the results to 'shv'.
shv = inv.exec("show ver").wait()

# Take all of the human-readable content that is locked away inside "shv", and run it through the genie parser.  Store the structured-data output from this as 'parsed'.
parsed = radkit_genie.parse(shv, os="ios")

# For every device we parsed an output for, pick out the key items from the structured data and print them on screen... one device per line.
for i in parsed:
    print(f"{i}, {parsed[i]['show ver'].data['version']['version']}, {parsed[i]['show ver'].data['version']['chassis']}")

The output from the script should look something like this:

someSwitchName, 16.12.4, C9300-24P
yourSwitchName, 16.9.3, C9300-24P
a
SwitchStack, 16.9.3, C9300-24P

And that's it...  I hope this brief intro to scripting with RADKit Client helps inspire you to get started with scripting, and to go on and tackle bigger issues more easily and essificently in your environments.

4 Replies 4

marcmedi
Cisco Employee
Cisco Employee

Hi Richard,

Could you tell me how I can install the radkit_genie? 



>>> import radkit_genie

Traceback (most recent call last):

  File "<stdin>", line 1, in <module>

ModuleNotFoundError: No module named 'radkit_genie'

marcmedi
Cisco Employee
Cisco Employee

pip3 install cisco_radkit_genie

This didn't work for me. Can't find cisco_radkit_genie

@dracmus20 , please share with me the pip command that you are using.