'Returns a list of hosts that meet the required specs, ordered by
their fitness.
These hosts will have already had their resources claimed in Placement.
:param context: The RequestContext object
:param spec_obj: The RequestSpec object
:param instance_uuids: List of instance UUIDs to place or move.
:param alloc_reqs_by_rp_uuid: Optional dict, keyed by resource provider
UUID, of the allocation requests that may
be used to claim resources against
matched hosts. If None, indicates either
the placement API wasn\'t reachable or
that there were no allocation requests
returned by the placement API. If the
latter, the provider_summaries will be an
empty dict, not None.
:param provider_summaries: Optional dict, keyed by resource provider
UUID, of information that will be used by
the filters/weighers in selecting matching
hosts for a request. If None, indicates that
the scheduler driver should grab all compute
node information locally and that the
Placement API is not used. If an empty dict,
indicates the Placement API returned no
potential matches for the requested
resources.'

def _schedule(self, context, spec_obj, instance_uuids, alloc_reqs_by_rp_uuid, provider_summaries):

    elevated = context.elevated()
    hosts = self._get_all_host_states(elevated, spec_obj, provider_summaries)
    claimed_instance_uuids = []
    selected_hosts = []
    num_instances = (len(instance_uuids) if instance_uuids else spec_obj.num_instances)
    for num in range(num_instances):
        hosts = self._get_sorted_hosts(spec_obj, hosts, num)
        if (not hosts):
            self._cleanup_allocations(claimed_instance_uuids)
            break
        if ((instance_uuids is None) or (not self.USES_ALLOCATION_CANDIDATES) or (alloc_reqs_by_rp_uuid is None)):
            claimed_host = hosts[0]
        else:
            instance_uuid = instance_uuids[num]
            claimed_host = None
            for host in hosts:
                cn_uuid = host.uuid
                if (cn_uuid not in alloc_reqs_by_rp_uuid):
                    LOG.debug("Found    host    state    %s    that    wasn't    in    allocation    requests.    Skipping.", cn_uuid)
                    continue
                alloc_reqs = alloc_reqs_by_rp_uuid[cn_uuid]
                if self._claim_resources(elevated, spec_obj, instance_uuid, alloc_reqs):
                    claimed_host = host
                    break
            if (claimed_host is None):
                LOG.debug('Unable    to    successfully    claim    against    any    host.')
                self._cleanup_allocations(claimed_instance_uuids)
                return []
            claimed_instance_uuids.append(instance_uuid)
        LOG.debug('Selected    host:    %(host)s', {'host': claimed_host})
        selected_hosts.append(claimed_host)
        claimed_host.consume_from_request(spec_obj)
        if (spec_obj.instance_group is not None):
            spec_obj.instance_group.hosts.append(claimed_host.host)
            spec_obj.instance_group.obj_reset_changes(['hosts'])
    return selected_hosts
