Beispiel #1
0
def targets(tgt, tgt_type='glob', **kwargs):  # pylint: disable=W0613
    '''
    Return the targets from the Salt Masters' minion cache.
    All targets and matchers are supported.

    The resulting roster can be configured using ``roster_order`` and ``roster_default``.
    '''
    minions = salt.utils.minions.CkMinions(__opts__)
    minions = minions.check_minions(tgt, tgt_type)

    ret = {}
    if not minions:
        return ret
    # log.debug(minions)

    cache = salt.cache.Cache(__opts__)

    roster_order = __opts__.get('roster_order', {
        'host': ('ipv6-private', 'ipv6-global', 'ipv4-private', 'ipv4-public')
    })
    if isinstance(roster_order, (tuple, list)):
        salt.utils.warn_until('Oxygen', 'Using legacy syntax for roster_order')
        roster_order = {'host': roster_order}
    for config_key, order in roster_order.items():
        for idx, key in enumerate(order):
            if key in ('public', 'private', 'local'):
                salt.utils.warn_until(
                    'Oxygen', 'roster_order {0} will include IPv6 soon. '
                    'Set order to ipv4-{0} if needed.'.format(key))
                order[idx] = 'ipv4-' + key

    # log.debug(roster_order)

    ret = {}
    for minion_id in minions:
        try:
            minion = _load_minion(minion_id, cache)
        except LookupError:
            continue

        minion_res = __opts__.get('roster_defaults', {}).copy()
        for param, order in roster_order.items():
            if not isinstance(order, (list, tuple)):
                order = [order]
            for key in order:
                kres = _minion_lookup(minion_id, key, minion)
                if kres:
                    minion_res[param] = kres
                    break

        if 'host' in minion_res:
            ret[minion_id] = minion_res
        else:
            log.warning(
                'Could not determine host information for minion {0}'.format(
                    minion_id))

    log.debug('Roster lookup result: {0}'.format(ret))

    return ret
Beispiel #2
0
def targets(tgt, tgt_type="glob", **kwargs):  # pylint: disable=W0613
    """
    Return the targets from the Salt Masters' minion cache.
    All targets and matchers are supported.

    The resulting roster can be configured using ``roster_order`` and ``roster_default``.
    """
    minions = salt.utils.minions.CkMinions(__opts__)
    _res = minions.check_minions(tgt, tgt_type)
    minions = _res["minions"]

    ret = {}
    if not minions:
        return ret
    # log.debug(minions)

    cache = salt.cache.Cache(__opts__)

    roster_order = __opts__.get(
        "roster_order",
        {
            "host":
            ("ipv6-private", "ipv6-global", "ipv4-private", "ipv4-public")
        },
    )

    ret = {}
    for minion_id in minions:
        try:
            minion = _load_minion(minion_id, cache)
        except LookupError:
            continue

        minion_res = copy.deepcopy(__opts__.get("roster_defaults", {}))
        for param, order in roster_order.items():
            if not isinstance(order, (list, tuple)):
                order = [order]
            for key in order:
                kres = _minion_lookup(minion_id, key, minion)
                if kres:
                    minion_res[param] = kres
                    break

        if "host" in minion_res:
            ret[minion_id] = minion_res
        else:
            log.warning("Could not determine host information for minion %s",
                        minion_id)

    log.debug("Roster lookup result: %s", ret)

    return ret