Replaces ``old_device`` with ``new_device``

    .. note::

        This is equivalent to attaching ``new_device``,
        waiting for it to resilver, and then detaching ``old_device``.

        The size of ``new_device`` must be greater than or equal to the minimum
        size of all the devices in a mirror or raidz configuration.

    zpool : string
        Name of storage pool

    old_device : string
        Old device to replace

    new_device : string
        Optional new device

    force : boolean
        Forces use of new_device, even if its appears to be in use.

    CLI Example:

    .. code-block:: bash

        salt '*' zpool.replace myzpool /path/to/vdev1 /path/to/vdev2

def replace(zpool, old_device, new_device=None, force=False):
    '''
    Replaces ``old_device`` with ``new_device``

    .. note::

        This is equivalent to attaching ``new_device``,
        waiting for it to resilver, and then detaching ``old_device``.

        The size of ``new_device`` must be greater than or equal to the minimum
        size of all the devices in a mirror or raidz configuration.

    zpool : string
        Name of storage pool

    old_device : string
        Old device to replace

    new_device : string
        Optional new device

    force : boolean
        Forces use of new_device, even if its appears to be in use.

    CLI Example:

    .. code-block:: bash

        salt '*' zpool.replace myzpool /path/to/vdev1 /path/to/vdev2

    '''
    ## Configure pool
    # NOTE: initialize the defaults
    flags = []
    target = []

    # NOTE: set extra config
    if force:
        flags.append('-f')

    # NOTE: append the pool name and specifications
    target.append(zpool)
    target.append(old_device)
    if new_device:
        target.append(new_device)

    ## Replace device
    res = __salt__['cmd.run_all'](
        __utils__['zfs.zpool_command'](
            command='replace',
            flags=flags,
            target=target,
        ),
        python_shell=False,
    )

    ret = __utils__['zfs.parse_command_result'](res, 'replaced')
    if ret['replaced']:
        ## NOTE: lookup zpool status for vdev config
        ret['vdevs'] = _clean_vdev_config(
            __salt__['zpool.status'](zpool=zpool)[zpool]['config'][zpool],
        )

    return ret