cisco IOS XE 17.16.x — Python Script

[Think: result = (bool(success), original_command, error_information)] The command parameters can be in multiple lines and in the same format that is displayed in the output of the show running-config command. The following is sample output from the cli.configure(command) function:

>>> cli.configure(["interface GigabitEthernet1/0/7", "no shutdown", "end"]) [ConfigResult(success=True, command='interface GigabitEthernet1/0/7', line=1, output='', notes=None), ConfigResult(success=True, command='no shutdown', line=2, output='', notes=None), ConfigResult(success=True, command='end', line=3, output='', notes=None)] cli.configurep(command) —This function works exactly the same as the cli.configure(command) function, except that it prints the resulting text to stdout rather than returning it. The following is sample output from the cli.configurep(command) function: >>> cli.configurep(["interface GigabitEthernet1/0/7", "no shutdown", "end"]) Line 1 SUCCESS:

interface GigabitEthernet1/0/7 Line 2 SUCCESS: no shut Line 3 SUCCESS: end Python Scripts Overview Python run in a virtualized Linux-based environment, Guest Shell. For more information, see the Guest Shell chapter. Cisco provides a Python module that allows user’s Python scripts to run IOS CLI commands on the host device. Interactive Python Prompt When you execute the guestshell run python command on a device, the interactive Python prompt is opened inside the Guest Shell. The Python interactive mode allows users to execute Python functions from the Cisco Python CLI module to configure the device. The following example shows how to enable the interactive Python prompt:

Device# guestshell run python Python 2.7.5 (default, Jun 17 2014, 18:11:42) [GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> Device# Python Script Python scripts can run in non-interactive mode by providing the Python script name as an argument in the Python command. Python scripts must be accessible from within the Guest Shell. To access Python scripts from the Guest Shell, save the scripts in bootflash/flash that is mounted within the Guest Shell. Shells and Scripting Python Scripts Overview Programmability Configuration Guide, Cisco IOS XE 17.16.x 137