mirror of
https://github.com/valitydev/salt.git
synced 2024-11-08 17:33:54 +00:00
Integrate the grains into the memory model
This commit is contained in:
parent
ee5b7a6852
commit
2775ba4b15
@ -10,6 +10,7 @@ import logging
|
||||
import yaml
|
||||
# Import salt libs
|
||||
import salt.crypt
|
||||
import salt.loader
|
||||
|
||||
def minion_config(path):
|
||||
'''
|
||||
@ -53,6 +54,8 @@ def minion_config(path):
|
||||
opts['log_level'],
|
||||
opts['out_level'])
|
||||
|
||||
opts['grains'] = salt.loader.grains
|
||||
|
||||
return opts
|
||||
|
||||
def master_config(path):
|
||||
@ -153,19 +156,3 @@ def minion_logger(log_file, log_level, console_level):
|
||||
|
||||
return logger
|
||||
|
||||
def facter_data():
|
||||
'''
|
||||
Returns a dict of data about the minion allowing modules to differ
|
||||
based on information gathered about the minion.
|
||||
So far only facter information is loaded
|
||||
'''
|
||||
facts = subprocess.Popen('facter',
|
||||
shell=True,
|
||||
stdout=subprocess.PIPE).communicate()[0]
|
||||
facter = {}
|
||||
for line in facts.split('\n'):
|
||||
if line.count('=>'):
|
||||
comps = line.split('=>')
|
||||
facter[comps[0].strip()] = comps[1].strip()
|
||||
|
||||
return facter
|
||||
|
@ -34,14 +34,14 @@ def returners(opts):
|
||||
load = Loader(module_dirs, opts)
|
||||
return load.filter_func('returner')
|
||||
|
||||
def grains(opts):
|
||||
def grains():
|
||||
'''
|
||||
Return the functions for the dynamic grains and the values for the static
|
||||
grains.
|
||||
'''
|
||||
module_dirs = [
|
||||
os.path.join(distutils.sysconfig.get_python_lib(), 'salt/grains'),
|
||||
] + opts['grains_dirs']
|
||||
]
|
||||
load = Loader(module_dirs, opts)
|
||||
return load.gen_grains()
|
||||
|
||||
@ -64,6 +64,10 @@ class Loader(object):
|
||||
'''
|
||||
def __init__(self, module_dirs, opts={}):
|
||||
self.module_dirs = module_dirs
|
||||
if opts.has_key('grains'):
|
||||
self.grains = opts['grains']
|
||||
else:
|
||||
self.grains = {}
|
||||
self.opts = self.__prep_mod_opts(opts)
|
||||
|
||||
def __prep_mod_opts(self, opts):
|
||||
@ -74,6 +78,8 @@ class Loader(object):
|
||||
for key, val in opts.items():
|
||||
if key == 'logger':
|
||||
continue
|
||||
if key == 'grains':
|
||||
continue
|
||||
mod_opts[key] = val
|
||||
return mod_opts
|
||||
|
||||
@ -143,6 +149,8 @@ class Loader(object):
|
||||
else:
|
||||
mod.__opts__ = self.opts
|
||||
|
||||
mod.__grains__ = self.grains
|
||||
|
||||
for attr in dir(mod):
|
||||
if attr.startswith('_'):
|
||||
continue
|
||||
|
Loading…
Reference in New Issue
Block a user