def get_clusters(include_linked=False):
    """
    Get configured or linked clusters.

    :param include_linked: whether to look for linked clusters
    :type include_linked: bool
    :returns: list of Clusters
    :rtype: [Clusters]
    """

    clusters_path = config.get_clusters_path()
    util.ensure_dir_exists(clusters_path)
    clusters = set()

    uuid_regex = re.compile((r'^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-'
                             r'[89ab][a-f0-9]{3}-[a-f0-9]{12}\Z'))

    for entry in os.listdir(clusters_path):
        entry_path = os.path.join(clusters_path, entry)
        if os.path.isdir(entry_path) and uuid_regex.match(entry):
            c = Cluster(entry)
            clusters.add(c)

    # Search for linked clusters after configured clusters, this makes sure
    # the set gives priority to Cluster over LinkedCluster.
    if include_linked:
        try:
            linked_clusters = get_linked_clusters()
        except DCOSException:
            pass
        else:
            clusters.update(linked_clusters)

    return list(clusters)
Exemple #2
0
def get_clusters():
    """
    :returns: list of configured Clusters
    :rtype: [Clusters]
    """

    clusters_path = config.get_clusters_path()
    util.ensure_dir_exists(clusters_path)
    clusters = os.listdir(clusters_path)
    return [Cluster(cluster_id) for cluster_id in clusters]
Exemple #3
0
def get_clusters():
    """
    :returns: list of configured Clusters
    :rtype: [Clusters]
    """

    clusters_path = config.get_clusters_path()
    util.ensure_dir_exists(clusters_path)
    clusters = []

    uuid_regex = re.compile((r'^[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-'
                             r'[89ab][a-f0-9]{3}-[a-f0-9]{12}\Z'))
    for entry in os.listdir(clusters_path):
        entry_path = os.path.join(clusters_path, entry)
        if os.path.isdir(entry_path) and uuid_regex.match(entry):
            clusters.append(entry)

    return [Cluster(cluster_id) for cluster_id in clusters]
Exemple #4
0
 def __init__(self, cluster_id):
     self.cluster_id = cluster_id
     self.cluster_path = os.path.join(config.get_clusters_path(),
                                      cluster_id)