'Creates the initial view of instances for all hosts.
As this initial population of instance information may take some time,
we don\'t wish to block the scheduler\'s startup while this completes.
The async method allows us to simply mock out the _init_instance_info()
method in tests.
:param compute_nodes: a list of nodes to populate instances info for
if is None, compute_nodes will be looked up in database'

def _init_instance_info(self, computes_by_cell=None):

    def _async_init_instance_info(computes_by_cell):
        context = context_module.RequestContext()
        self._load_cells(context)
        LOG.debug('START:_async_init_instance_info')
        self._instance_info = {}
        count = 0
        if (not computes_by_cell):
            computes_by_cell = {}
            for cell in self.cells:
                with context_module.target_cell(context, cell) as cctxt:
                    cell_cns = objects.ComputeNodeList.get_all(cctxt).objects
                    computes_by_cell[cell] = cell_cns
                    count += len(cell_cns)
        LOG.debug('Total    number    of    compute    nodes:    %s', count)
        for (cell, compute_nodes) in computes_by_cell.items():
            batch_size = 10
            start_node = 0
            end_node = batch_size
            while (start_node <= len(compute_nodes)):
                curr_nodes = compute_nodes[start_node:end_node]
                start_node += batch_size
                end_node += batch_size
                filters = {'host': [curr_node.host for curr_node in curr_nodes], 'deleted': False}
                with context_module.target_cell(context, cell) as cctxt:
                    result = objects.InstanceList.get_by_filters(cctxt.elevated(), filters)
                instances = result.objects
                LOG.debug('Adding    %s    instances    for    hosts    %s-%s', len(instances), start_node, end_node)
                for instance in instances:
                    host = instance.host
                    if (host not in self._instance_info):
                        self._instance_info[host] = {'instances': {}, 'updated': False}
                    inst_dict = self._instance_info[host]
                    inst_dict['instances'][instance.uuid] = instance
                time.sleep(0)
            LOG.debug('END:_async_init_instance_info')
    utils.spawn_n(_async_init_instance_info, computes_by_cell)
