salt.modules.at: minor cleanups

- foo.split('\n') --> foo.splitlines()
    - Add outputter for at, atq, and atrm funcs
    - Use the os_family grain for all RedHat hosts

Please test this out folks, I'm not a huge at user
This commit is contained in:
Jeff Schroeder 2012-10-31 21:26:17 -07:00
parent 043d7204ab
commit 328aeb751a

View File

@ -11,19 +11,19 @@ import time
__outputter__ = { __outputter__ = {
'atc': 'txt', 'atc': 'txt',
'at': 'yaml',
'atq': 'yaml',
'atrm': 'yaml',
} }
# OS Families that should work (Ubuntu and Debian are the # OS Families that should work (Ubuntu and Debian are the
# default) # default)
# Tested on CentOS 5.8
rhel = ('CentOS', 'Scientific', 'RedHat', 'Fedora', 'CloudLinux')
# Tested on OpenBSD 5.0 # Tested on OpenBSD 5.0
bsd = ('OpenBSD', 'FreeBSD') bsd = ('OpenBSD', 'FreeBSD')
# Known not to work # Known not to work
bad = ('Windows') bad = ('Windows',)
def __virtual__(): def __virtual__():
@ -58,7 +58,8 @@ def atq(tag=None):
# Shim to produce output similar to what __virtual__() should do # Shim to produce output similar to what __virtual__() should do
# but __salt__ isn't available in __virtual__() # but __salt__ isn't available in __virtual__()
if __grains__['os'] in rhel: # Tested on CentOS 5.8
if __grains__['os_family'] == "RedHat":
output = _cmd('at', '-l') output = _cmd('at', '-l')
else: else:
output = _cmd('atq') output = _cmd('atq')
@ -73,7 +74,7 @@ def atq(tag=None):
# Split each job into a dictionary and handle # Split each job into a dictionary and handle
# pulling out tags or only listing jobs with a certain # pulling out tags or only listing jobs with a certain
# tag # tag
for line in output.split('\n'): for line in output.splitlines():
job_tag = '' job_tag = ''
# Jobs created with at.at() will use the following # Jobs created with at.at() will use the following
@ -81,7 +82,7 @@ def atq(tag=None):
job_kw_regex = re.compile('^### SALT: (\w+)') job_kw_regex = re.compile('^### SALT: (\w+)')
# Redhat/CentOS # Redhat/CentOS
if __grains__['os'] in rhel: if __grains__['os_family'] == 'RedHat':
job, spec = line.split('\t') job, spec = line.split('\t')
specs = spec.split() specs = spec.split()
elif __grains__['os'] in bsd: elif __grains__['os'] in bsd:
@ -107,7 +108,7 @@ def atq(tag=None):
# Search for any tags # Search for any tags
atc_out = _cmd('at', '-c', job) atc_out = _cmd('at', '-c', job)
for line in atc_out.split('\n'): for line in atc_out.splitlines():
tmp = job_kw_regex.match(line) tmp = job_kw_regex.match(line)
if tmp: if tmp:
job_tag = tmp.groups()[0] job_tag = tmp.groups()[0]
@ -197,7 +198,7 @@ def at(*pargs, **kwargs):
if not bin: if not bin:
return '"{0}" is not available.'.format('at.at') return '"{0}" is not available.'.format('at.at')
if __grains__['os'] in rhel: if __grains__['os_family'] == 'RedHat':
echo_cmd = 'echo -e' echo_cmd = 'echo -e'
else: else:
echo_cmd = 'echo' echo_cmd = 'echo'
@ -222,10 +223,10 @@ def at(*pargs, **kwargs):
return {'jobs': [], 'error': 'invalid timespec'} return {'jobs': [], 'error': 'invalid timespec'}
if output.startswith('warning: commands'): if output.startswith('warning: commands'):
output = output.split('\n')[1] output = output.splitlines()[1]
if output.startswith('commands will be executed'): if output.startswith('commands will be executed'):
output = output.split('\n')[1] output = output.splitlines()[1]
if __grains__['os'] in bsd: if __grains__['os'] in bsd:
return atq(str(output.split()[1])) return atq(str(output.split()[1]))