Skip to content

How to make scripts OS agnostic

Matthew Spangler edited this page Sep 17, 2021 · 7 revisions

Say you want to make a script that prints out a brief summary of interfaces.

The command to do this differs between different Cisco operating systems. For example, on IOS XE it is #show ip interface brief and on NXOS it is #show interface brief.

However, you can write a script that will print out the brief summary no matter the OS.

Start by using the start_cisco_session() method. This method detects the OS in the current tab, and creates and instance of the corresponding runner class.

scrt = CrtSession(crt)
scrt.active_session.start_cisco_session()
runner = scrt.active_session.runner

Now scrt.active_session.runner is an instance of a class corresponding to the current Cisco OS, like runner.cisco.XE() or runner.cisco.NXOS().

Each runner.cisco class contains a method for displaying the interface summary. Run the following method, and it will send the correct command:

interface_brief_summary = scrt.active_session.runner.show_intf_brief()
Clone this wiki locally