cisco IOS XE 17.16.x — Running Python Scripts as Part of EEM Applet Actions

Running Python Scripts as Part of EEM Applet Actions Python Script: eem_script.py An EEM applet can include a Python script with an action command. In this example, an user is trying to run a standard Python script as part of the EEM action, however; EEM Python package is not available in the standard Python script. The standard Python script in IOS has a package named from cli import cli,clip and this package can be used to execute IOS commands. import sys from cli import cli,clip,execute,executep,configure,configurep intf= sys.argv[1:] intf = ''.join(intf[0]) print ('This script is going to unshut interface %s and then print show ip interface brief'%intf) if intf == 'loopback55':

configurep(["interface loopback55","no shutdown","end"]) else : cmd='int %s,no shut ,end' % intf configurep(cmd.split(',')) executep('show ip interface brief') This following is sample output from the guestshell run python3 command. Device# guestshell run python3 /flash/eem_script.py loop55 This script is going to unshut interface loop55 and then print show ip interface brief Line 1 SUCCESS: int loop55 Line 2 SUCCESS: no shut Line 3 SUCCESS: end Interface IP-Address OK?

Method Status Protocol Vlan1 unassigned YES NVRAM administratively down down GigabitEthernet0/0 5.30.15.37 YES NVRAM up up GigabitEthernet1/0/1 unassigned YES unset down down GigabitEthernet1/0/2 unassigned YES unset down down GigabitEthernet1/0/3 unassigned YES unset down down GigabitEthernet1/0/4 unassigned YES unset up up GigabitEthernet1/0/5 unassigned YES unset down down GigabitEthernet1/0/6 unassigned YES unset down down GigabitEthernet1/0/7 unassigned YES unset down down GigabitEthernet1/0/8 unassigned YES unset down down GigabitEthernet1/0/9 unassigned YES unset down down GigabitEthernet1/0/10 unassigned YES unset down down GigabitEthernet1/0/11 unassigned YES unset down down GigabitEthernet1/0/12 unassigned YES unset down down GigabitEthernet1/0/13 unassigned YES unset down down GigabitEthernet1/0/14 unassigned YES unset down down GigabitEthernet1/0/15 unassigned YES unset down down GigabitEthernet1/0/16 unassigned YES unset down down GigabitEthernet1/0/17 unassigned YES unset down down GigabitEthernet1/0/18 unassigned YES unset down down GigabitEthernet1/0/19 unassigned YES unset down down GigabitEthernet1/0/20 unassigned YES unset down down GigabitEthernet1/0/21 unassigned YES unset down down GigabitEthernet1/0/22 unassigned YES unset down down Shells and Scripting Running Python Scripts as Part of EEM Applet Actions Programmability Configuration Guide, Cisco IOS XE 17.16.x 148