Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 75 additions & 0 deletions nxapi/samples/conf_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import requests
import json

print ("enter ip address of switch")
ip = input ()

#get the interface to be configured
print ("what interface would you like to configure, e.g interface 'eth 1/1'")
int_id = input ()

#print ("is this interface: 'routed' or an 'access' port?")
#port_type = ()

#if port_type = "routed"
# port = "no switchport"

#get ip address of interface
print ("enter ip of the interface, e.g. 'A.B.C.D/SM'")
int_ip = input()

myheaders = {'content-type': 'application/json-rpc'}
url = ("http://"+ip+"/ins")
username = ("admin")
password = ("Cisco321")

payload = [
{
"jsonrpc": "2.0",
"method": "cli",
"params": {
"cmd": "conf t",
"version": 1
},
"id": 1
},
{
"jsonrpc": "2.0",
"method": "cli",
"params": {
"cmd": "interface "+int_id,
"version": 1
},
"id": 2
},
{
"jsonrpc": "2.0",
"method": "cli",
"params": {
"cmd": "no switchport",
"version": 1
},
"id": 3
},
{
"jsonrpc": "2.0",
"method": "cli",
"params": {
"cmd": "ip address "+int_ip,
"version": 1
},
"id": 4
},
{
"jsonrpc": "2.0",
"method": "cli",
"params": {
"cmd": "no shut",
"version": 1
},
"id": 5
},
]


response = requests.post(url,data=json.dumps(payload), headers=myheaders,auth=(username,password)).json()
21 changes: 9 additions & 12 deletions nxapi/samples/conf_svi.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import requests
import json

print "enter ip address of switch"
ip=raw_input()
print ("enter ip address of switch")
ip = input ()

print "enter vlan for which svi has to be configured"
vlanId=raw_input()
print ("enter vlan for which svi has to be configured")
vlanId = input ()

print "enter ip of the svi"
ip_vlanId = raw_input()
print ("enter ip of the svi")
ip_vlanId = input()

myheaders = {'content-type': 'application/json-rpc'}
url = "http://"+ip+"/ins"
username = "admin"
password = "ciscotme"
url = ("http://"+ip+"/ins")
username = ("admin")
password = ("Cisco321")

payload=[
{"jsonrpc": "2.0","method": "cli","params": {"cmd": "conf t","version": 1},"id": 1},
Expand All @@ -24,6 +24,3 @@
]

response = requests.post(url,data=json.dumps(payload), headers=myheaders,auth=(username,password)).json()



13 changes: 5 additions & 8 deletions nxapi/samples/conf_vlan.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import requests
import json

print "enter ip address"
ip=raw_input()
print ("enter ip address of switch")
ip=input()

print "enter vlan to be configured"
vlanId=raw_input()
print ("enter vlan to be configured")
vlanId=input()

myheaders = {'content-type': 'application/json-rpc'}
url = "http://"+ip+"/ins"
username = "admin"
password = "ciscotme"
password = "Cisco321"


payload=[
Expand All @@ -20,6 +20,3 @@
]

response = requests.post(url,data=json.dumps(payload), headers=myheaders,auth=(username,password)).json()



46 changes: 46 additions & 0 deletions nxapi/samples/show_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#Show interfaces from a switch
import json
import requests

print ("enter ip address of the switch")
ip=input ()

print ('what interface do you want to check? e.g. eth 1/1')
interface = input ()

my_headers = {'content-type': 'application/json-rpc'}
url = "http://"+ip+"/ins"
username = "admin"
password = "Cisco321"

#Json-rpc payload
payload=[
{
"jsonrpc": "2.0",
"method": "cli",
"params": {
"cmd": "sh ip int "+interface,
"version": 1
},
"id": 1
}
]

#Post the payload to the switch in a json-rpc format to get a response and save it
response = requests.post(url, data=json.dumps(payload), headers=my_headers, auth=(username, password)).json()

#Now Process the response
#First check if the interface is disabled/unconfigured
if response['result']['body']['TABLE_intf']['ROW_intf']['ip-disabled'] == 'TRUE':
print ('This interface is disabled')
#If it isn't disabled, then go ahead to search for its details
else:
Int1 = response['result']['body']['TABLE_intf']['ROW_intf']['intf-name']
link_state = response['result']['body']['TABLE_intf']['ROW_intf']['link-state']
intf_ip = response['result']['body']['TABLE_intf']['ROW_intf']['prefix']
mask = response['result']['body']['TABLE_intf']['ROW_intf']['masklen']
#chassis_id = response['result']['body']['chassis_id']
#hostname = response['result']['body']['host_name']

print ("The interface is : {0} it has an ip of {2}/{3} and it is {1}".format(Int1, link_state, intf_ip, mask))
#print ("ip : {0} is a \"{1}\" with hostname: {2} running software version : {3}".format(ip , chassis_id, hostname, kick_start_image))
18 changes: 10 additions & 8 deletions nxapi/samples/show_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@
import json
import requests

print "enter ip address"
ip=raw_input()
print ("enter ip address of the switch")
ip=input ()

my_headers = {'content-type': 'application/json-rpc'}
url = "http://"+ip+"/ins"
username = "admin"
password = "ciscotme"
password = "Cisco321"


payload=[{"jsonrpc": "2.0",
"method": "cli",
"params": {"cmd": "show version",
"version": 1},
"id": 1}
"params": {
"cmd": "show version",
"version": 1
},
"id": 1
}
]

response = requests.post(url, data=json.dumps(payload), headers=my_headers, auth=(username, password)).json()
Expand All @@ -25,5 +28,4 @@
chassis_id = response['result']['body']['chassis_id']
hostname = response['result']['body']['host_name']

print "ip : {0} is a \"{1}\" with hostname: {2} running software version : {3}".format(ip , chassis_id, hostname, kick_start_image)

print ("Switch of this ip : {0} is a \"{1}\" with hostname: {2} running software version : {3}".format(ip , chassis_id, hostname, kick_start_image))