Working interactively in the Python shell

Use this procedure to access a Python shell, within which you can use Python commands that call and manipulate Extreme operating system commands.

Before you begin

Note

Note

The Python shell is accessible only to admin-role users.

Python syntax is case-sensitive.

Procedure

  1. In privileged EXEC mode, enter python to access the Python shell.
    device# python
    The device# prompt changes to a Python prompt:
    device# python
    Python 3.5.2 (default, Apr 11 2019, 13:05:18) 
    [GCC 4.8.2] on linux
    Type "help", "copyright", "credits" or "license" for more information.
  2. To exit the Python shell and return to the Extreme operating system prompt, enter either:
    • exit()
    • Ctrl-D
  3. To run a Extreme operating system command from within the Python shell, enter the CLI( ) command.
    >>> cmd_show_running_ve = CLI('show running-config interface ve')
    !Command: show running-config interface ve
    !Time: Mon Aug 22 16:53:13 2019
    
    The statement entered above does two things:
    • Runs the show running-config interface ve command and displays the result.
    • Assigns that command to a Python variable named cmd_show_running_ve
  4. To run a series of Extreme operating system commands from within the Python shell, separate the commands with \n.
    >>> cmd_config_ve = CLI('configure \n interface ve 101-103')
    !Command: configure 
     interface ve 101-103
    !Time: Mon Aug 22 16:53:13 2019
    Note

    Note

    There is a difference between running a sequence of Extreme operating system CLI commands in the Python shell rather than in the standard Extreme operating system interface. Whereas in the standard interface the result of a command is persistent, in the Python shell each CLI( ) statement is independent of any preceding ones.

Example

In the following example, the lines beginning with # are added for explanation.

device# python
Python 3.5.2 (default, Apr 11 2019, 13:05:18) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> cmd_show_running_ve = CLI('show running-config interface ve')
!Command: show running-config interface ve
!Time: Mon Aug 22 16:53:13 2019

% No entries found.
# The SLX-OS show running-config interface ve command is run,
# and that command is assigned to the Python variable cmd_show_running_ve.

>>> cmd_config_ve = CLI('configure \n interface ve 101-103')
# A series of three commands are run and assigned to the Python variable cmd_config_ve.
!Command: configure 
 interface ve 101-103
!Time: Mon Aug 22 16:53:13 2019


>>> cmd_show_running_ve.rerun()
# The rerun() function appended to cmd_show_running_ve gives the following output:
!Command: show running-config interface ve
!Time: Mon Aug 22 16:53:13 2019

interface Ve 101
 shutdown
!
interface Ve 102
 shutdown
!
interface Ve 103
 shutdown
!
!