def MaintainInstanceList(self, instances):
    idict = self._data["instance"]

    # First, delete obsolete instances
    obsolete_instances = set(idict).difference(instances)
    for inst in obsolete_instances:
      logging.debug("Forgetting obsolete instance %s", inst)
      idict.pop(inst, None)

    # Second, delete expired records
    earliest = time.time() - RETRY_EXPIRATION
    expired_instances = [i for i in idict
                         if idict[i].get(KEY_RESTART_WHEN, 0) < earliest]
    for inst in expired_instances:
      logging.debug("Expiring record for instance %s", inst)
      idict.pop(inst, None)
Perform maintenance on the recorded instances.
dataset/ETHPy150Open ganeti/ganeti/lib/watcher/state.py/WatcherState.MaintainInstanceList