Format a filesystem onto a device

    .. versionadded:: 2016.11.0

    device
        The device in which to create the new filesystem

    fs_type
        The type of filesystem to create

    inode_size
        Size of the inodes

        This option is only enabled for ext and xfs filesystems

    lazy_itable_init
        If enabled and the uninit_bg feature is enabled, the inode table will
        not be fully initialized by mke2fs.  This speeds up filesystem
        initialization noticeably, but it requires the kernel to finish
        initializing the filesystem  in  the  background  when  the filesystem
        is first mounted.  If the option value is omitted, it defaults to 1 to
        enable lazy inode table zeroing.

        This option is only enabled for ext filesystems

    fat
        FAT size option. Can be 12, 16 or 32, and can only be used on
        fat or vfat filesystems.

    force
        Force mke2fs to create a filesystem, even if the specified device is
        not a partition on a block special device. This option is only enabled
        for ext and xfs filesystems

        This option is dangerous, use it with caution.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.format /dev/sdX1

def format_(device,
            fs_type='ext4',
            inode_size=None,
            lazy_itable_init=None,
            fat=None,
            force=False):
    '''
    Format a filesystem onto a device

    .. versionadded:: 2016.11.0

    device
        The device in which to create the new filesystem

    fs_type
        The type of filesystem to create

    inode_size
        Size of the inodes

        This option is only enabled for ext and xfs filesystems

    lazy_itable_init
        If enabled and the uninit_bg feature is enabled, the inode table will
        not be fully initialized by mke2fs.  This speeds up filesystem
        initialization noticeably, but it requires the kernel to finish
        initializing the filesystem  in  the  background  when  the filesystem
        is first mounted.  If the option value is omitted, it defaults to 1 to
        enable lazy inode table zeroing.

        This option is only enabled for ext filesystems

    fat
        FAT size option. Can be 12, 16 or 32, and can only be used on
        fat or vfat filesystems.

    force
        Force mke2fs to create a filesystem, even if the specified device is
        not a partition on a block special device. This option is only enabled
        for ext and xfs filesystems

        This option is dangerous, use it with caution.

    CLI Example:

    .. code-block:: bash

        salt '*' disk.format /dev/sdX1
    '''
    cmd = ['mkfs', '-t', six.text_type(fs_type)]
    if inode_size is not None:
        if fs_type[:3] == 'ext':
            cmd.extend(['-i', six.text_type(inode_size)])
        elif fs_type == 'xfs':
            cmd.extend(['-i', 'size={0}'.format(inode_size)])
    if lazy_itable_init is not None:
        if fs_type[:3] == 'ext':
            cmd.extend(['-E', 'lazy_itable_init={0}'.format(lazy_itable_init)])
    if fat is not None and fat in (12, 16, 32):
        if fs_type[-3:] == 'fat':
            cmd.extend(['-F', fat])
    if force:
        if fs_type[:3] == 'ext':
            cmd.append('-F')
        elif fs_type == 'xfs':
            cmd.append('-f')
    cmd.append(six.text_type(device))

    mkfs_success = __salt__['cmd.retcode'](cmd, ignore_retcode=True) == 0
    sync_success = __salt__['cmd.retcode']('sync', ignore_retcode=True) == 0

    return all([mkfs_success, sync_success])