def destroy_container(target, instance, nbd=False):
    """Destroy the container once it terminates.

    It will umount the container that is mounted, try to find the loopback
    device associated with the container and delete it.

    LXC does not support qcow2 images yet.
    """
    out, err = utils.execute('mount', run_as_root=True)
    for loop in out.splitlines():
        if instance['name'] in loop:
            device = loop.split()[0]

    try:
        container_dir = '%s/rootfs' % target
        utils.execute('umount', container_dir, run_as_root=True)
        _unlink_device(device, nbd)
    except Exception, exn:
        LOG.exception(_('Failed to remove container: %s'), exn)
dataset/ETHPy150Open nii-cloud/dodai-compute/nova/virt/disk.py/destroy_container/original