in ccmlib/cluster.py [0:0]
def populate(self, nodes, debug=False, tokens=None, use_vnodes=None, ipprefix='127.0.0.', ipformat=None, install_byteman=False, use_single_interface=False):
"""Populate a cluster with nodes
@use_single_interface : Populate the cluster with nodes that all share a single network interface.
"""
if self.cassandra_version() < '4' and use_single_interface:
raise common.ArgumentError('use_single_interface is not supported in versions < 4.0')
node_count = nodes
dcs = []
if use_vnodes is None:
self.use_vnodes = len(tokens or []) > 1 or self._more_than_one_token_configured()
else:
self.use_vnodes = use_vnodes
if isinstance(nodes, list):
# We set PFS here as a "marker" that we need to read cassandra-topology.properties for this cluster
# This is then checked in node.py::_update_yaml where we check if initial_location_provider is set in
# the yaml (indicating that modern config is supported) and we set TopologyFileLocationProvider if so
self.set_configuration_options(values={'endpoint_snitch': 'org.apache.cassandra.locator.PropertyFileSnitch'})
node_count = 0
i = 0
for c in nodes:
i = i + 1
node_count = node_count + c
for x in xrange(0, c):
dcs.append('dc%d' % i)
if node_count < 1:
raise common.ArgumentError('invalid node count %s' % nodes)
for i in xrange(1, node_count + 1):
if 'node%s' % i in list(self.nodes.values()):
raise common.ArgumentError('Cannot create existing node node%s' % i)
if tokens is None:
if self.use_vnodes:
# from 4.0 tokens can be pre-generated via the `allocate_tokens_for_local_replication_factor: 3` strategy
# this saves time, as allocating tokens during first start is slow and non-concurrent
if self.can_generate_tokens() and not 'CASSANDRA_TOKEN_PREGENERATION_DISABLED' in self._environment_variables:
if len(dcs) <= 1:
for x in xrange(0, node_count):
dcs.append('dc1')
tokens = self.generated_tokens(dcs)
else:
common.debug("using balanced tokens for non-vnode cluster")
if len(dcs) <= 1:
tokens = self.balanced_tokens(node_count)
else:
tokens = self.balanced_tokens_across_dcs(dcs)
if not ipformat:
ipformat = ipprefix + "%d"
for i in xrange(1, node_count + 1):
tk = None
if tokens is not None and i - 1 < len(tokens):
tk = tokens[i - 1]
dc = dcs[i - 1] if i - 1 < len(dcs) else None
binary = None
if self.cassandra_version() >= '1.2':
if use_single_interface:
#Always leave 9042 and 9043 clear, in case someone defaults to adding
# a node with those ports
binary = (ipformat % 1, 9042 + 2 + (i * 2))
else:
binary = (ipformat % i, 9042)
thrift = None
if self.cassandra_version() < '4':
thrift = (ipformat % i, 9160)
storage_interface = ((ipformat % i), 7000)
if use_single_interface:
#Always leave 7000 and 7001 in case someone defaults to adding
#with those port numbers
storage_interface = (ipformat % 1, 7000 + 2 + (i * 2))
node = self.create_node(name='node%s' % i,
auto_bootstrap=False,
thrift_interface=thrift,
storage_interface=storage_interface,
jmx_port=str(7000 + i * 100),
remote_debug_port=str(2000 + i * 100) if debug else str(0),
byteman_port=str(4000 + i * 100) if install_byteman else str(0),
initial_token=tk,
binary_interface=binary,
environment_variables=self._environment_variables)
self.add(node, True, dc)
self._update_config()
return self