コード例 #1
0
ファイル: server_metadata.py プロジェクト: AnishSid/calamari
def get_local_grains():
    """
    Return the salt grains for this host that we are running
    on.  If we support SELinux in the future this may need
    to be moved into a cthulhu RPC as the apache worker may
    not have the right capabilities to query all the grains.
    """
    # Stash grains as an attribute of this function
    if not hasattr(get_local_grains, 'grains'):

        # >> work around salt issue #11402
        import __main__ as main
        main.__file__ = 'workaround'
        # <<

        # Use salt to get an interesting subset of the salt grains (getting
        # everything is a bit slow)
        grains = {}
        c = master_config(config.get('cthulhu', 'salt_config_path'))
        l = _create_loader(c, 'grains', 'grain')
        funcs = l.gen_functions()
        for key in [k for k in funcs.keys() if k.startswith('core.')]:
            ret = funcs[key]()
            if isinstance(ret, dict):
                grains.update(ret)
        get_local_grains.grains = grains
    else:
        grains = get_local_grains.grains

    return grains
コード例 #2
0
def get_grains_from_loader():
    # Use salt to get an interesting subset of the salt grains (getting
    # everything is a bit slow)
    master_conf = master_config(config.get('cthulhu', 'salt_config_path'))
    load = _create_loader(master_conf, 'grains', 'grain')
    # static_loader returns a dict object, _create_loader returns
    # a Loader object. Handle both cases.
    if isinstance(load, dict):
        funcs = load
    else:
        funcs = load.gen_functions()

    return funcs
コード例 #3
0
ファイル: salt_remote.py プロジェクト: zerolugithub/calamari
    def get_local_metadata(self):
        # Stash grains as an attribute of this function
        if not hasattr(SaltRemote, 'grains'):
            # >> work around salt issue #11402
            import __main__ as main
            main.__file__ = 'workaround'
            # <<

            # Use salt to get an interesting subset of the salt grains (getting
            # everything is a bit slow)
            grains = {}
            c = master_config(config.get('cthulhu', 'salt_config_path'))
            l = _create_loader(c, 'grains', 'grain')
            funcs = l.gen_functions()
            for key in [k for k in funcs.keys() if k.startswith('core.')]:
                ret = funcs[key]()
                if isinstance(ret, dict):
                    grains.update(ret)
            SaltRemote.grains = grains
        else:
            grains = SaltRemote.grains

        return grains
コード例 #4
0
ファイル: salt_remote.py プロジェクト: ceph/calamari
    def get_local_metadata(self):
        # Stash grains as an attribute of this function
        if not hasattr(SaltRemote, 'grains'):
            # >> work around salt issue #11402
            import __main__ as main
            main.__file__ = 'workaround'
            # <<

            # Use salt to get an interesting subset of the salt grains (getting
            # everything is a bit slow)
            grains = {}
            c = master_config(config.get('cthulhu', 'salt_config_path'))
            l = _create_loader(c, 'grains', 'grain')
            funcs = l.gen_functions()
            for key in [k for k in funcs.keys() if k.startswith('core.')]:
                ret = funcs[key]()
                if isinstance(ret, dict):
                    grains.update(ret)
            SaltRemote.grains = grains
        else:
            grains = SaltRemote.grains

        return grains