Determine what the most resource free host is based on the given data
356584
def _determine_host(data, omit=''):
    '''
    
    '''
    # This is just checking for the host with the most free ram, this needs
    # to be much more complicated.
    host = ''
    bestmem = 0
    for hv_, comps in six.iteritems(data):
        if hv_ == omit:
            continue
        if not isinstance(comps, dict):
            continue
        if comps.get('freemem', 0) > bestmem:
            bestmem = comps['freemem']
            host = hv_
    return host
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
104654
def cli(env, sortby, cpu, columns, datacenter, name, memory, disk, tag):
    """"""
    mgr = SoftLayer.DedicatedHostManager(env.client)
    hosts = mgr.list_instances(cpus=cpu,
                               datacenter=datacenter,
                               hostname=name,
                               memory=memory,
                               disk=disk,
                               tags=tag,
                               mask=columns.mask())

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

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

    env.fout(table)
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
1217016
def resources_availability(self):
        """"""
        # Flatten the list.
        availabilities = list(
            chain(
                *[org.check_availability() for org in self.organizations]
            )
        )
        # Filter out the unknown
        availabilities = [a for a in availabilities if type(a) is bool]
        if availabilities:
            # Trick will work because it's a sum() of booleans.
            return round(100. * sum(availabilities) / len(availabilities), 2)
        # if nothing is unavailable, everything is considered OK
        return 100
716187
def _choose_host(self):
        
        # If a host hasn't been chosen yet or there is only one host
        if len(self._hosts) == 1 or self._http_host is None:
            self._http_host = self._hosts[0]
        else:  # There is a list of hosts to choose from, pick a random one
            choice = self._http_host
            while choice == self._http_host:
                choice = random.choice(self._hosts)
            self._http_host = choice
            self._notify(logging.INFO,
                         consts.LOG_MSG_NEW_SERVER % self._http_host)

        # Set the validation and the REST URLs
        secure = 's' if self._use_ssl else ''
        self._connection_validation_url = \
            consts.CONN_VALIDATION_URL_TEMPLATE.format(host=self._http_host,
                                                       secure=secure)
        self._rest_url = consts.REST_URL_TEMPLATE.format(host=self._http_host,
                                                         token=self._token,
                                                         secure=secure)
        self._token_verification_url = \
            consts.TOKEN_VERIFICATION_URL_TEMPLATE.format(host=self._http_host,
                                                          token=self._token,
                                                          secure=secure)
419483
def all_host_infos():
    '''
        
    '''
    output = []
    output.append(["Operating system", os()])
    output.append(["CPUID information", cpu()])
    output.append(["CC information", compiler()])
    output.append(["JDK information", from_cmd("java -version")])
    output.append(["MPI information", from_cmd("mpirun -version")])
    output.append(["Scala information", from_cmd("scala -version")])
    output.append(["OpenCL headers", from_cmd(
        "find /usr/include|grep opencl.h")])
    output.append(["OpenCL libraries", from_cmd(
        "find /usr/lib/ -iname '*opencl*'")])
    output.append(["NVidia SMI", from_cmd("nvidia-smi -q")])
    output.append(["OpenCL Details", opencl()])
    return output
586462
def ip_host(value, options=None, version=None):
    '''
    
    '''
    ipaddr_filter_out = _filter_ipaddr(value, options=options, version=version)
    if not ipaddr_filter_out:
        return
    if not isinstance(value, (list, tuple, types.GeneratorType)):
        return six.text_type(ipaddress.ip_interface(ipaddr_filter_out[0]))
    return [six.text_type(ipaddress.ip_interface(ip_a)) for ip_a in ipaddr_filter_out]
830927
public ResourceRequestInfo getPendingRequestForAny(
    String host, ResourceType type) {
    Context c = getContext(type);
    for (ResourceRequestInfo req: c.anyHostRequests) {
      Set<String> excluded = req.getExcludeHosts();
      if (!excluded.contains(host)) {
        return req;
      }
    }
    return null;
  }
580766
def check_resources(self, number):
    ''''''
    if not current_app.config.get('LINKCHECKING_ENABLED'):
        log.error('Link checking is disabled.')
        return

    base_pipeline = [
        {'$match': {'resources': {'$gt': []}}},
        {'$project': {'resources._id': True,
                      'resources.extras.check:date': True}},
        {'$unwind': '$resources'},
    ]
    # unchecked resources
    pipeline = base_pipeline + [
        {'$match': {'resources.extras.check:date': {'$eq': None}}},
        {'$limit': number}
    ]
    resources = list(Dataset.objects.aggregate(*pipeline))
    # not recently checked resources
    slots_left = number - len(resources)
    if slots_left:
        pipeline = base_pipeline + [
            {'$match': {'resources.extras.check:date': {'$ne': None}}},
            {'$sort': {'resources.extras.check:date': 1}},
            {'$limit': slots_left}
        ]
        resources += list(Dataset.objects.aggregate(*pipeline))

    nb_resources = len(resources)
    log.info('Checking %s resources...', nb_resources)
    for idx, dataset_resource in enumerate(resources):
        dataset_obj = Dataset.objects.get(id=dataset_resource['_id'])
        resource_id = dataset_resource['resources']['_id']
        rid = uuid.UUID(resource_id)
        resource_obj = get_by(dataset_obj.resources, 'id', rid)
        log.info('Checking resource %s (%s/%s)',
                 resource_id, idx + 1, nb_resources)
        if resource_obj.need_check():
            check_resource(resource_obj)
        else:
            log.info("--> Skipping this resource, cache is fresh enough.")
    log.info('Done.')
514128
public static String getHost(TextArrayWritable hosts) throws IOException {
        String [] hostStrings = hosts.toStrings();
        if(hostStrings == null || hostStrings.length==0) 
            throw new IOException("Number of forests is 0: "
                + "check forests in database");
        int count = hostStrings.length;
        int position = (int)(Math.random() * count);
        return hostStrings[position];
    }
212455
def _list_available_hosts(self, *args):
        '''  '''

        return [ h for h in self.inventory.list_hosts(*args) if (h not in self.stats.failures) and (h not in self.stats.dark)]
602264
private void findHostname() {
    String startupInfo = Environment.runCommand(
        "grep --max-count=1 STARTUP_MSG:\\s*host " + file.getName()).toString();
    Pattern pattern = Pattern.compile("\\s+(\\w+/.+)\\s+");
    Matcher matcher = pattern.matcher(startupInfo);
    if (matcher.find(0)) {
      hostname = matcher.group(1).split("/")[0];
      ips = new String[1];
      ips[0] = matcher.group(1).split("/")[1];
    }
  }
769288
def host_info(host=None):
    '''
    
    '''
    data = query(host, quiet=True)
    for id_ in data:
        if 'vm_info' in data[id_]:
            data[id_].pop('vm_info')
    __jid_event__.fire_event({'data': data, 'outputter': 'nested'}, 'progress')
    return data
468645
def getWorkerQte(hosts):
    """"""
    if "SLURM_NTASKS" in os.environ:
        return int(os.environ["SLURM_NTASKS"])
    elif "PBS_NP" in os.environ:
        return int(os.environ["PBS_NP"])
    elif "NSLOTS" in os.environ:
        return int(os.environ["NSLOTS"])
    else:
        return sum(host[1] for host in hosts)
965654
def get_host(self, host):
        '''  '''

        if len(self.index) == 0:
            # Need to load index from cache
            self.load_index_from_cache()

        if not host in self.index:
            # try updating the cache
            self.do_api_calls_update_cache()
            if not host in self.index:
                # host might not exist anymore
                return {}

        (region, instance_id) = self.index[host]

        instance = self.get_instance(region, instance_id)
        return self.get_host_info_dict_from_instance(instance)
420226
def _get_total_hosts_not_monitored(self):
        
        return sum(1 for h in self.hosts if not h.active_checks_enabled and
                   not h.passive_checks_enabled)