added top modules
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2024-02-19 21:25:13 +01:00
parent a179470603
commit 990a67664a
2 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,50 @@
"""
SaltClass Pillar Module
=======================
.. code-block:: yaml
ext_pillar:
- saltclass:
- path: /srv/saltclass
For additional configuration instructions, see the :mod:`saltclass <salt.tops.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)

View File

@ -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)