Guest User

Untitled

a guest
Aug 10th, 2016
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.63 KB | None | 0 0
  1. #!/usr/bin/python
  2. import pyeapi
  3. import pymongo
  4. import threading
  5.  
  6. __author__ = ['shane@craigslist.org']
  7. __version__ = "August 2016"
  8.  
  9. #ileaf collection for threading
  10. def ileaf_collect(ic):
  11. # connect to the node
  12. node = pyeapi.connect_to(ic)
  13. # insert running config into neteng database with collection ileaf
  14. db.ileaf_ospf.insert(node.enable(['show hostname','show ip ospf'])
  15. ,check_keys=False)
  16. # check_keys false otherwise keys with '.' contained in them raise an error
  17.  
  18. #spine collection for threading
  19. def spine_collect(sp):
  20. # connect to the node
  21. node = pyeapi.connect_to(sp)
  22. # insert running config into neteng database with collection ileaf
  23. db.spine_ospf.insert(node.enable(['show hostname','show ip ospf']),
  24. check_keys=False)
  25. # check_keys false otherwise keys with '.' contained in them raise an error
  26.  
  27. #eleaf collection for threading
  28. def eleaf_collect(el):
  29. # connect to the node
  30. node = pyeapi.connect_to(el)
  31. # insert running config into neteng database with collection ileaf
  32. db.eleaf_ospf.insert(node.enable(['show hostname','show ip ospf']),
  33. check_keys=False)
  34. # check_keys false otherwise keys with '.' contained in them raise an error
  35.  
  36. #icore collection for threading
  37. def icore_collect(ic):
  38. # connect to the node
  39. node = pyeapi.connect_to(ic)
  40. # insert running config into neteng database with collection ileaf
  41. db.icore_ospf.insert(node.enable(['show hostname','show ip ospf']),
  42. check_keys=False)
  43. # check_keys false otherwise keys with '.' contained in them raise an error
  44.  
  45. #ashburn 200paul ileaf arista devices
  46. ileaf = ('ileaf-01-02-53a','ileaf-01-05-50a','ileaf-01-06-50a',
  47. 'ileaf-01-07-50a','ileaf-01-12-50a','ileaf-01-12-50a',
  48. 'ileaf-01-13-50a','ileaf-01-14-50a','ileaf-01-14-50a',
  49. 'ileaf-01-15-50a','ileaf-02-05-50a','ileaf-02-06-50a',
  50. 'ileaf-02-07-50a','ileaf-02-12-50a','ileaf-02-13-50a',
  51. 'ileaf-02-14-50a','ileaf-02-15-50a','ileaf-00-00-34f',
  52. 'ileaf-00-01-34f','ileaf-00-02-22f','ileaf-00-03-34f',
  53. 'ileaf-00-04-34f','ileaf-00-05-34f','ileaf-01-00-34f',
  54. 'ileaf-01-01-34f','ileaf-01-02-34f','ileaf-01-03-34f',
  55. 'ileaf-01-04-34f','ileaf-01-05-34f','ileaf-01-06-36f',
  56. 'ileaf-01-07-36f','ileaf-01-08-36f','ileaf-01-09-36f',
  57. 'ileaf-01-10-36f','ileaf-01-11-36f','ileaf-01-12-36f',
  58. 'ileaf-01-13-36f','ileaf-04-01-34f','ileaf-04-02-34f',
  59. 'ileaf-04-03-34f','ileaf-04-04-34f','ileaf-04-05-34f',
  60. 'ileaf-04-06-36f','ileaf-04-07-36f','ileaf-04-08-36f',
  61. 'ileaf-04-09-36f','ileaf-04-10-36f','ileaf-04-11-36f',
  62. 'ileaf-04-12-36f','ileaf-04-13-36f'
  63. )
  64. #ashburn 200paul spine arista devices
  65. spine = ('spine1a','spine2a','spine3a','spine4a',
  66. 'spine1f','spine2f','spine3f','spine4f'
  67. )
  68. #ashburn 200paul eleaf arista devices
  69. eleaf = ('eleaf1a','eleaf2a','eleaf3a','eleaf4a',
  70. 'eleaf1f','eleaf2f','eleaf3f','eleaf4f'
  71. )
  72. #ashburn 200paul icore arista devices
  73. icore = ('icore1a','icore2a','icore1f-new','icore2f-new')
  74.  
  75. if __name__ == '__main__':
  76. try:
  77. # needs a mongodb instance running
  78. # https://wiki.int.craigslist.org/twiki/bin/view/Main/MongodbAristaJuniper
  79. conn = pymongo.MongoClient('172.19.18.1', 27017)
  80. except pymongo.errors.ConnectionFailure, e:
  81. print "Could not connect to MongoDB: %s" % e
  82. # connecting to the database named neteng
  83. db = conn.neteng
  84. # load predefined listing of nodes and values of the format:
  85. # each device
  86. #[connection:$DEVICE_NAME]
  87. #host: $IP
  88. # once per file
  89. #[DEFAULT]
  90. #username: $USER
  91. #password: $PASS
  92. #transport: https
  93. pyeapi.load_config('~/.eapi.conf')
  94. #reset collection ileaf spine eleaf icore
  95. db.drop_collection('ileaf_ospf')
  96. db.drop_collection('spine_ospf')
  97. db.drop_collection('eleaf_ospf')
  98. db.drop_collection('icore_ospf')
  99. threads = []
  100. # loop through ileaf arista devices
  101. for il in ileaf:
  102. t = threading.Thread(target=ileaf_collect, args=(il,))
  103. threads.append(t)
  104. t.start()
  105. # loop through spine arista devices
  106. for sp in spine:
  107. t = threading.Thread(target=spine_collect, args=(sp,))
  108. threads.append(t)
  109. t.start()
  110. # loop through eleaf arista devices
  111. for el in eleaf:
  112. t = threading.Thread(target=eleaf_collect, args=(el,))
  113. threads.append(t)
  114. t.start()
  115. # loop through icore arista devices
  116. for ic in icore:
  117. t = threading.Thread(target=icore_collect, args=(ic,))
  118. threads.append(t)
  119. t.start()
Add Comment
Please, Sign In to add comment