Created
June 18, 2015 19:13
-
-
Save hkumarmk/89fecf3f21cab3a2575b to your computer and use it in GitHub Desktop.
to get data in contrail
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
pool = ConnectionPool('config_db_uuid') | |
col_fam = ColumnFamily(pool, 'obj_uuid_table') | |
zk = KazooClient(hosts='127.0.0.1:2181') | |
zk.start() | |
uuid = sys.argv[1] | |
print 'Looking up %s in Cassandra... ' % (uuid,), | |
cass_data = col_fam.get_range(uuid).next()[1] | |
print 'Found it!' | |
t = cass_data['type'] | |
if t != '"route_target"': | |
print 'Unexpected type:', t | |
sys.exit(1) | |
print 'Backrefs:' | |
backrefs_found = False | |
for k in cass_data: | |
if k.startswith('backref'): | |
_br, _type, next_uuid = k.split(':') | |
print '%s: %s' % (_type, next_uuid) | |
backrefs_found = True | |
if not backrefs_found: | |
print ' No backrefs' | |
display_name = cass_data['prop:display_name'].strip('"') | |
print 'Display name:', display_name | |
rt_id = int(display_name.split(':')[-1]) | |
zk_path = '/id/bgp/route-targets/%010d' % (rt_id,) | |
print 'Looking it up in Zookeeper (%s)... ' % (zk_path,), | |
zk_data, _zk_stat = zk.get(zk_path) | |
print 'Found it!' | |
print 'Data:', zk_data | |
zk_path = '/fq-name-to-uuid/routing_instance:%s' % (zk_data,) | |
try: | |
print 'Looking up as routing instance (%s)... ' % (zk_path,), | |
zk_data, _zk_stat = zk.get(zk_path) | |
print 'Found it!' | |
print 'UUID:', zk_data | |
print 'Looking it up in Cassandra...', | |
cass_data = col_fam.get_range(zk_data).next()[1] | |
print 'Found it!' | |
print cass_data | |
except: | |
print 'Not found!' | |
print 'Scanning through Cassandra for fq_name: %s' % zk_data | |
fq_name = zk_data.split(':') | |
match = None | |
for d in col_fam.get_range(): | |
uuid, data = d | |
if data.get('type', '') == '"routing_instance"' and data['fq_name'] == fq_name: | |
match = d | |
break | |
if match: | |
print 'Found it!' | |
print data['fq_name'] | |
print fq_name | |
else: | |
print 'Not found!' | |
zk.stop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment