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
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
def update_connected_minions(): from cthulhu.manager import config from calamari_common.salt_wrapper import Key, master_config if len(Key(master_config(config.get('cthulhu', 'salt_config_path'))).list_keys()['minions']) == 0: # no minions to update return message = "Updating already connected nodes." log.info(message) p = subprocess.Popen(["salt", "*", "state.highstate"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() log.debug("{message} salt stdout: {out}".format(message=message, out=out)) log.debug("{message} salt stderr: {err}".format(message=message, err=err)) if p.returncode != 0: raise RuntimeError("{message} failed with rc={rc}".format(message=message, rc=p.returncode))
def update_connected_minions(): from cthulhu.manager import config from calamari_common.salt_wrapper import Key, master_config if len( Key(master_config(config.get( 'cthulhu', 'salt_config_path'))).list_keys()['minions']) == 0: # no minions to update return message = "Updating already connected nodes." log.info(message) p = subprocess.Popen(["salt", "*", "state.highstate"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = p.communicate() log.debug("{message} salt stdout: {out}".format(message=message, out=out)) log.debug("{message} salt stderr: {err}".format(message=message, err=err)) if p.returncode != 0: raise RuntimeError("{message} failed with rc={rc}".format( message=message, rc=p.returncode))
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
def _salt_key(self): return Key(master_config(config.get('cthulhu', 'salt_config_path')))
def _salt_key(self): return Key(master_config(config.get("cthulhu", "salt_config_path")))