HowTo Automate Multiple CLI commands on Mellanox Switches

Version 8

    This post shows a simple tool called CLI Player that basically play list of CLI commands on a list of Mellanox switches.

     

    References

     

    Installation

    There are several ways to install the CLI player package.

     

    • Install the VMS wizard (The CLI player is included inside)
    • Install the MLAG wizard (The CLI player is included inside)
    • Install only the CLI player only via the VMS wizard installation while using the -o flag to install the CLI player only.

     

    ./vms_install.sh -o cli_player

        

     

    For further installation instructions refer to HowTo Configure MLAG on Mellanox switches using MLAG Wizard and to the VMS manual located here .

     

    Configuration

    Once the CLI player is installed you need to create two files, and then run the cli_player script.

    • switches.csv file
    • cli_commands.txt file

     

    Follow the next example:

    1. Create and edit switches.csv file

    # wget  http://www.mellanox.com/downloads/solutions/vms/switches_template.csv /root/switches.csv

        

    This file list the switches you wish to run the CLI commands.

    Here is an example of the switches.csv file (the hostname can be either IP or hostname):

    Role,Hostname,Username,Password,Community

    tor_0,r-qa-sit-sx03,admin,admin,public

    tor_1,r-qa-sit-sx04,admin,admin,public

     

    2. create a file (e.g. called cli_commmands.txt) and add list of commands you wish to play on the switches

    For example:

    ntp enable

    snmp-server enable

    lldp

        

     

    3. Run the play the list of commands on the list of switches

    It is possible to use "-h" flag to see more options.

    # /opt/vms/src/cli_player/vms_cli_player.py -c /root/switches.csv -f cli_commands.txt -n

    INFO - Command invoked: ['./vms_cli_player.py', '-c', '/root/switches.csv', '-f', 'my_commands.txt', '-n']

    INFO - Running in single configuration mode

    INFO - Starting configuration on: r-qa-sit-sx04

    INFO - Starting configuration on: r-qa-sit-sx03

    INFO - Running command "no cli session paging enable" on r-qa-sit-sx04

    INFO - Running command "enable" on r-qa-sit-sx04

    INFO - Running command "configure terminal" on r-qa-sit-sx04

    INFO - Running command "ntp enable" on r-qa-sit-sx04

    INFO - Running command "snmp-server enable" on r-qa-sit-sx04

    INFO - Running command "lldp" on r-qa-sit-sx04

    INFO - Running command "" on r-qa-sit-sx04

    INFO - Host r-qa-sit-sx04 configuration completed successfully

    INFO - Running command "no cli session paging enable" on r-qa-sit-sx03

    INFO - Running command "enable" on r-qa-sit-sx03

    INFO - Running command "configure terminal" on r-qa-sit-sx03

    INFO - Running command "ntp enable" on r-qa-sit-sx03

    INFO - Running command "snmp-server enable" on r-qa-sit-sx03

    INFO - Running command "lldp" on r-qa-sit-sx03

    INFO - Running command "" on r-qa-sit-sx03

    INFO - Host r-qa-sit-sx03 configuration completed successfully

    INFO - Configuration Finished Successfully!

    INFO - Configuration Summary:

    INFO - switch r-qa-sit-sx04 configuration success.

    INFO - switch r-qa-sit-sx03 configuration success.

        

     

    Note: to run a simple command, simply use the -m flag.

    /opt/vms/src/cli_player/vms_cli_player.py -c /root/switches.csv -m "ntp enable" -n

        

    4. For debug purposes (if needed) you can check the log files located here:

    # cd /opt/vms/log

    # ls

    cli_player.log

    cli_player.r-qa-sit-sx03.log

    cli_player.r-qa-sit-sx04.log

    #