get hosts, applications, and other cluster stuff
763388
function(req, res, next) {
        async.parallel({
            applications: (fn) => {
                const spy = { stash: {} };
                applications.get(req, spy, () => {
                    if(spy.stash.code !== 200) {
                        return fn(new Error('Error getting applications.'));
                    }

                    return fn(null, spy.stash.body);
                });
            },
            hosts: (fn) => {
                const spy = { stash: {} };
                hosts.get(req, spy, () => {
                    if(spy.stash.code !== 200) {
                        return fn(new Error('Error getting hosts.'));
                    }

                    return fn(null, spy.stash.body);
                });
            }
        }, (err, results) => {
            if(err) {
                res.stash.code = 500;
                return next();
            }

            res.stash.body = {
                applications: results.applications,
                hosts: results.hosts
            };
            res.stash.code = 200;
            return next();
        });
    }
429218
def get_hosts(self):
        
        limited_hosts = {}
        if self.limit is not None:
            # Find hosts and groups of hosts to include
            for include in self.limit['include']:
                # Include whole group
                for hostname in self.hosts_in_group(include):
                    limited_hosts[hostname] = self.hosts[hostname]
                # Include individual host
                if include in self.hosts:
                    limited_hosts[include] = self.hosts[include]
            # Find hosts and groups of hosts to exclude
            for exclude in self.limit["exclude"]:
                # Exclude whole group
                for hostname in self.hosts_in_group(exclude):
                    if hostname in limited_hosts:
                        limited_hosts.pop(hostname)
                # Exclude individual host
                if exclude in limited_hosts:
                    limited_hosts.pop(exclude)

            return limited_hosts
        else:
            # Return all hosts
            return self.hosts
1019699
public Collection<ApplicationHost> list(long applicationId, List<String> queryParams)
    {
        return HTTP.GET(String.format("/v2/applications/%d/hosts.json", applicationId), null, queryParams, APPLICATION_HOSTS).get();
    }
824490
def gather_data(registry):
    """"""

    # Get the host name of the machine
    host = socket.gethostname()

    # Create our collectors
    ram_metric = Gauge("memory_usage_bytes", "Memory usage in bytes.",
                       {'host': host})
    cpu_metric = Gauge("cpu_usage_percent", "CPU usage percent.",
                       {'host': host})

    # register the metric collectors
    registry.register(ram_metric)
    registry.register(cpu_metric)

    # Start gathering metrics every second
    while True:
        time.sleep(1)

        # Add ram metrics
        ram = psutil.virtual_memory()
        swap = psutil.swap_memory()

        ram_metric.set({'type': "virtual", }, ram.used)
        ram_metric.set({'type': "virtual", 'status': "cached"}, ram.cached)
        ram_metric.set({'type': "swap"}, swap.used)

        # Add cpu metrics
        for c, p in enumerate(psutil.cpu_percent(interval=1, percpu=True)):
            cpu_metric.set({'core': c}, p)
800495
def getHostOffsets(self, hosts):
        
        info_dict = {}
        output = util.exec_command([ntpdateCmd, '-u', '-q'] + list(hosts))
        for line in output.splitlines():
            mobj = re.match('server\s+(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}),'
                            '\s*stratum\s+(\d),.*offset\s+([\d\.-]+),'
                            '.*delay\s+([\d\.]+)\s*$', line)
            if mobj:
                host_dict = {}
                host = mobj.group(1)
                host_dict['stratum'] = int(mobj.group(2))
                host_dict['delay'] = float(mobj.group(4))
                host_dict['offset'] = float(mobj.group(3))
                info_dict[host] = host_dict
        return info_dict
521742
def _get_host_disks(host_reference):
    '''
    
    '''
    storage_system = host_reference.configManager.storageSystem
    disks = storage_system.storageDeviceInfo.scsiLun
    ssds = []
    non_ssds = []

    for disk in disks:
        try:
            has_ssd_attr = disk.ssd
        except AttributeError:
            has_ssd_attr = False
        if has_ssd_attr:
            ssds.append(disk)
        else:
            non_ssds.append(disk)

    return {'SSDs': ssds, 'Non-SSDs': non_ssds}
305033
def get_services(root, hosts_map, view=None):
  ''' 
  '''
  services_list = []
  mgmt_service = root.get_cloudera_manager().get_service()
  services_list.append({"hostname": CM_DUMMY_HOST,
                        "name": mgmt_service.name,
                        "display_name": "CM Managed Service: %s" % (mgmt_service.name,),
                        "status": get_status(mgmt_service),
                        "url": mgmt_service.serviceUrl,
                        "health_summary": mgmt_service.healthSummary})
  for cm_role in root.get_cloudera_manager().get_service().get_all_roles(view):
    services_list.append({"hostname": hosts_map[cm_role.hostRef.hostId]["hostname"],
                          "name": cm_role.name,
                          "display_name": "CM Management Service: %s" % (cm_role.name,),
                          "status": get_status(cm_role),
                          "url": cm_role.roleUrl,
                          "health_summary": cm_role.healthSummary})
  for cm_host in root.get_all_hosts(view):
    services_list.append({"hostname": hosts_map[cm_host.hostId]["hostname"],
                          "name": "cm-host-%s" % (cm_host.hostname,),
                          "display_name": "CM Managed Host: %s" % (cm_host.hostname,),
                          "status": get_status(cm_host),
                          "url": cm_host.hostUrl,
                          "health_summary": cm_host.healthSummary})
  for cluster in root.get_all_clusters(view):
    for service in cluster.get_all_services(view):
      services_list.append({"hostname": cluster.name,
                            "name": service.name,
                            "display_name": "CM Managed Service: %s" % (service.name,),
                            "status": get_status(service),
                            "url": service.serviceUrl,
                            "health_summary": service.healthSummary})
      for role in service.get_all_roles(view):
        services_list.append({"hostname": hosts_map[role.hostRef.hostId]["hostname"],
                              "name": role.name,
                              "display_name": "%s:%s" % (cluster.name, role.name,),
                              "status": get_status(role),
                              "url": role.roleUrl,
                              "health_summary": role.healthSummary})
  return services_list
1011032
def get_cluster_nodes(self):
        
        if not hasattr(self, '_cluster_nodes_cache'):
            server, port = self._servers[0].split(':')
            try:
                self._cluster_nodes_cache = (
                    get_cluster_info(server, port,
                                     self._ignore_cluster_errors)['nodes'])
            except (socket.gaierror, socket.timeout) as err:
                raise Exception('Cannot connect to cluster {0} ({1})'.format(
                    self._servers[0], err
                ))
        return self._cluster_nodes_cache
1158771
def cli(env, identifier, sortby, cpu, domain, hostname, memory, tag, columns):
    """"""

    mgr = SoftLayer.DedicatedHostManager(env.client)
    guests = mgr.list_guests(host_id=identifier,
                             cpus=cpu,
                             hostname=hostname,
                             domain=domain,
                             memory=memory,
                             tags=tag,
                             mask=columns.mask())

    table = formatting.Table(columns.columns)
    table.sortby = sortby

    for guest in guests:
        table.add_row([value or formatting.blank()
                       for value in columns.row(guest)])

    env.fout(table)
564858
def getHostsFromPBS():
    """"""
    # See above comment about Counter
    with open(os.environ["PBS_NODEFILE"], 'r') as hosts:
        hostlist = groupTogether(hosts.read().split())
        retVal = []
        for key, group in groupby(hostlist):
            retVal.append((key, len(list(group))))
        return retVal
791480
def _get_ids_from_hostname(self, hostname):
        """"""
        results = self.list_instances(hostname=hostname, mask="id")
        return [result['id'] for result in results]
665074
public String getHostsUsed() {
		String hostsUsed= new String();
		StringBuilder strBldr = new StringBuilder();
	
		Set<Entry<String,CassandraHost>> se= m_hostsUsed.entrySet();
		
		for (Entry<String, CassandraHost> entry : se) 
		{
			strBldr.append(entry.getValue().toString());
			strBldr.append(';');	
		}
		if(se.size()>0 && strBldr.length()>0)
		{
			hostsUsed=strBldr.substring(0, strBldr.length()-1);
		}
		return hostsUsed;
	}
168821
def get_nodes(cluster):
    
    gk = get_api_client()
    site = get_cluster_site(cluster)
    return gk.sites[site].clusters[cluster].nodes.list()
1208242
def get_servers():
    '''
    
    '''
    ret = list()

    with salt.utils.winapi.Com():
        try:
            connection = wmi.WMI(namespace=_WMI_NAMESPACE)
            objs = connection.IIsSmtpServerSetting()

            for obj in objs:
                ret.append(six.text_type(obj.Name))
        except wmi.x_wmi as error:
            _LOG.error('Encountered WMI error: %s', error.com_error)
        except (AttributeError, IndexError) as error:
            _LOG.error('Error getting IIsSmtpServerSetting: %s', error)

    _LOG.debug('Found SMTP servers: %s', ret)
    return ret
277025
def get_cluster_name(self):
        
        return self._get(
            url=self.url + '/api/cluster-name',
            headers=self.headers,
            auth=self.auth
        )
732226
def get_all(root=None):
    '''
    
    '''
    ret = _get_systemd_services(root)
    ret.update(set(_get_sysv_services(root, systemd_services=ret)))
    return sorted(ret)
1339870
def _get_running_apps(self, instance, requests_config):
        
        tags = instance.get('tags', [])
        if tags is None:
            tags = []
        master_address = self._get_master_address(instance)
        # Get the cluster name from the instance configuration
        cluster_name = instance.get('cluster_name')
        if cluster_name is None:
            raise Exception('The cluster_name must be specified in the instance configuration')
        tags.append('cluster_name:%s' % cluster_name)
        tags = list(set(tags))
        # Determine the cluster mode
        cluster_mode = instance.get(SPARK_CLUSTER_MODE)
        if cluster_mode is None:
            self.log.warning(
                'The value for `spark_cluster_mode` was not set in the configuration. '
                'Defaulting to "%s"' % SPARK_YARN_MODE
            )
            cluster_mode = SPARK_YARN_MODE

        if cluster_mode == SPARK_STANDALONE_MODE:
            # check for PRE-20
            pre20 = is_affirmative(instance.get(SPARK_PRE_20_MODE, False))
            return self._standalone_init(master_address, pre20, requests_config, tags)

        elif cluster_mode == SPARK_MESOS_MODE:
            running_apps = self._mesos_init(instance, master_address, requests_config, tags)
            return self._get_spark_app_ids(running_apps, requests_config, tags)

        elif cluster_mode == SPARK_YARN_MODE:
            running_apps = self._yarn_init(master_address, requests_config, tags)
            return self._get_spark_app_ids(running_apps, requests_config, tags)

        else:
            raise Exception('Invalid setting for %s. Received %s.' % (SPARK_CLUSTER_MODE, cluster_mode))