Recursively destroy and delete a persistent virtual machine, pass True for
    dir's to also delete the directories containing the virtual machine disk
    images - USE WITH EXTREME CAUTION!

    Pass removables=False to avoid deleting cdrom and floppy images. To avoid
    disruption, the default but dangerous value is True. This will be changed
    to the safer False default value in Sodium.

    :param vm_: domain name
    :param dirs: pass True to remove containing directories
    :param removables: pass True to remove removable devices

        .. versionadded:: 2019.2.0
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.purge <domain> removables=False

def purge(vm_, dirs=False, removables=None, **kwargs):
    '''
    Recursively destroy and delete a persistent virtual machine, pass True for
    dir's to also delete the directories containing the virtual machine disk
    images - USE WITH EXTREME CAUTION!

    Pass removables=False to avoid deleting cdrom and floppy images. To avoid
    disruption, the default but dangerous value is True. This will be changed
    to the safer False default value in Sodium.

    :param vm_: domain name
    :param dirs: pass True to remove containing directories
    :param removables: pass True to remove removable devices

        .. versionadded:: 2019.2.0
    :param connection: libvirt connection URI, overriding defaults

        .. versionadded:: 2019.2.0
    :param username: username to connect with, overriding defaults

        .. versionadded:: 2019.2.0
    :param password: password to connect with, overriding defaults

        .. versionadded:: 2019.2.0

    CLI Example:

    .. code-block:: bash

        salt '*' virt.purge <domain> removables=False
    '''
    conn = __get_conn(**kwargs)
    dom = _get_domain(conn, vm_)
    disks = _get_disks(dom)
    if removables is None:
        salt.utils.versions.warn_until(
            'Sodium',
            'removables argument default value is True, but will be changed '
            'to False by default in {version}. Please set to True to maintain '
            'the current behavior in the future.'
        )
        removables = True
    if VIRT_STATE_NAME_MAP.get(dom.info()[0], 'unknown') != 'shutdown' and dom.destroy() != 0:
        return False
    directories = set()
    for disk in disks:
        if not removables and disks[disk]['type'] in ['cdrom', 'floppy']:
            continue
        elif disks[disk].get('zfs', False):
            # TODO create solution for 'dataset is busy'
            time.sleep(3)
            fs_name = disks[disk]['file'][len('/dev/zvol/'):]
            log.info('Destroying VM ZFS volume %s', fs_name)
            __salt__['zfs.destroy'](
                    name=fs_name,
                    force=True)
        else:
            os.remove(disks[disk]['file'])
            directories.add(os.path.dirname(disks[disk]['file']))
    if dirs:
        for dir_ in directories:
            shutil.rmtree(dir_)
    if getattr(libvirt, 'VIR_DOMAIN_UNDEFINE_NVRAM', False):
        # This one is only in 1.2.8+
        try:
            dom.undefineFlags(libvirt.VIR_DOMAIN_UNDEFINE_NVRAM)
        except libvirt.libvirtError:
            dom.undefine()
    else:
        dom.undefine()
    conn.close()
    return True