in ccmlib/cluster.py [0:0]
def generate_dc_tokens(self, node_count, tokens):
if self.cassandra_version() < '4' or (self.partitioner and not ('Murmur3' in self.partitioner or 'Random' in self.partitioner)):
raise common.ArgumentError("generate-tokens script only for >=4.0 and Murmur3 or Random")
if not self._more_than_one_token_configured():
raise common.ArgumentError("Cannot use generate-tokens script without num_tokens > 1")
partitioner = 'RandomPartitioner' if ( self.partitioner and 'Random' in self.partitioner) else 'Murmur3Partitioner'
generate_tokens = common.join_bin(self.get_install_dir(), os.path.join('tools', 'bin'), 'generatetokens')
cmd_list = [generate_tokens, '-n', str(node_count), '-t', str(self._config_options.get("num_tokens")), '--rf', str(min(3,node_count)), '-p', partitioner]
process = subprocess.Popen(cmd_list, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=os.environ.copy())
# the first line is "Generating tokens for X nodes with" and can be ignored
process.stdout.readline()
for n in range(1,node_count+1):
stdout_output = re.sub(r'^.*?:', '', process.stdout.readline().decode("utf-8"))
node_tokens = stdout_output.replace('[','').replace(' ','').replace(']','').replace('\n','')
tokens.append(node_tokens)
assert 0 < len(tokens), "No tokens generated from invocation: {}".format(str(cmd_list))
common.debug("pregenerated tokens from cmd_list: {} are {}".format(str(cmd_list),tokens))