Ping

Ping is a networking utility program or a tool to test if a particular host is reachable. It is a diagnostic that checks if your computer is connected to a server. Ping, a term taken from the echo location of a submarine, sends data packet to a server and if it receives a data packet back, then you have a connection. Following example shows usage of ping in nexus devices.

Troubleshooting with Ping
# Sample file to troubleshoot using ping

from .nxcli import NXCLI
import traceback

# Fill the details to troubleshoot using ping
host = '172.31.219.60'
count = '4'
vrf = 'management'


def check_ping_ops():
        """
        Checks if the host is reachable
        """
        try:
                interface = NXCLI('ping %s count %s vrf %s' % (host, count, vrf))
                return True
        except:
                return False

if __name__=="__main__":

        try:
                check_ping_ops()
        except Exception,e:
                traceback.print_exc()
Puppet script not available
NX-API REST script not available

Using Python in the Sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage ping configuration using python, create test_ping.py using vi editor like this: vi test_ping.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python 'm cisco.test_ping
  8. The format of the command to be executed is, '/isan/bin/python -m'

TraceRoute

Traceroute is a computer network diagnostic tool for displaying the route (path) and measuring transit delays of packets across an Internet Protocol (IP) network. Following example shows the usage of traceroute in nexus devices.

Troubleshooting with TraceRoute
# Sample file to troubleshoot using traceroute

from .nxcli import NXCLI
import traceback

# Fill the details to troubleshoot using traceroute
host = '172.31.219.60'
vrf = 'management'

def check_traceroute_ops():
        """
        traceroute the host
        """
        try:
                interface = NXCLI('traceroute %s vrf %s' % (host, vrf))
                return True
        except:
                return False

if __name__=="__main__":

        try:
                check_traceroute_ops()
        except Exception,e:
                traceback.print_exc()
Puppet script is not available
NX-API REST script not available

Using Python in the Sandbox

Follow following steps to execute the python scripts on Nexus switch.

  1. Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
  2. If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
  3. Run 'run bash' to go to bash shell.
  4. Run sudo su
  5. Copy the required script to /isan/python/scripts/cisco directory. For example, if you want to manage Traceroute configuration using python, create test_traceroute.py using vi editor like this: vi test_traceroute.py
  6. Now copy the script to this file. Save and exit.
  7. Execute following command to run the script '/isan/bin/python -m cisco.test_traceroute
  8. The format of the command to be executed is, '/isan/bin/python -m'