'Called periodically.  On every call, try to update the
info_cache\'s network information for another instance by
calling to the network manager.
This is implemented by keeping a cache of uuids of instances
that live on this host.  On each call, we pop one off of a
list, pull the DB record, and try the call to the network API.
If anything errors don\'t fail, as it\'s possible the instance
has been deleted, etc.'

@periodic_task.periodic_task(spacing=CONF.heal_instance_info_cache_interval)
def _heal_instance_info_cache(self, context):

    heal_interval = CONF.heal_instance_info_cache_interval
    if (not heal_interval):
        return
    instance_uuids = getattr(self, '_instance_uuids_to_heal', [])
    instance = None
    LOG.debug('Starting    heal    instance    info    cache')
    if (not instance_uuids):
        LOG.debug('Rebuilding    the    list    of    instances    to    heal')
        db_instances = objects.InstanceList.get_by_host(context, self.host, expected_attrs=[], use_slave=True)
        for inst in db_instances:
            if (inst.vm_state == vm_states.BUILDING):
                LOG.debug('Skipping    network    cache    update    for    instance    because    it    is    Building.', instance=inst)
                continue
            if (inst.task_state == task_states.DELETING):
                LOG.debug('Skipping    network    cache    update    for    instance    because    it    is    being    deleted.', instance=inst)
                continue
            if (not instance):
                instance = inst
            else:
                instance_uuids.append(inst['uuid'])
        self._instance_uuids_to_heal = instance_uuids
    else:
        while instance_uuids:
            try:
                inst = objects.Instance.get_by_uuid(context, instance_uuids.pop(0), expected_attrs=['system_metadata', 'info_cache', 'flavor'], use_slave=True)
            except exception.InstanceNotFound:
                continue
            if (inst.host != self.host):
                LOG.debug('Skipping    network    cache    update    for    instance    because    it    has    been    migrated    to    another    host.', instance=inst)
            elif (inst.task_state == task_states.DELETING):
                LOG.debug('Skipping    network    cache    update    for    instance    because    it    is    being    deleted.', instance=inst)
            else:
                instance = inst
                break
    if instance:
        try:
            self.network_api.get_instance_nw_info(context, instance)
            LOG.debug('Updated    the    network    info_cache    for    instance', instance=instance)
        except exception.InstanceNotFound:
            LOG.debug('Instance    no    longer    exists.    Unable    to    refresh', instance=instance)
            return
        except exception.InstanceInfoCacheNotFound:
            LOG.debug('InstanceInfoCache    no    longer    exists.    Unable    to    refresh', instance=instance)
        except Exception:
            LOG.error('An    error    occurred    while    refreshing    the    network    cache.', instance=instance, exc_info=True)
    else:
        LOG.debug("Didn't    find    any    instances    for    network    info    cache    update.")
