当前位置: 首页>>代码示例>>Python>>正文


Python Device.conf方法代码示例

本文整理汇总了Python中device.Device.conf方法的典型用法代码示例。如果您正苦于以下问题:Python Device.conf方法的具体用法?Python Device.conf怎么用?Python Device.conf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在device.Device的用法示例。


在下文中一共展示了Device.conf方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: mon_device

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import conf [as 别名]
def mon_device(device,seconds,tabs,destinationIp):
	threadQueue.put(1)
	destIp = destinationIp
	tabs = tabs*2
	deviceIp = device.connectedOn
	username = device.username
	passwor = device.password
	sw1 = Device(ip=deviceIp, username=username, password=passwor)
	sw1.open()

	flag = True
	print "Monitoring:",deviceIp
	try:
		while flag:
			allPack = []
			interfacers = get_int(sw1)
			device.updateInterfaceCounters(interfacers)
			for i in  interfacers:
				x = interface(i["interface"])
				x.populateCounters(i)
				#if x.eth_giants > 0 or x.eth_jumbo_inpkts > 0 or x.eth_crc > 0 or x.eth_giants or x.eth_inerr:
				if x.eth_outpkts > 1000:
					print ("-" * tabs)+ "Over 1000 on ", x.interface, x.eth_outpkts,deviceIp
					create_span = sw1.conf(" conf t ; monitor session 30 type erspan-source ; description ERSPAN30 for TEST ; source interface " + x.interface + " both ; destination ip " + destIp + " ; vrf default ; erspan-id 30 ; ip ttl 64 ; ip prec 0 ; ip dscp 0 ; mtu 1500 ; header-type 2 ; no shut ; end ;")
					print ("-" * tabs) + "Beginning erspan for", seconds ,"seconds","to",deviceIp,"on int",x.interface
					time.sleep(10)
					print ("-" * tabs) + "Done capturing, now Cleaning config",deviceIp,"on int",x.interface
					clean = sw1.conf("config t ;" + " no monitor session 30 ; end")
					clearing_counters = sw1.conf("clear counters interface" + x.interface)
					print ("-" * tabs) + "Done Cleaning, erspan sent to", destIp, "from",deviceIp, "-", x.interface
					# Remove flag for continous moitoring, with flag on it stops after the interface is noticed
					#flag = False
				else:
					allPack.append([x.eth_outpkts,x.interface])
			# 	if x.state == "up" and "Ether" in x.interface:
			# 		print x.interface, x.state, x.eth_outpkts
			time.sleep(3)
			ints = []
			interf = []
			for i in allPack:
				ints.append(i[0])
				interf.append(i[1])
			maxInt = max(ints)
			maxInterface = interf[ints.index(maxInt)]
			print ("-" * tabs) + "Highest packet count is", maxInt, "that is under 1000 on",maxInterface
	except (KeyboardInterrupt, SystemExit):
		print ("-" * tabs) + "Keyboard Interrupt, Forcing cleaning of",deviceIp
		clean = sw1.conf("config t ;" + " no monitor session 30 ; end")
		print ("-" * tabs) + "Done Cleaning, erspan sent to", destIp, "from",deviceIp,
	queue.put("RANDOM DATA FOR QUEUE")         
	threadQueue.get(False, 2)
开发者ID:knolls,项目名称:cisco_class,代码行数:53,代码来源:MultiSpaner.py

示例2: conf_intfs

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import conf [as 别名]
def conf_intfs(conf_dict):
    """
    This connects to the chosen switch and gets all of the ports. and vlans.
    This is filtered to access ports only.

    params:
    conf_dict (dictionary), example:

    {
    "switch_ip": "172.31.217.135",
    "intf_desc": "Configured by NXAPI",
    "intf_id": [
	"Ethernet1/1",
	"Ethernet1/2"
    ],
    "vlan_id": "31"
	}

    """
    config_changes_list = ""
    switch_user = "admin"
    switch_pw = "cisco123"
    switch_ip = conf_dict["switch_ip"]
    switch_name = get_switchname(switch_ip)
    # Connect to switch
    switch = Device(ip=switch_ip, username=switch_user, password=switch_pw)
    switch.open()
    # Parse data in to commands
    for item in range(len(conf_dict["intf_id"])):
        change_vlan = (
            "config t ; interface " + conf_dict["intf_id"][item] + " ; switchport access vlan " + conf_dict["vlan_id"]
        )
        change_desc = "config t ; interface " + conf_dict["intf_id"][item] + " ; description " + conf_dict["intf_desc"]
        # Send switch commands to NXAPI
        switch.conf(change_vlan)
        switch.conf(change_desc)
        # Generate NXOS-friendly config to return to consumer
        config_changes_list += show_run(switch_ip, conf_dict["intf_id"][item])
        # Log cli_conf call to local file
        logtime = get_time()
        log_change(logtime + ": " + switch_name + "(" + switch_user + "): " + change_vlan + "\n")
        log_change(logtime + ": " + switch_name + "(" + switch_user + "): " + change_desc + "\n")
    return config_changes_list
开发者ID:sigmanet,项目名称:configurator,代码行数:45,代码来源:switchconfig.py

示例3: conf_intfs

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import conf [as 别名]
def conf_intfs(conf_dict):
    '''
    This connects to the chosen switch and gets all of the ports. and vlans.
    This is filtered to access ports only.
    '''
    config_changes_list = ""
    switch_user = 'admin'
    switch_pw = 'cisco123'
    switch_ip = conf_dict['switch_ip']
    switch = Device(ip=switch_ip, username=switch_user, password=switch_pw)
    switch.open()

    for item in range(len(conf_dict['intf_id'])):
        change_vlan = 'config t ; interface ' + conf_dict['intf_id'][item] + ' ; switchport access vlan ' + conf_dict['vlan_id']
        change_desc = 'config t ; interface ' + conf_dict['intf_id'][item] + ' ; description ' + conf_dict['intf_desc']
        switch.conf(change_vlan)
        switch.conf(change_desc)
        config_changes_list += show_run(switch_ip, conf_dict['intf_id'][item])

    return config_changes_list
开发者ID:jeffliu0,项目名称:classproj,代码行数:22,代码来源:switchconfig.py

示例4: mon_device

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import conf [as 别名]
def mon_device(device):
	threadQueue.put(1)
	deviceIp = device.connectedOn
	username = device.username
	passwor = device.password
	sw1 = Device(ip=deviceIp, username=username, password=passwor)
	sw1.open()

	flag = True
	print "Monitoring:",deviceIp
	while flag:
		allPack = []
		interfacers = get_int(sw1)
		device.updateInterfaceCounters(interfacers)
		for i in  interfacers:
			x = interface(i["interface"])
			x.populateCounters(i)
			#if x.eth_giants > 0 or x.eth_jumbo_inpkts > 0 or x.eth_crc > 0 or x.eth_giants or x.eth_inerr:
			if x.eth_outpkts > 1000:
				print "Over 1000 on ", x.interface, x.eth_outpkts,deviceIp
				conf = sw1.conf("config t ; ip access-list MonACLTemp ; permit ip any any log ;" + "int " + x.interface  + " ; ip access-group MonACLTemp in ; end ; ethanalyzer local interface inband write bootflash:test.cap ")
				print "\tBeginning Cap for 1 min",deviceIp
				time.sleep(10)
				print "\tDone capturing, now Cleaning config",deviceIp
				clean = sw1.conf("config t ;" + " int " + x.interface  + " ; no ip access-group MonACLTemp in ; exit ; no ip access-list MonACLTemp ; end")
				clearing_counters = sw1.conf("clear counters interface" + x.interface)
				# Remove flag for continous moitoring, with flag on it stops after the interface is noticed
				flag = False
			else:
				allPack.append(x.eth_outpkts)
		# 	if x.state == "up" and "Ether" in x.interface:
		# 		print x.interface, x.state, x.eth_outpkts
		time.sleep(3)
		print max(allPack), "highest packet count number under 1000 on",deviceIp
	queue.put("RANDOM DATA FOR QUEUE")         
	threadQueue.get(False, 2)
	print "Done Cleaning, capture at bootflash:test.cap", deviceIp
开发者ID:knolls,项目名称:cisco_class,代码行数:39,代码来源:MultiAutoShark.py

示例5:

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import conf [as 别名]


ip = result['ins_api']['outputs']['output']['body']['TABLE_interface']['ROW_interface']['eth_ip_addr']
print ip

mask = result['ins_api']['outputs']['output']['body']['TABLE_interface']['ROW_interface']['eth_ip_mask']
print mask

print ip + '/' + mask

sh_vlan = sw1.show('sh vl')
sh_vlan_dict = xmltodict.parse(sh_vlan[1])
print json.dumps( sh_vlan_dict, indent=4)


vlan10_name = sh_vlan_dict['ins_api']['outputs']['output']['body']['TABLE_vlanbrief']['ROW_vlanbrief'][1]['vlanshowbr-vlanname']
print vlan10_name


vlans = sh_vlan_dict['ins_api']['outputs']['output']['body']['TABLE_vlanbrief']['ROW_vlanbrief']
for each in vlans:
	print 'VLAN ID: ', each['vlanshowbr-vlanid-utf']
	print 'VLAN NAME: ', each['vlanshowbr-vlanname']
	print '=' * 25

push_l3port = sw1.conf('config t ; interface e1/24 ; no switchport ')
push_l3ip = sw1.conf('config t ; interface e1/24 ; ip address 172.19.21.1/24 ')
cmd = 'config t ; int e1/24 ; '

开发者ID:abzweber,项目名称:cisco_class,代码行数:30,代码来源:lab311_NX_API.py


注:本文中的device.Device.conf方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。