Merge pull request #38104 from rallytime/bp-36794

Back-port #36794 to 2016.3
This commit is contained in:
Mike Place 2016-12-07 06:23:48 -07:00 committed by GitHub
commit 8c8cbc2734

View file

@ -2,7 +2,10 @@
'''
Module for viewing and modifying sysctl parameters
'''
# Import Python libs
from __future__ import absolute_import
import logging
# Import salt libs
import salt.utils
@ -11,6 +14,9 @@ from salt.exceptions import CommandExecutionError
# Define the module's virtual name
__virtualname__ = 'sysctl'
# Get logging started
log = logging.getLogger(__name__)
def __virtual__():
'''
@ -56,17 +62,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):