def get_clusters(cluster_regex='all', all_metadata=False):
    """Get all clusters matching the cluster name regex.

    Returns a list of names, unless all_metadata=True, then a map of
    all container inspection data is returned.
    """
    cluster_regex = cluster_regex + ("" if cluster_regex.endswith("$") else "$")
    clusters = defaultdict(list) # {cluster_name : [first_node_metadata, 2nd...], ...}
    cluster_nodes = defaultdict(list)
    p = subprocess.Popen(shlex.split("docker ps -aq"), stdout=subprocess.PIPE)
    containers = p.communicate()[0].strip()
    class NoContainersException(Exception):
        pass
    try:
        if containers == '':
            raise NoContainersException
        containers = containers.split('\n')
        for container in containers:
            data = get_container_data(container)
            try:
                labels = data['Config']['Labels']
                if labels and labels['cstar_node'] == 'true':
                    container_name = data['Name'] = data['Name'].lstrip('/')
                    node_num = labels['node'] = int(labels['node'])
                    if cluster_regex.lower() == 'all$' or re.match(cluster_regex, labels['cluster_name']):
                        clusters[labels['cluster_name']].append(data)
                        cluster_nodes[labels['cluster_name']].append(container_name)
            except __HOLE__:
                pass
    except NoContainersException:
        pass   

    # Sort cluster lists by node number:
    for cluster_name, cluster_data  in clusters.items():
        cluster_data.sort(key=lambda x:x['Config']['Labels']['node'])
        # spot check for inconsistencies:
        cluster_types = set([x['Config']['Labels']['cluster_type'] for x in cluster_data])
        assert len(cluster_types) == 1, "{} has more than one cluster_type: {}".format(cluster_name, cluster_types)
    for cluster_name, nodes in cluster_nodes.items():
        nodes.sort()

        
    if all_metadata:
        return clusters
    else:
        return cluster_nodes
dataset/ETHPy150Open datastax/cstar_perf/tool/cstar_perf/docker/cstar_docker.py/get_clusters