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.
- SSH to switch using provided credentials. (If credentials are not provided Default username is 'admin' and password 'cisco123'
- Run 'config t' on the switch prompt.
- Enable nxapi by running 'feature nxapi'.
- Exit to switch prompt by running 'exit'.
- 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:
- Copy POST URL, mentioned in 'setup postman' section above, after replacing SWITCH-IP with IP address of Nexus switch .
- Select method as POST
- Open raw JSON section.
- Copy POST-BODY JSON to raw JSON body section of postman.
- Replace SWITCH_USERNAME with switch user.
- Replace SWITCH_PASSWORD with switch password.
- Click send button
Note: If the cookie gets expired you might have to perform the above steps again.
For subsequent NXAPI call:
- Copy POST URL, after replacing SWITCH-IP with IP address of Nexus switch.
- Select method as POST
- Open raw JSON section.
- Copy POST-BODY JSON to raw JSON body section of postman.
- Click send button
Using Python in the Sandbox
Follow following steps to execute the python scripts on Nexus switch.
- Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
- If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
- Run 'run bash' to go to bash shell.
- Run sudo su
- 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
- Now copy the script to this file. Save and exit.
- Execute following command to run the script '/isan/bin/python –m cisco.test_interface
- 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.
- Login to switch using provided credentials. Example username is 'admin' and password 'cisco123'.
- If bash is not enabled, Goto 'config t' and enable it by running 'feature bash-shell'
- Run 'run bash' to go to bash shell.
- Run sudo su
- 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
- Now copy the script to this file. Save and exit.
- Execute following command to run the script '/isan/bin/python 'm cisco.test_hardware_buff_stats
- The format of the command to be executed is, '/isan/bin/python -m'