Interface

Program and manage interfaces. You can configure interfaces using different configuration management tools. Following example shows the details of an interface.

Getting the Physical Ethernet Port
GET https://SWITCH_IP/api/mo/sys/intf/phys-[eth1/1].json?query-target=self HTTP/1.1
Host: switch_ip
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: f92aa2b5-ac52-a3ff-60fa-348a69faf3e0
Getting Interface Statistics
GET https://SWITCH_IP/api/mo/sys/intf/phys-[eth1/5].json?rsp-subtree=full&rsp-subtree-include=stats HTTP/1.1
Host: switch_ip
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 61080f1e-cd96-5e9c-8797-a6e9936bc7e5
# Sample file to Show Interface details
# Import Interface class
from .interface import  Interface
from .nxcli import NXCLI
import traceback

interfaceName = "Ethernet1/6"

def available_interface(interfaceName):
        """
        Display interface details.
        """
        interface = NXCLI('show interface %s' % interfaceName)


if __name__=="__main__":
        try:
                available_interface(interfaceName)
        except Exception,e:
                traceback.print_exc()
Puppet script not available

Using NX-API REST in the Sandbox

Follow following steps to execute the nxapi code snippet files on nx9000 switch.

On the nx9000 switch perform following operation.

  1. SSH to switch using provided credentials. (If credentials are not provided Default username is 'admin' and password 'cisco123'
  2. Run 'config t' on the switch prompt.
  3. Enable nxapi by running 'feature nxapi'.
  4. Exit to switch prompt by running 'exit'.
  5. Run 'Copy r s' to save the configuration.

Setup postman Code snippet: In order to execute the the NXAPI from postman the login needs to be performed first. The cookie would get generated and stored for subsequent execution.

Logging in to Postman
  POST-URL : https://SWITCH-IP/api/aaaLogin.json     
  Content-Type: application/json     
  Cache-Control: no-cache     
  POST BODY :     
       {    
         "aaaUser" : {    
           "attributes" : {    
             "name" : "SWITCH_USER",    
             "pwd" : "SWITCH_PASSWORD"     
           }     
         }     
       }      

Executing NXAPI using postman for first time:

  1. Copy POST URL, mentioned in 'setup postman' section above, after replacing SWITCH-IP with IP address of Nexus switch .
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Replace SWITCH_USERNAME with switch user.
  6. Replace SWITCH_PASSWORD with switch password.
  7. Click send button

Note: If the cookie gets expired you might have to perform the above steps again.

For subsequent NXAPI call:

  1. Copy POST URL, after replacing SWITCH-IP with IP address of Nexus switch.
  2. Select method as POST
  3. Open raw JSON section.
  4. Copy POST-BODY JSON to raw JSON body section of postman.
  5. Click send button

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 Interface configuration using python, create test_interface.py using vi editor like this: vi test_interface.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_interface
  8. The format of the command to be executed is, '/isan/bin/python -m'

Hardware Buffer

Program and manage the hardware buffer. Following example shows the internal buffer packet statistics details.

Getting Switch Hardware Buffer Details
# Sample file to display the switch hardware buffer info

from .nxcli import NXCLI
import traceback

def show_hardware_buffer():
        """
        Show the switch hardware buffer info
        """
        try:
                interface = NXCLI('show hardware internal buffer info pkt-stats detail')
                return True
        except:
                return False

if __name__=="__main__":

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

Using Python in the Sandbox

Follow the 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 Hardware Buffer stats configuration using python, create test_hardware_buff_stats.py using vi editor like this: vi test_hardware_buff_stats.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_hardware_buff_stats
  8. The format of the command to be executed is, '/isan/bin/python -m'