def get_clusters_with_role(role, state="running", region="us-east-1"): all_instances = get_ec2_connection(region).get_all_instances() clusters = [] for res in all_instances: instance = res.instances[0] for group in res.groups: if group.name.endswith("-" + role) and instance.state == state: clusters.append(re.sub("-%s$" % re.escape(role), "", group.name)) return clusters
def __init__(self, name, config_dir, region): super(Ec2Cluster, self).__init__(name, config_dir, region) self.ec2Connection = get_ec2_connection(region)