paulbsd-salt/states/_tops/paulbsdclass.py

45 lines
1.0 KiB
Python
Raw Permalink Normal View History

2024-02-19 21:25:13 +01:00
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)