Example #1
0
    takes a directoyr passed as an argument, if provided, and iterates over the lines of all the files found parsing
    out data to create a dictionary of device data.

    The files are assumed to be output from "show cdp neig detail".

    The files are assumed to be named r*.txt or s*.txt

    If no directory is provided as an argument a default directory is chosen
'''

import glob
import sys
import pyfornet as pfn
import pprint as pp


data_file_directory = '/home/steve/dev/python-for-networkers/datafiles'  # set default dir

if len(sys.argv) == 2:
    data_file_directory = sys.argv[1]

if data_file_directory.endswith('/'):
    data_file_directory += '[rs]*.txt'
else:
    data_file_directory += '/[rs]*.txt'

file_list = glob.glob(data_file_directory)

dict = pfn.build_dev_dict(file_list)

pp.pprint(dict)
IOS (tm) C2950 Software (C2950-I6Q4L2-M), Version 12.1(22)EA8a, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2006 by cisco Systems, Inc.
Compiled Fri 28-Jul-06 15:16 by weiliu
advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF0000000000000019E845CE80FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full'''

r5_scnd = '''R5>show cdp neighbors detail
-------------------------
Device ID: SW1
Entry address(es):
  IP address: 10.1.1.22
Platform: cisco WS-C2950-24,  Capabilities: Switch IGMP
Interface: FastEthernet1,  Port ID (outgoing port): FastEthernet0/15
Holdtime : 145 sec
Version :
Cisco Internetwork Operating System Software
IOS (tm) C2950 Software (C2950-I6Q4L2-M), Version 12.1(22)EA8a, RELEASE SOFTWARE (fc1)
Copyright (c) 1986-2006 by cisco Systems, Inc.
Compiled Fri 28-Jul-06 15:16 by weiliu
advertisement version: 2
Protocol Hello:  OUI=0x00000C, Protocol ID=0x0112; payload len=27, value=00000000FFFFFFFF010221FF0000000000000019E845CE80FF0000
VTP Management Domain: ''
Native VLAN: 1
Duplex: full'''

dev_dict = pfn.build_dev_dict([sw1_scnd, r1_scnd, r2_scnd, r3_scnd, r4_scnd, r5_scnd])

pp.pprint(dev_dict)