Monday, January 16, 2012

[Level 2] Cassandra token generation tool by Python.

#!/bin/env python
import sys 
if (len(sys.argv) > 1): 
    num=int(sys.argv[1])
else:
    num=int(raw_input("How many nodes are in your cluster? "))
for i in range(0, num):
    print 'node %d: %d' % (i, (i*(2**127)/num))
$ ./cassandraTokenGenTools.py 
How many nodes are in your cluster? 5 
node 0: 0
node 1: 34028236692093846346337460743176821145
node 2: 68056473384187692692674921486353642291
node 3: 102084710076281539039012382229530463436
node 4: 136112946768375385385349842972707284582
Wish this helps.
regards,
Stanley Huang