<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:

def agent_maintenance(consul_url=None, token=None, **kwargs):
    '''
    Manages node maintenance mode

    :param consul_url: The Consul server URL.
    :param enable: The enable flag is required.
                   Acceptable values are either true
                   (to enter maintenance mode) or
                   false (to resume normal operation).
    :param reason: If provided, its value should be a
                   text string explaining the reason for
                   placing the node into maintenance mode.
    :return: Boolean and message indicating success or failure.

    CLI Example:

    .. code-block:: bash

        salt '*' consul.agent_maintenance enable='False' reason='Upgrade in progress'

    '''
    ret = {}
    query_params = {}
    if not consul_url:
        consul_url = _get_config()
        if not consul_url:
            log.error('No Consul URL found.')
            ret['message'] = 'No Consul URL found.'
            ret['res'] = False
            return ret

    if 'enable' in kwargs:
        query_params['enable'] = kwargs['enable']
    else:
        ret['message'] = 'Required parameter "enable" is missing.'
        ret['res'] = False
        return ret

    if 'reason' in kwargs:
        query_params['reason'] = kwargs['reason']

    function = 'agent/maintenance'
    res = _query(consul_url=consul_url,
                 function=function,
                 token=token,
                 method='PUT',
                 query_params=query_params)
    if res['res']:
        ret['res'] = True
        ret['message'] = ('Agent maintenance mode '
                          '{0}ed.'.format(kwargs['enable']))
    else:
        ret['res'] = True
        ret['message'] = 'Unable to change maintenance mode for agent.'
    return ret