Skip to content

Instantly share code, notes, and snippets.

@gladiatr72
Last active June 16, 2016 18:25
Show Gist options
  • Save gladiatr72/60d7f85931a0634000b73ec74df46e5e to your computer and use it in GitHub Desktop.
Save gladiatr72/60d7f85931a0634000b73ec74df46e5e to your computer and use it in GitHub Desktop.
saltstack, dunders and /srv/salt/_utils
# /srv/salt/_modules/thing.py
import sys as _sys
def __virtual__():
return "thing"
def has_thing():
return True if __salt__['sys.list_modules']('thing') else False
def run():
return __utils__['thing.test']()
def thing_namespace():
__utils__['thing.test']()
THING = _sys.modules['salt.loaded.ext.utils.thing']
return dir(THING)
# /srv/salt/_utils/thing.py
import sys as _sys
from salt.loader import utils as _utils
_anchor = _sys.modules[__name__]
def __virtual__():
setattr(_anchor, '__utilS__', _utils(__opts__, context=__context__))
return "thing"
def test():
return True if getattr(_anchor, '__utilS__', None) else False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment