The etcd watcher, called to invoke the watch command.
    When called, execute a etcd function based on a watch call requisite.

    .. note::
        This state exists to support special handling of the ``watch``
        :ref:`requisite <requisites>`. It should not be called directly.

        Parameters for this function should be set by the state being triggered.

def mod_watch(name, **kwargs):
    '''
    The etcd watcher, called to invoke the watch command.
    When called, execute a etcd function based on a watch call requisite.

    .. note::
        This state exists to support special handling of the ``watch``
        :ref:`requisite <requisites>`. It should not be called directly.

        Parameters for this function should be set by the state being triggered.
    '''

    # Watch to set etcd key
    if kwargs.get('sfun') in ['wait_set_key', 'wait_set']:
        return set_(
            name,
            kwargs.get('value'),
            kwargs.get('profile'))

    # Watch to rm etcd key
    if kwargs.get('sfun') in ['wait_rm_key', 'wait_rm']:
        return rm(
            name,
            kwargs.get('profile'))

    return {
        'name': name,
        'changes': {},
        'comment': 'etcd.{0[sfun]} does not work with the watch requisite, '
                   'please use etcd.wait_set or etcd.wait_rm'.format(kwargs),
        'result': False
    }