Delete the subvolume(s) from the filesystem

    The user can remove one single subvolume (name) or multiple of
    then at the same time (names). One of the two parameters needs to
    specified.

    Please, refer to the documentation to understand the implication
    on the transactions, and when the subvolume is really deleted.

    Return True if the subvolume is deleted, False is the subvolume
    was already missing.

    name
        Name of the subvolume to remove

    names
        List of names of subvolumes to remove

    commit
        * 'after': Wait for transaction commit at the end
        * 'each': Wait for transaction commit after each delete

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_delete /var/volumes/tmp
        salt '*' btrfs.subvolume_delete /var/volumes/tmp commit=after

def subvolume_delete(name=None, names=None, commit=None):
    '''
    Delete the subvolume(s) from the filesystem

    The user can remove one single subvolume (name) or multiple of
    then at the same time (names). One of the two parameters needs to
    specified.

    Please, refer to the documentation to understand the implication
    on the transactions, and when the subvolume is really deleted.

    Return True if the subvolume is deleted, False is the subvolume
    was already missing.

    name
        Name of the subvolume to remove

    names
        List of names of subvolumes to remove

    commit
        * 'after': Wait for transaction commit at the end
        * 'each': Wait for transaction commit after each delete

    CLI Example:

    .. code-block:: bash

        salt '*' btrfs.subvolume_delete /var/volumes/tmp
        salt '*' btrfs.subvolume_delete /var/volumes/tmp commit=after

    '''
    if not name and not (names and type(names) is list):
        raise CommandExecutionError('Provide a value for the name parameter')

    if commit and commit not in ('after', 'each'):
        raise CommandExecutionError('Value for commit not recognized')

    # Filter the names and take the ones that are still there
    names = [n for n in itertools.chain([name], names or [])
             if n and subvolume_exists(n)]

    # If the subvolumes are gone, we are done
    if not names:
        return False

    cmd = ['btrfs', 'subvolume', 'delete']
    if commit == 'after':
        cmd.append('--commit-after')
    elif commit == 'each':
        cmd.append('--commit-each')
    cmd.extend(names)

    res = __salt__['cmd.run_all'](cmd)
    salt.utils.fsutils._verify_run(res)
    return True