'Returns a list of HostState objects that match the required
scheduling constraints for the request spec object and have been sorted
according to the weighers.'

def _get_sorted_hosts(self, spec_obj, host_states, index):

    filtered_hosts = self.host_manager.get_filtered_hosts(host_states, spec_obj, index)
    LOG.debug('Filtered    %(hosts)s', {'hosts': filtered_hosts})
    if (not filtered_hosts):
        return []
    weighed_hosts = self.host_manager.get_weighed_hosts(filtered_hosts, spec_obj)
    weighed_hosts = [h.obj for h in weighed_hosts]
    LOG.debug('Weighed    %(hosts)s', {'hosts': weighed_hosts})
    host_subset_size = CONF.filter_scheduler.host_subset_size
    if (host_subset_size < len(weighed_hosts)):
        weighed_subset = weighed_hosts[0:host_subset_size]
    else:
        weighed_subset = weighed_hosts
    chosen_host = random.choice(weighed_subset)
    weighed_hosts.remove(chosen_host)
    return ([chosen_host] + weighed_hosts)
