FreeBSD sysctl module now handels config_file parameter in show method

This commit is contained in:
Dominic Schlegel 2016-10-05 14:49:10 +02:00 committed by rallytime
parent fbc87769b9
commit da3ebf83e6

View file

@ -56,17 +56,31 @@ def show(config_file=False):
)
cmd = 'sysctl -ae'
ret = {}
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
comps = ['']
for line in out.splitlines():
if any([line.startswith('{0}.'.format(root)) for root in roots]):
comps = line.split('=', 1)
ret[comps[0]] = comps[1]
elif comps[0]:
ret[comps[0]] += '{0}\n'.format(line)
else:
continue
return ret
if config_file:
try:
with salt.utils.fopen(config_file, 'r') as f:
for line in f.readlines():
l = line.strip()
if l != "" and not l.startswith("#"):
comps = line.split('=', 1)
ret[comps[0]] = comps[1]
return ret
except (OSError, IOError):
log.error('Could not open sysctl config file')
return None
else:
out = __salt__['cmd.run'](cmd, output_loglevel='trace')
for line in out.splitlines():
if any([line.startswith('{0}.'.format(root)) for root in roots]):
comps = line.split('=', 1)
ret[comps[0]] = comps[1]
elif comps[0]:
ret[comps[0]] += '{0}\n'.format(line)
else:
continue
return ret
def get(name):