Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import pyeapi
- import pymongo
- import threading
- __author__ = ['shane@craigslist.org']
- __version__ = "August 2016"
- #ileaf collection for threading
- def ileaf_collect(ic):
- # connect to the node
- node = pyeapi.connect_to(ic)
- # insert running config into neteng database with collection ileaf
- db.ileaf_ospf.insert(node.enable(['show hostname','show ip ospf'])
- ,check_keys=False)
- # check_keys false otherwise keys with '.' contained in them raise an error
- #spine collection for threading
- def spine_collect(sp):
- # connect to the node
- node = pyeapi.connect_to(sp)
- # insert running config into neteng database with collection ileaf
- db.spine_ospf.insert(node.enable(['show hostname','show ip ospf']),
- check_keys=False)
- # check_keys false otherwise keys with '.' contained in them raise an error
- #eleaf collection for threading
- def eleaf_collect(el):
- # connect to the node
- node = pyeapi.connect_to(el)
- # insert running config into neteng database with collection ileaf
- db.eleaf_ospf.insert(node.enable(['show hostname','show ip ospf']),
- check_keys=False)
- # check_keys false otherwise keys with '.' contained in them raise an error
- #icore collection for threading
- def icore_collect(ic):
- # connect to the node
- node = pyeapi.connect_to(ic)
- # insert running config into neteng database with collection ileaf
- db.icore_ospf.insert(node.enable(['show hostname','show ip ospf']),
- check_keys=False)
- # check_keys false otherwise keys with '.' contained in them raise an error
- #ashburn 200paul ileaf arista devices
- ileaf = ('ileaf-01-02-53a','ileaf-01-05-50a','ileaf-01-06-50a',
- 'ileaf-01-07-50a','ileaf-01-12-50a','ileaf-01-12-50a',
- 'ileaf-01-13-50a','ileaf-01-14-50a','ileaf-01-14-50a',
- 'ileaf-01-15-50a','ileaf-02-05-50a','ileaf-02-06-50a',
- 'ileaf-02-07-50a','ileaf-02-12-50a','ileaf-02-13-50a',
- 'ileaf-02-14-50a','ileaf-02-15-50a','ileaf-00-00-34f',
- 'ileaf-00-01-34f','ileaf-00-02-22f','ileaf-00-03-34f',
- 'ileaf-00-04-34f','ileaf-00-05-34f','ileaf-01-00-34f',
- 'ileaf-01-01-34f','ileaf-01-02-34f','ileaf-01-03-34f',
- 'ileaf-01-04-34f','ileaf-01-05-34f','ileaf-01-06-36f',
- 'ileaf-01-07-36f','ileaf-01-08-36f','ileaf-01-09-36f',
- 'ileaf-01-10-36f','ileaf-01-11-36f','ileaf-01-12-36f',
- 'ileaf-01-13-36f','ileaf-04-01-34f','ileaf-04-02-34f',
- 'ileaf-04-03-34f','ileaf-04-04-34f','ileaf-04-05-34f',
- 'ileaf-04-06-36f','ileaf-04-07-36f','ileaf-04-08-36f',
- 'ileaf-04-09-36f','ileaf-04-10-36f','ileaf-04-11-36f',
- 'ileaf-04-12-36f','ileaf-04-13-36f'
- )
- #ashburn 200paul spine arista devices
- spine = ('spine1a','spine2a','spine3a','spine4a',
- 'spine1f','spine2f','spine3f','spine4f'
- )
- #ashburn 200paul eleaf arista devices
- eleaf = ('eleaf1a','eleaf2a','eleaf3a','eleaf4a',
- 'eleaf1f','eleaf2f','eleaf3f','eleaf4f'
- )
- #ashburn 200paul icore arista devices
- icore = ('icore1a','icore2a','icore1f-new','icore2f-new')
- if __name__ == '__main__':
- try:
- # needs a mongodb instance running
- # https://wiki.int.craigslist.org/twiki/bin/view/Main/MongodbAristaJuniper
- conn = pymongo.MongoClient('172.19.18.1', 27017)
- except pymongo.errors.ConnectionFailure, e:
- print "Could not connect to MongoDB: %s" % e
- # connecting to the database named neteng
- db = conn.neteng
- # load predefined listing of nodes and values of the format:
- # each device
- #[connection:$DEVICE_NAME]
- #host: $IP
- # once per file
- #[DEFAULT]
- #username: $USER
- #password: $PASS
- #transport: https
- pyeapi.load_config('~/.eapi.conf')
- #reset collection ileaf spine eleaf icore
- db.drop_collection('ileaf_ospf')
- db.drop_collection('spine_ospf')
- db.drop_collection('eleaf_ospf')
- db.drop_collection('icore_ospf')
- threads = []
- # loop through ileaf arista devices
- for il in ileaf:
- t = threading.Thread(target=ileaf_collect, args=(il,))
- threads.append(t)
- t.start()
- # loop through spine arista devices
- for sp in spine:
- t = threading.Thread(target=spine_collect, args=(sp,))
- threads.append(t)
- t.start()
- # loop through eleaf arista devices
- for el in eleaf:
- t = threading.Thread(target=eleaf_collect, args=(el,))
- threads.append(t)
- t.start()
- # loop through icore arista devices
- for ic in icore:
- t = threading.Thread(target=icore_collect, args=(ic,))
- threads.append(t)
- t.start()
Add Comment
Please, Sign In to add comment