Guest User

Untitled

a guest
Jul 14th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. import sys
  2.  
  3.  
  4. pool = ConnectionPool('config_db_uuid')
  5. col_fam = ColumnFamily(pool, 'obj_uuid_table')
  6. zk = KazooClient(hosts='127.0.0.1:2181')
  7. zk.start()
  8.  
  9. uuid = sys.argv[1]
  10. print 'Looking up %s in Cassandra... ' % (uuid,),
  11. cass_data = col_fam.get_range(uuid).next()[1]
  12. print 'Found it!'
  13.  
  14. t = cass_data['type']
  15. if t != '"route_target"':
  16. print 'Unexpected type:', t
  17. sys.exit(1)
  18.  
  19. print 'Backrefs:'
  20. backrefs_found = False
  21. for k in cass_data:
  22. if k.startswith('backref'):
  23. _br, _type, next_uuid = k.split(':')
  24. print '%s: %s' % (_type, next_uuid)
  25. backrefs_found = True
  26.  
  27. if not backrefs_found:
  28. print ' No backrefs'
  29.  
  30. print
  31. display_name = cass_data['prop:display_name'].strip('"')
  32. print 'Display name:', display_name
  33.  
  34. rt_id = int(display_name.split(':')[-1])
  35. zk_path = '/id/bgp/route-targets/%010d' % (rt_id,)
  36.  
  37. print 'Looking it up in Zookeeper (%s)... ' % (zk_path,),
  38. zk_data, _zk_stat = zk.get(zk_path)
  39. print 'Found it!'
  40.  
  41. print
  42. print 'Data:', zk_data
  43.  
  44. print
  45.  
  46. zk_path = '/fq-name-to-uuid/routing_instance:%s' % (zk_data,)
  47. try:
  48. print 'Looking up as routing instance (%s)... ' % (zk_path,),
  49. zk_data, _zk_stat = zk.get(zk_path)
  50. print 'Found it!'
  51.  
  52. print 'UUID:', zk_data
  53.  
  54. print
  55.  
  56. print 'Looking it up in Cassandra...',
  57. cass_data = col_fam.get_range(zk_data).next()[1]
  58. print 'Found it!'
  59.  
  60. print
  61.  
  62. print cass_data
  63. except:
  64. print 'Not found!'
  65. print
  66. print 'Scanning through Cassandra for fq_name: %s' % zk_data
  67. fq_name = zk_data.split(':')
  68. match = None
  69. for d in col_fam.get_range():
  70. uuid, data = d
  71. if data.get('type', '') == '"routing_instance"' and data['fq_name'] == fq_name:
  72. match = d
  73. break
  74. if match:
  75. print 'Found it!'
  76. print data['fq_name']
  77. print fq_name
  78. else:
  79. print 'Not found!'
  80.  
  81. zk.stop()
Advertisement
Add Comment
Please, Sign In to add comment