'Terminate an instance on this host.'

@wrap_exception()
@reverts_task_state
@wrap_instance_event(prefix='compute')
@wrap_instance_fault
def terminate_instance(self, context, instance, bdms, reservations):

    @utils.synchronized(instance.uuid)
    def do_terminate_instance(instance, bdms):
        for bdm in list(bdms):
            if (bdm.is_volume and (not bdm.volume_id)):
                LOG.debug('There    are    potentially    stale    BDMs    during    delete,    refreshing    the    BlockDeviceMappingList.', instance=instance)
                bdms = objects.BlockDeviceMappingList.get_by_instance_uuid(context, instance.uuid)
                break
        try:
            self._delete_instance(context, instance, bdms)
        except exception.InstanceNotFound:
            LOG.info('Instance    disappeared    during    terminate', instance=instance)
        except Exception:
            with excutils.save_and_reraise_exception():
                LOG.exception('Setting    instance    vm_state    to    ERROR', instance=instance)
                self._set_instance_obj_error_state(context, instance)
    do_terminate_instance(instance, bdms)
