def update_cdp(hostip, userid, passwd):
	retval = True
	target_cmd = "python bootflash:update_cdp.py"
	target_cmd = util.remove_last_semicolon(target_cmd)
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	if not 'Success' in outputs['msg']:
		retval = False
	print 'update_cdp on %s is %s' %(hostip, retval)
	return retval
Beispiel #2
0
def delete_vrf( hostip, userid, passwd, vrf_name, vnid):
	retval = True
	target_cmd = "conf t ; no vrf context %s ; interface nve1 ; no member vni %d associate-vrf " %(vrf_name, vnid)
	target_cmd = util.remove_last_semicolon(target_cmd)
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'do delete vrf/tenant on %s is %s' %(hostip, retval)
	return retval
Beispiel #3
0
def delete_vlan(hostip, userid, passwd, vlan, vlan_svi, vrf, vxlan, mcast):
	retval = True
	target_cmd  = "conf t ; no interface vlan %d ; no vlan %d ; interface nve1 ; no member vni %d ; evpn ; no vni %d l2" %(vlan, vlan, vxlan, vxlan)
	target_cmd = util.remove_last_semicolon(target_cmd)
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'delete vlan on %s is %s' %(hostip, retval)
	return retval
Beispiel #4
0
def create_vrf(hostip, userid, passwd, vrf_name, vnid, vlan):
	retval = True
	target_cmd = "conf t ; vrf context %s ; vni %d ; rd auto ; address-family ipv4 unicast ; route-target export %d:%d ; route-target import %d:%d ; route-target both auto evpn ; " %(vrf_name, vnid, vlan, vlan)
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'do conf vrf/tenant on %s is %s' %(hostip, retval)
	return retval
def list_interface_by_host( hostip, userid, passwd):
	print hostip
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_payload( "show interface brief")), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']
	if not 'Success' in outputs['output']['msg']:
		return
	try:
		for row in outputs['output']['body']['TABLE_interface']['ROW_interface']:
			if row['state'] == 'up':
				print " - ", row['interface'], row['vlan'] if row.has_key('vlan') else '--', row['portmode'] if row.has_key('portmode') else ''

	except Exception as e:
		print e
Beispiel #6
0
def add_nve_vni(hostip, userid, passwd, vnid, mcast_grp):
	retval = True
	target_cmd = "conf t ; interface nve 1 ; member vni %d ; suppress-arp ; mcast-group %s ; member vni %d associate-vrf" %(vnid, mcast_grp, vnid)
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'add nve_vni on %s is %s' %(hostip, retval)
	return retval
def list_interface_by_host(hostip, userid, passwd):
    print hostip
    resp = requests.post(
        util.get_nxapi_endpoint(hostip),
        data=json.dumps(util.get_payload("show ip interface vrf all")),
        headers=util.myheaders,
        auth=(userid, passwd),
    ).json()
    outputs = resp["ins_api"]["outputs"]
    if not "Success" in outputs["output"]["msg"]:
        return
    pt = PrettyTable(["intf-name", "vrf-name", "link-state", "admin-stat", "prefix", "secondary"])
    pt.align["intf-name"] = "l"  # Left align city names
    pt.padding_width = 1  # One space between column edges and contents (default)
    try:
        if type(outputs["output"]["body"]["TABLE_intf"]) == dict:
            for row in outputs["output"]["body"]["TABLE_intf"]["ROW_intf"]:
                # print 'dict %r' %row
                if row["link-state"].upper() == "TRUE":
                    pt.add_row(
                        [
                            row["intf-name"],
                            row["vrf-name-out"],
                            "up",
                            "up" if row["admin-state"].upper() == "TRUE" else "down",
                            row["prefix"],
                            row["TABLE_secondary_address"]["ROW_secondary_address"]["prefix1"]
                            if row.has_key("TABLE_secondary_address")
                            else "-",
                        ]
                    )
        else:
            for idx, row in enumerate(outputs["output"]["body"]["TABLE_intf"]):
                # print 'list %r' %row
                # print row['ROW_intf']['link-state']
                if row["ROW_intf"]["link-state"] == "up":
                    pt.add_row(
                        [
                            row["ROW_intf"]["intf-name"],
                            outputs["output"]["body"]["TABLE_vrf"][idx]["ROW_vrf"]["vrf-name-out"],
                            "up",
                            row["ROW_intf"]["admin-state"],
                            row["ROW_intf"]["prefix"],
                            row["ROW_intf"]["TABLE_secondary_address"]["ROW_secondary_address"]["prefix1"]
                            if row["ROW_intf"].has_key("TABLE_secondary_address")
                            else "-",
                        ]
                    )
    except Exception as e:
        print e
    print pt
Beispiel #8
0
def conf_ospf( hostip, userid, passwd, ospf_as, intfs):
	retval = True
	target_cmd = 'conf t ; router ospf %d'
	for intf in intfs:
		target_cmd += 'interface %s ; ip router ospf %s area 0.0.0.0 ; ' %(intf, ospf_as)
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	for output in outputs:
		if not 'Success' == output['msg']:
			retval = False
	print 'do ospf conf on %s is %s' %(hostip, retval)
	return retval
Beispiel #9
0
def conf_nve1( hostip, userid, passwd ):
	retval = True
	target_cmd = "conf t ; interface nve1 ; no shutdown ; source-interface loopback0 ; host-reachability protocol bgp"

	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'do conf nve1 on %s is %s' %(hostip, retval)
	return retval
Beispiel #10
0
def conf_basic( hostip, userid, passwd, role):
	retval = True
	target_cmd = "conf t ; vlan 1 ; ip domain-lookup ; line console ; line vty ; "
	if role == 'leaf':
		target_cmd += 'hardware access-list tcam region vacl 0 ; hardware access-list tcam region arp-ether 256 ; hardware qos ns-buffer-profile burst '		
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'do conf nve1 on %s is %s' %(hostip, retval)
	return retval
Beispiel #11
0
def conf_features( hostip, userid, passwd, features):
	retval = True
	target_cmd = ""
	cmd = " feature %s ;"
	for f in features:
		target_cmd +=  cmd % f
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'do conf feature on %s is %s' %(hostip, retval)
	return retval
Beispiel #12
0
def conf_bgp( hostip, userid, passwd, bgp_as, lo0, peers, role = 'spine'):
	retval = True
	target_cmd = 'conf t ; router bgp %s ; router-id %s ;' %(bgp_as, lo0)
	for peer in peers:
		target_cmd += ' neighbor %s remote-as %s ; update-source loopback0 ; address-family l2vpn evpn ; send-community both ; ' % (peer, bgp_as)
		if role == 'spine':
			target_cmd += ' route-reflector-client ; '
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for output in outputs:
		if not 'Success' == output['msg']:
			retval = False
	print 'do bgp conf on %s is %s' %(hostip, retval)	
	return retval
def list_vrf_interface_by_host( hostip, userid, passwd):
	print hostip
	vrf_map = {}
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_payload( "show vrf interface")), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']
	if not 'Success' in outputs['output']['msg']:
		return
	for row in outputs['output']['body']['TABLE_if']['ROW_if']:
		if vrf_map.has_key( row['vrf_name']):
			vrf_map[row['vrf_name']].add( row['if_name'])
		else:
			vrf_map[row['vrf_name']] = set()
			vrf_map[row['vrf_name']].add( row['if_name'])
	pt = PrettyTable(["vrf-name", "interface"])
	pt.align["vrf-name"] = "l" # Left align city names
	pt.padding_width = 1 # One space between column edges and contents (default)	
	for n in vrf_map.keys():
		pt.add_row( [ n, ",".join( vrf_map.get(n))])	
	print pt
Beispiel #14
0
def conf_interface( hostip, userid, passwd, switch_model, ospf_as):
	retval = True
	target_cmd = 'conf t ; interface lo0 ; ip address %s ; ip router ospf %s area 0.0.0.0 ; ip pim sparse-mode ; ' %( switch_model['lo0'], ospf_as)
	if switch_model.has_key('lo1') and switch_model['role'] == 'spine' :
		target_cmd += 'interface lo1 ; ip address %s ; ip router ospf %s area 0.0.0.0 ; ip pim sparse-mode ; ' %( switch_model['lo1'], ospf_as)
	if switch_model.has_key('lo0.sec') and switch_model['role'] == 'leaf':
		target_cmd += ' interface lo0 ; ip address %s secondary ;' %(switch_model['lo0.sec'])
	for intf in switch_model['fabric'].keys():
		target_cmd += 'interface %s ; no switchport ; mtu 9216 ; load-interval counter 1 5 ; no ip redirects ; ip address %s ; ip router ospf %s area 0.0.0.0 ; ip pim sparse-mode ; no shut ; ' %(intf, switch_model['fabric'][intf], ospf_as)
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'conf interface on %s is %s' %(hostip, retval)
	return retval	
Beispiel #15
0
def create_vlan( hostip, userid, passwd, vlan, vlan_svi, vrf, vxlan, mcast):
	retval = True
	#create vlan and map vxlan 
	target_cmd = "conf t ; vlan %d ; vn-segment %d ;" %(vlan, vxlan)
	#config vlan svi 
	target_cmd += " interface vlan %d ; no shut ;  vrf member %s ; ip address %s/24 ; ipv6 address %s/64 ; fabric forwarding mode anycast-gateway ; " %(vlan, vrf, vlan_svi, util.to_simple_ipv6(vlan_svi))
	#add nve1 
	target_cmd += " interface nve1 ; member vni %d ; suppress-arp ; mcast-group %s ;" %(vxlan, mcast)
	#add evpn
	target_cmd += " evpn ; vni %d l2 ; route-target import auto ; route-target export auto" %(vxlan)
	target_cmd = util.remove_last_semicolon(target_cmd)
	#print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'create vlan on %s is %s' %(hostip, retval)
	return retval
Beispiel #16
0
def conf_vxlan_mcast( hostip, userid, passwd, anycast, mgrp_list, list_lo1, role='spine'):
	retval = True
	target_cmd = "conf t ; ip pim rp-address %s  group-list %s/8 ; ip pim ssm range 232.0.0.0/8 ; " %(anycast, mgrp_list)
	if role == 'leaf':
		target_cmd += "fabric forwarding anycast-gateway-mac 0000.2222.3333 ; "
	if role == 'spine':
		target_cmd += "ip pim rp-candidate loopback1 group-list %s/8 ; " %(mgrp_list)
		for lo1 in list_lo1:
			target_cmd += "ip pim anycast-rp %s %s ; " %(anycast, util.get_ip_from_cidr(lo1))
	
	target_cmd = util.remove_last_semicolon(target_cmd)
	print target_cmd
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_conf_payload( target_cmd)), headers=util.myheaders,auth=(userid,passwd)).json()
	outputs = resp['ins_api']['outputs']['output']
	#print outputs
	for out in outputs:
		if not 'Success' in out['msg']:
			retval = False
	print 'do conf vxlan/nve1 on %s is %s' %(hostip, retval)
	return retval
def get_neighbors( hostip, userid, passwd):
	myentries = []
	resp = requests.post( util.get_nxapi_endpoint( hostip), data=json.dumps( util.get_payload('show cdp neighbors')), headers=util.myheaders,auth=(userid,passwd)).json()
	#print resp
	success = resp['ins_api']['outputs']['output']['msg']
	if success == 'Success' :
		entries = resp['ins_api']['outputs']['output']['body']['TABLE_cdp_neighbor_brief_info']['ROW_cdp_neighbor_brief_info']
		if type(entries) == list:
			for entry in entries:
				e = {}
				e['device_id'] = entry['device_id']
				e['intf_id'] = entry['intf_id']
				e['port_id'] = entry['port_id']
				myentries.append( e)
			return myentries
		elif type(entries) == dict:
			e = {}
			e['device_id'] = entries['device_id']
			e['intf_id'] = entries['intf_id']
			e['port_id'] = entries['port_id']
			myentries.append( e)
		return myentries