Read pillar data from Foreman via its API.

def ext_pillar(minion_id,
               pillar,  # pylint: disable=W0613
               key=None,
               only=()):
    '''
    Read pillar data from Foreman via its API.
    '''
    url = __opts__['foreman.url']
    user = __opts__['foreman.user']
    password = __opts__['foreman.password']
    api = __opts__['foreman.api']
    verify = __opts__['foreman.verifyssl']
    certfile = __opts__['foreman.certfile']
    keyfile = __opts__['foreman.keyfile']
    cafile = __opts__['foreman.cafile']
    lookup_parameters = __opts__['foreman.lookup_parameters']

    log.info("Querying Foreman at %r for information for %r", url, minion_id)
    try:
        # Foreman API version 1 is currently not supported
        if api != 2:
            log.error('Foreman API v2 is supported only, please specify'
                    'version 2 in your Salt master config')
            raise Exception

        headers = {'accept': 'version=' + six.text_type(api) + ',application/json'}

        if verify and cafile is not None:
            verify = cafile

        resp = requests.get(
                url + '/hosts/' + minion_id,
                auth=(user, password),
                headers=headers,
                verify=verify,
                cert=(certfile, keyfile)
                )
        result = resp.json()

        log.debug('Raw response of the Foreman request is %r', result)

        if lookup_parameters:
            parameters = dict()
            for param in result['all_parameters']:
                parameters.update({param['name']: param['value']})

            result['parameters'] = parameters

        if only:
            result = dict((k, result[k]) for k in only if k in result)

    except Exception:
        log.exception(
            'Could not fetch host data via Foreman API:'
        )
        return {}

    if key:
        result = {key: result}

    return result