Exemplo n.º 1
0
def ext_pillar(minion_id, pillar, pillar_name=None):
    '''
    A salt external pillar which provides the list of nodegroups of which the minion is a member.

    :param minion_id: used for compound matching nodegroups
    :param pillar: provided by salt, but not used by nodegroups ext_pillar
    :param pillar_name: optional name to use for the pillar, defaults to 'nodegroups'
    :return: a dictionary which is included by the salt master in the pillars returned to the minion
    '''

    pillar_name = pillar_name or 'nodegroups'
    all_nodegroups = __opts__['nodegroups']
    nodegroups_minion_is_in = []
    ckminions = None
    for nodegroup_name in six.iterkeys(all_nodegroups):
        ckminions = ckminions or CkMinions(__opts__)
        _res = ckminions.check_minions(
            all_nodegroups[nodegroup_name],
            'compound')
        match = _res['minions']

        if minion_id in match:
            nodegroups_minion_is_in.append(nodegroup_name)

    return {pillar_name: nodegroups_minion_is_in}
Exemplo n.º 2
0
class UyuniChildMasterIntegration:
    """
    Integration with the Salt Master which is running
    on the same host as this current Minion.
    """
    DEFAULT_MASTER_CONFIG_PATH = "/etc/salt/master"

    def __init__(self):
        self._minions = CkMinions(
            salt.config.client_config(self._get_master_config()))

    @staticmethod
    def _get_master_config() -> str:
        """
        Return master config.
        :return: path to salt master configuration file
        """
        cfg_path = UyuniChildMasterIntegration.DEFAULT_MASTER_CONFIG_PATH
        for path in __pillar__.get("uyuni",
                                   {}).get("masters",
                                           {}).get("configs", [cfg_path]):
            if os.path.exists(path):
                cfg_path = path
                break

        return cfg_path

    def select_minions(
            self,
            target: str,
            target_type: str = "glob") -> Dict[str, Union[List[str], bool]]:
        """
        Select minion IDs that matches the target expression.

        :param target: target expression to be applied
        :param target_type: target type, one of the following: glob, grain, grain_pcre, pillar, pillar_pcre,
                    pillar_exact, compound, compound_pillar_exact. Default: glob.

        :return: list of minions
        """
        return self._minions.check_minions(expr=target, tgt_type=target_type)
Exemplo n.º 3
0
 def __init__(self):
     self._minions = CkMinions(
         salt.config.client_config(self._get_master_config()))