Builds the inventory for the given cluster and returns its path

        :param cluster: cluster to build inventory for
        :type cluster: :py:class:`elasticluster.cluster.Cluster`
974986
def _build_inventory(self, cluster):
        
        inventory_data = defaultdict(list)
        for node in cluster.get_all_nodes():
            if node.kind not in self.groups:
                # FIXME: should this raise a `ConfigurationError` instead?
                warn("Node kind `{0}` not defined in cluster!".format(node.kind))
                continue
            extra_vars = ['ansible_user=%s' % node.image_user]
            # check for nonstandard port, either IPv4 or IPv6
            if node.preferred_ip and ':' in node.preferred_ip:
                match = IPV6_RE.match(node.preferred_ip)
                if match:
                    host_port = match.groups()[1]
                else:
                    _, _, host_port = node.preferred_ip.partition(':')
                if host_port:
                    extra_vars.append('ansible_port=%s' % host_port)

            if node.kind in self.environment:
                extra_vars.extend('%s=%s' % (k, v) for k, v in
                                  self.environment[node.kind].items())
            for group in self.groups[node.kind]:
                connection_ip = node.preferred_ip
                if connection_ip:
                    inventory_data[group].append(
                        (node.name, connection_ip, str.join(' ', extra_vars)))

        if not inventory_data:
            elasticluster.log.info("No inventory file was created.")
            return None

        # create a temporary file to pass to ansible, since the
        # api is not stable yet...
        if self._storage_path_tmp:
            if not self._storage_path:
                self._storage_path = tempfile.mkdtemp()
            elasticluster.log.warning(
                "Writing inventory file to tmp dir `%s`", self._storage_path)

        inventory_path = os.path.join(
            self._storage_path, (cluster.name + '.inventory'))
        log.debug("Writing Ansible inventory to file `%s` ...", inventory_path)
        with open(inventory_path, 'w+') as inventory_file:
            for section, hosts in inventory_data.items():
                # Ansible throws an error "argument of type 'NoneType' is not
                # iterable" if a section is empty, so ensure we have something
                # to write in there
                if hosts:
                    inventory_file.write("\n[" + section + "]\n")
                    for host in hosts:
                        # don't want port, makes it look like ipv6
                        if ':' in host[1]:
                            match = IPV6_RE.match(node.preferred_ip)
                            if match:
                                host = (host[0], match.groups()[0], host[2])
                            else:
                                host = (host[0], host[1].partition(':')[0],
                                        host[2])
                        hostline = "%s ansible_host=%s %s\n" % host
                        inventory_file.write(hostline)
        return inventory_path
818505
def cluster_centers_(self):
        
        # TODO: Handle agglomerative clustering and LDA
        for attr in ('cluster_centers_',):
            try:
                return getattr(self.estimator, attr)
            except AttributeError:
                continue

        raise AttributeError(
            "could not find or make cluster_centers_ for {}".format(
            self.estimator.__class__.__name__
        ))
249673
def on_cluster_add(self, cluster):
        
        if cluster.discovery not in self.configurables[Discovery]:
            return

        discovery = self.configurables[Discovery][cluster.discovery]

        self.launch_thread(
            cluster.name, discovery.start_watching,
            cluster, self.sync_balancer_files
        )
1165392
def getclusters(self, count):
        

        # only proceed if we got sensible input
        if count <= 1:
            raise ClusteringError("When clustering, you need to ask for at "
                                  "least two clusters! "
                                  "You asked for %d" % count)

        # return the data straight away if there is nothing to cluster
        if (self.__data == [] or len(self.__data) == 1 or
                count == self.__initial_length):
            return self.__data

        # It makes no sense to ask for more clusters than data-items available
        if count > self.__initial_length:
            raise ClusteringError(
                "Unable to generate more clusters than "
                "items available. You supplied %d items, and asked for "
                "%d clusters." % (self.__initial_length, count))

        self.initialise_clusters(self.__data, count)

        items_moved = True  # tells us if any item moved between the clusters,
                            # as we initialised the clusters, we assume that
                            # is the case

        while items_moved is True:
            items_moved = False
            for cluster in self.__clusters:
                for item in cluster:
                    res = self.assign_item(item, cluster)
                    if items_moved is False:
                        items_moved = res
        return self.__clusters
413674
def cluster_node(self, node_id):
        
        path = '/ws/v1/cluster/nodes/{nodeid}'.format(nodeid=node_id)

        return self.request(path)
298870
def Inventory(cls):
        
        l = ServerSet()
        rs = cls.find()
        for server in rs:
            l.append(server)
        return l
807113
def clusters(self):
        """"""
        if self._resources is None:
            self.__init()
        if "clusters" in self._resources:
            url = self._url + "/clusters"
            return _clusters.Cluster(url=url,
                                     securityHandler=self._securityHandler,
                                     proxy_url=self._proxy_url,
                                     proxy_port=self._proxy_port,
                                     initialize=True)
        else:
            return None
1178531
def load_bucket_inventory(
        client, inventory_bucket, inventory_prefix, versioned, ifilters):
    
    now = datetime.datetime.now()
    key_prefix = "%s/%s" % (inventory_prefix, now.strftime('%Y-%m-'))
    keys = client.list_objects(
        Bucket=inventory_bucket, Prefix=key_prefix).get('Contents', [])
    keys = [k['Key'] for k in keys if k['Key'].endswith('.json')]
    keys.sort()
    if not keys:
        # no manifest delivery
        return None
    latest_manifest = keys[-1]
    manifest = client.get_object(Bucket=inventory_bucket, Key=latest_manifest)
    manifest_data = json.load(manifest['Body'])

    # schema as column name to column index mapping
    schema = dict([(k, i) for i, k in enumerate(
        [n.strip() for n in manifest_data['fileSchema'].split(',')])])

    processor = functools.partial(
        load_manifest_file, client, inventory_bucket,
        schema, versioned, ifilters)
    generators = map(processor, manifest_data.get('files', ()))
    return random_chain(generators)
480737
def inventory(self, modules_inventory=False):
        

        self.c_info = self.get_attributes()
        for m_index, m_portcounts in enumerate(self.c_info['c_portcounts'].split()):
            if int(m_portcounts):
                module = XenaModule(parent=self, index=m_index)
                if modules_inventory:
                    module.inventory()
1220586
def do_start_cluster(self, cluster):
        
        try:
            cluster = api.get_cluster(cluster)
            cluster.start()
            print("Starting Cluster")
        except ApiException:
            print("Cluster not found")
            return None
659711
def _construct_sharded(self):
        """"""

        current_version = self.getMongoDVersion()

        num_mongos = self.args['mongos'] if self.args['mongos'] > 0 else 1
        shard_names = self._get_shard_names(self.args)

        # create shards as stand-alones or replica sets
        nextport = self.args['port'] + num_mongos
        for shard in shard_names:
            if (self.args['single'] and
                    LooseVersion(current_version) >= LooseVersion("3.6.0")):
                errmsg = " \n * In MongoDB 3.6 and above a Shard must be " \
                         "made up of a replica set. Please use --replicaset " \
                         "option when starting a sharded cluster.*"
                raise SystemExit(errmsg)

            elif (self.args['single'] and
                    LooseVersion(current_version) < LooseVersion("3.6.0")):
                self.shard_connection_str.append(
                    self._construct_single(
                        self.dir, nextport, name=shard, extra='--shardsvr'))
                nextport += 1
            elif self.args['replicaset']:
                self.shard_connection_str.append(
                    self._construct_replset(
                        self.dir, nextport, shard,
                        num_nodes=list(range(self.args['nodes'])),
                        arbiter=self.args['arbiter'], extra='--shardsvr'))
                nextport += self.args['nodes']
                if self.args['arbiter']:
                    nextport += 1

        # start up config server(s)
        config_string = []

        # SCCC config servers (MongoDB <3.3.0)
        if not self.args['csrs'] and self.args['config'] >= 3:
            config_names = ['config1', 'config2', 'config3']
        else:
            config_names = ['config']

        # CSRS config servers (MongoDB >=3.1.0)
        if self.args['csrs']:
            config_string.append(self._construct_config(self.dir, nextport,
                                                        "configRepl", True))
        else:
            for name in config_names:
                self._construct_config(self.dir, nextport, name)
                config_string.append('%s:%i' % (self.args['hostname'],
                                                nextport))
                nextport += 1

        # multiple mongos use <datadir>/mongos/ as subdir for log files
        if num_mongos > 1:
            mongosdir = os.path.join(self.dir, 'mongos')
            if not os.path.exists(mongosdir):
                if self.args['verbose']:
                    print("creating directory: %s" % mongosdir)
                os.makedirs(mongosdir)

        # start up mongos, but put them to the front of the port range
        nextport = self.args['port']
        for i in range(num_mongos):
            if num_mongos > 1:
                mongos_logfile = 'mongos/mongos_%i.log' % nextport
            else:
                mongos_logfile = 'mongos.log'
            self._construct_mongos(os.path.join(self.dir, mongos_logfile),
                                   nextport, ','.join(config_string))

            nextport += 1
592810
def add_elasticache_node(self, node, cluster, region):
        '''  '''

        # Only want available nodes unless all_elasticache_nodes is True
        if not self.all_elasticache_nodes and node['CacheNodeStatus'] != 'available':
            return

        # Select the best destination address
        dest = node['Endpoint']['Address']

        if not dest:
            # Skip nodes we cannot address (e.g. private VPC subnet)
            return

        node_id = self.to_safe(cluster['CacheClusterId'] + '_' + node['CacheNodeId'])

        # Add to index
        self.index[dest] = [region, node_id]

        # Inventory: Group by node ID (always a group of 1)
        if self.group_by_instance_id:
            self.inventory[node_id] = [dest]
            if self.nested_groups:
                self.push_group(self.inventory, 'instances', node_id)

        # Inventory: Group by region
        if self.group_by_region:
            self.push(self.inventory, region, dest)
            if self.nested_groups:
                self.push_group(self.inventory, 'regions', region)

        # Inventory: Group by availability zone
        if self.group_by_availability_zone:
            self.push(self.inventory, cluster['PreferredAvailabilityZone'], dest)
            if self.nested_groups:
                if self.group_by_region:
                    self.push_group(self.inventory, region, cluster['PreferredAvailabilityZone'])
                self.push_group(self.inventory, 'zones', cluster['PreferredAvailabilityZone'])

        # Inventory: Group by node type
        if self.group_by_instance_type:
            type_name = self.to_safe('type_' + cluster['CacheNodeType'])
            self.push(self.inventory, type_name, dest)
            if self.nested_groups:
                self.push_group(self.inventory, 'types', type_name)

        # Inventory: Group by VPC (information not available in the current
        # AWS API version for ElastiCache)

        # Inventory: Group by security group
        if self.group_by_security_group:

            # Check for the existence of the 'SecurityGroups' key and also if
            # this key has some value. When the cluster is not placed in a SG
            # the query can return None here and cause an error.
            if 'SecurityGroups' in cluster and cluster['SecurityGroups'] is not None:
                for security_group in cluster['SecurityGroups']:
                    key = self.to_safe("security_group_" + security_group['SecurityGroupId'])
                    self.push(self.inventory, key, dest)
                    if self.nested_groups:
                        self.push_group(self.inventory, 'security_groups', key)

        # Inventory: Group by engine
        if self.group_by_elasticache_engine:
            self.push(self.inventory, self.to_safe("elasticache_" + cluster['Engine']), dest)
            if self.nested_groups:
                self.push_group(self.inventory, 'elasticache_engines', self.to_safe("elasticache_" + cluster['Engine']))

        # Inventory: Group by parameter group (done at cluster level)

        # Inventory: Group by replication group (done at cluster level)

        # Inventory: Group by ElastiCache Cluster
        if self.group_by_elasticache_cluster:
            self.push(self.inventory, self.to_safe("elasticache_cluster_" + cluster['CacheClusterId']), dest)

        # Global Tag: all ElastiCache nodes
        self.push(self.inventory, 'elasticache_nodes', dest)

        host_info = self.get_host_info_dict_from_describe_dict(node)

        if dest in self.inventory["_meta"]["hostvars"]:
            self.inventory["_meta"]["hostvars"][dest].update(host_info)
        else:
            self.inventory["_meta"]["hostvars"][dest] = host_info
577435
def add_to_cluster(self, name, **attrs):
        
        cluster = self.get_cluster(name=name)
        attrs_ = cluster['cluster']
        attrs_.update(**attrs)
645400
def _cluster_by(end_iter, attr1, attr2, cluster_distance):
    
    ClusterInfo = namedtuple("ClusterInfo", ["chroms", "clusters", "lookup"])
    chr_clusters = {}
    chroms = []
    brends_by_id = {}
    for brend in end_iter:
        if not chr_clusters.has_key(brend.chrom1):
            chroms.append(brend.chrom1)
            chr_clusters[brend.chrom1] = ClusterTree(cluster_distance, 1)
        brends_by_id[int(brend.name)] = brend
        chr_clusters[brend.chrom1].insert(getattr(brend, attr1),
                                          getattr(brend, attr2),
                                          int(brend.name))
    return ClusterInfo(chroms, chr_clusters, brends_by_id)
1350842
def create_cluster(cluster_info)
      cluster_info = cluster_info.inject({}) { |v, hv|
        v.merge({"cluster[#{hv.first}]" => hv.last})
      }

      request(
        :expects => 201,
        :method => :post,
        :path => "/#{account_id}/api/clusters",
        :query => cluster_info
      )
    end
254290
public static Cluster getOrCreateCluster(String clusterName,
      CassandraHostConfigurator cassandraHostConfigurator) {
    return createCluster(clusterName, cassandraHostConfigurator, null);
  }
436919
def show(cls, cluster_id_label):
        
        conn = Qubole.agent()
        return conn.get(cls.element_path(cluster_id_label))