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


Python Device.open方法代码示例

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


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

示例1: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():

    switch = Device(ip='172.31.217.136', username='admin', password='cisco123')
    switch.open()

    show_boot_config = copy_bootflash(switch)
    print show_boot_config
开发者ID:danny-chan8,项目名称:cisco_class,代码行数:9,代码来源:bf-config_v4.py

示例2: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():
	'''Call the show_ip_int_brief function and read in from file'''
	
	#check they entered a filename
	if len(sys.argv) <= 1:
		print "You must enter a filename: int_brief.py <filename>"
		sys.exit()
	
	else:
		#check if the file name is correct and can be opened
		try:
			script, filename = sys.argv
			with open(filename, 'r') as fp:	#with will close file
				for line in fp:				#loop through the lines
					switch_admin = []
					if len(line.split()) == 3:	#check if there are three variables per line

						for word in line.split():	#loop through the words and add them to a list
							#fill a list with the items in the line - should be three
							switch_admin.append(word)
						
						#create the switch object
						switch = Device(ip=switch_admin[0], username=switch_admin[1], password=switch_admin[2])
						switch.open()
						#call the  function
						show_ip_int_brief(switch, switch_admin[0])
					else:
						print "Your file variables are incorrect. It should be <ip address> <username> <password> per line."
						sys.exit()
		except IOError:
			print "Your file was mistyped! Please try again."
			sys.exit()
开发者ID:lisroach,项目名称:9k_scripts,代码行数:34,代码来源:int_brief.py

示例3: crawlDevice

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def crawlDevice(ip_address,user,pw):
	sw1 = Device(ip=ip_address, username=user, password=pw)
	sw1.open()

	# Getting everything into dicts
	sh_vrf = get_vrf(sw1)
	int_brief = get_ip_int_b(sw1)
	int_status = get_int_status(sw1)
	hostname,proccesor_ID,version = get_hostname_serial_version(sw1)
	neighbors = get_cdp_info(sw1)
	port_channels = get_portchannel_sum(sw1)
	# Adding all data into objs
	LocalDevice = root_Device(hostname,proccesor_ID,version,ip_address,user,pw)

	for singleVrf in sh_vrf:
		vrf = Vrf(singleVrf["vrf-name-out"])
		if "TABLE_prefix" in singleVrf["TABLE_addrf"][ "ROW_addrf"].keys():
			for prefixes in singleVrf["TABLE_addrf"][ "ROW_addrf"]["TABLE_prefix"]["ROW_prefix"]:
				vrf.addPrefix(prefixes["ipprefix"])
			LocalDevice.addVrf(vrf)

	for ipInter in int_brief:
		LocalDevice.addIp(ipInter["ROW_intf"]["prefix"])

	LocalDevice.addPortChannel(port_channels)
	for interface in int_status:
		LocalDevice.addIp(interface)

	for neighbor in neighbors:
		neighEntry = Neighbors(root_Device,neighbor)
		LocalDevice.addNeighbor(neighEntry)



	return LocalDevice
开发者ID:knolls,项目名称:cisco_class,代码行数:37,代码来源:MultiAutoShark.py

示例4: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():

    switch = Device(ip='172.31.217.133',username='admin',password='cisco123')
    switch.open()

    mac_table = get_mac(switch)
    arp_table = get_arp(switch)

    print "Will parse the following MAC and ARP tables obtained from the switch:"
    print json.dumps(mac_table, indent=4)   
    print json.dumps(arp_table, indent=4)
    
    # Loop through the MAC address table
    for mac_entry in mac_table:
        # If the MAC address is present in the ARP table
        if mac_entry in arp_table:

            #Attempt name resolution.  gethostbyaddr will throw an exception if host is not found
            try:
                
                ip_address = arp_table[mac_entry]
                interface_name = mac_table[mac_entry]
                
                hostname = gethostbyaddr(ip_address)
                
                print hostname[0] + " (" + ip_address + ") is on " + interface_name
                
                # Pass the result to write_descript to apply the hostname to the NX-OS interface
                write_descript(switch,interface_name,hostname[0])
                
            except:
                # For simplicity, we will assume that any exception is a host not found and move on
                print "No hostname for " + ip_address + " was found... skipping"
开发者ID:mijo77,项目名称:cisco_class,代码行数:35,代码来源:update_descrip.py

示例5: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():
    '''

    Main loop to retrieve data

    :return:
    '''
    args = getargs()

    username = args.user

    if not username:
        username = raw_input("Device Username:")

    password = getpass.getpass('Device password:')

    switch = Device(ip=args.switch, username=username, password=password)

    switch.open()

    result = get_forwardingpath(switch,
                                interface=args.interface,
                                src=args.source,
                                dst=args.destination,
                                lbalgo='ip' )

    print 'Traffic flowing from %s to %s will use physical interface %s' % (args.source, args.destination, result)
开发者ID:kevechol,项目名称:Kovarus-ACI-RP-Rotation,代码行数:29,代码来源:get-po-flow.py

示例6: getneighbors

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def getneighbors(ip,username,password):
    devices = [ ip ]
    devicecount=0
    while devicecount != len(devices):
        dev = Device(ip=devices[devicecount], username=username, password=password)
        dev.open()
        devices = devices + show_cdwneighbors(dev,devices)
        devicecount+=1
    return devices
开发者ID:jeremyguthrie,项目名称:cisco_class,代码行数:11,代码来源:portmap.py

示例7: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():

    switch = Device(ip='172.31.217.134', username='admin', password='cisco123')
    switch.open()

    ver = show_dev_version(switch)

    print json.dumps(ver, indent=4)

    ver_check = check_version(switch)
开发者ID:brentloper,项目名称:cisco_class,代码行数:12,代码来源:class-project-working.py

示例8: connect_pulldata

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def connect_pulldata(ipaddr, uname, pword):

  switch = Device(ip=ipaddr, username=uname, password=pword)
  switch.open()

  vtp_facts = ipaddr + ',' + vtp_info(switch)

  csvwriter = csv.writer(open("vtp.csv", "a"))

  csvwriter.writerow([vtp_facts])
开发者ID:rcraner,项目名称:cisco_class,代码行数:12,代码来源:rainman_v6.py

示例9: mon_device

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [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

示例10: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():

    args = sys.argv

    if len(args)  == 4:
        switch = Device(ip=args[1], username=args[2], password=args[3])
        
        try:
            switch.open()
            interface = show_interface(switch)
        except:
            print "\nshow-simple-inventory.py: Please review your input parameters."
    else:
        print "\nshow-simple-inventory.py: Invalid Key.\nSyntax: show-simple-inventory.py <switch-name> <username> <password>\n"
开发者ID:ronaldonascimentodantas,项目名称:cisco_class,代码行数:16,代码来源:show-simple-inventory.py

示例11: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():
    args = sys.argv


    sw1 = Device(ip='172.31.217.134', username='admin', password='cisco123')
    sw1.open()

    hardware = get_hardware(sw1)
    mgmt = get_mgmt(sw1)
    facts =  dict(hardware, **mgmt)
    if len(args) == 1:
        print json.dumps( facts, indent=4)
    elif args[1] in facts:
        print args[1].upper() + ":", json.dumps(facts[args[1]], indent=4)
    else:
        print "Invalid Key.  Try again."
开发者ID:sigmanet,项目名称:cisco_class,代码行数:18,代码来源:nxapi_facts.py

示例12: main

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def main():

    args = sys.argv

    if len(args)  == 5:
        switch = Device(ip=args[1], username=args[2], password=args[3])
        interface_name = args[4]   # Get the interface name
        
        try:
            switch.open()
            cdp = show_cdp(switch, interface_name)
            print cdp
        except:
            print "\nshow-cdp-inventory-interface.py: Please review your input parameters.\n\nSyntax: show-cdp-inventory-interface.py <switch-name> <username> <password> <interface_name>\n"
    else:
        print "\nshow-cdp-inventory-interface.py: Invalid Key.\nSyntax: show-cdp-inventory-interface.py <switch-name> <username> <password> <interface_name>\n"
开发者ID:ronaldonascimentodantas,项目名称:cisco_class,代码行数:18,代码来源:show-cdp-inventory-interface.py

示例13: show_run

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def show_run(switch_ip, intf_id):
    switch_user = 'admin'
    switch_pw = 'cisco123'

    switch = Device(ip=switch_ip, username=switch_user, password=switch_pw)
    switch.open()
    command = switch.show('show interface ' + intf_id + ' switchport')
    show_dict = xmltodict.parse(command[1])
    results = show_dict['ins_api']['outputs']['output']['body']['TABLE_interface']['ROW_interface']
    oper_mode = results['oper_mode']
    access_vlan = results['access_vlan']
    command = switch.show('show interface ' + intf_id)
    show_dict = xmltodict.parse(command[1])
    results = show_dict['ins_api']['outputs']['output']['body']['TABLE_interface']['ROW_interface']
    desc = results['desc']
    config_text = 'interface ' + intf_id + '\n  description ' + desc + '\n  switchport mode ' + oper_mode + '\n  switchport access vlan ' + access_vlan + '\n!\n'
    return config_text
开发者ID:jeffliu0,项目名称:classproj,代码行数:19,代码来源:switchconfig.py

示例14: getswitchinfo

# 需要导入模块: from device import Device [as 别名]
# 或者: from device.Device import open [as 别名]
def getswitchinfo(sw):
	switch = Device(ip=sw)
	switch.open()
	getdata = switch.show('show interface brief')

	show_intf_dict = xmltodict.parse(getdata[1])

	data = show_intf_dict['ins_api']['outputs']['output']['body']['TABLE_interface']['ROW_interface']

	#rint data
	# Code to loop through interfaces and put all 'up' in a list (align list with key)
	up_list= []
	for each in data:
		if 'up' in each.values():
			up_list.append(each['interface'])
	#print up_list
	return up_list
开发者ID:lisroach,项目名称:9k_scripts,代码行数:19,代码来源:Monitor_Interfaces.py

示例15: get_intfs

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

    switch = Device(ip=switch_ip, username=switch_user, password=switch_pw)
    switch.open()
    command = switch.show('show interface')
    show_dict = xmltodict.parse(command[1])
    results = show_dict['ins_api']['outputs']['output']['body']['TABLE_interface']['ROW_interface']
    intf_list = []
    for result in results:
        if 'eth_mode' in result and result['eth_mode'] == 'access':
            intf_list.append(result['interface'])
    return intf_list
开发者ID:jeffliu0,项目名称:classproj,代码行数:20,代码来源:switchconfig.py


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