diff --git a/states/_modules/paulbsdclass.py b/states/_modules/paulbsdclass.py new file mode 100644 index 0000000..c823d4f --- /dev/null +++ b/states/_modules/paulbsdclass.py @@ -0,0 +1,50 @@ +""" +SaltClass Pillar Module +======================= + +.. code-block:: yaml + + ext_pillar: + - saltclass: + - path: /srv/saltclass + +For additional configuration instructions, see the :mod:`saltclass ` module +""" + + +import logging + +import salt.utils.saltclass as sc + +log = logging.getLogger(__name__) + + +def __virtual__(): + """ + This module has no external dependencies + """ + return True + + +def ext_pillar(minion_id, pillar, *args, **kwargs): + """ + Compile pillar data + """ + for i in args: + if "path" not in i: + path = "/srv/saltclass" + args[i]["path"] = path + log.warning("path variable unset, using default: %s", path) + else: + path = i["path"] + + salt_data = { + "__opts__": __opts__, + "__salt__": __salt__, + "__grains__": __grains__, + "__pillar__": pillar, + "minion_id": minion_id, + "path": path, + } + + return sc.get_pillars(minion_id, salt_data) diff --git a/states/_tops/paulbsdclass.py b/states/_tops/paulbsdclass.py new file mode 100644 index 0000000..2673967 --- /dev/null +++ b/states/_tops/paulbsdclass.py @@ -0,0 +1,44 @@ +import logging + +import salt.loader +import salt.utils.saltclass as sc + +log = logging.getLogger(__name__) + + +def __virtual__(): + """ + Only run if properly configured + """ + if __opts__["master_tops"].get("paulbsdclass"): + return True + return False + + +def top(**kwargs): + """ + Compile tops + """ + _opts = __opts__["master_tops"]["paulbsdclass"] + if "path" not in _opts: + path = "/srv/saltclass" + log.warning("path variable unset, using default: %s", path) + else: + path = _opts["path"] + + if "id" not in kwargs["opts"]: + log.warning("Minion id not found - Returning empty dict") + return {} + else: + minion_id = kwargs["opts"]["id"] + + salt_data = { + "__opts__": kwargs["opts"], + "__salt__": salt.loader.minion_mods(__opts__,whitelist=["saltutil", "mine", "grains"]), + "__grains__": kwargs["grains"], + "__pillar__": {}, + "minion_id": minion_id, + "path": path, + } + + return sc.get_tops(minion_id, salt_data)