Last active
June 16, 2016 18:25
-
-
Save gladiatr72/60d7f85931a0634000b73ec74df46e5e to your computer and use it in GitHub Desktop.
saltstack, dunders and /srv/salt/_utils
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /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