Merge branch 'develop' of github.com:saltstack/salt into develop

This commit is contained in:
Thomas S Hatch 2012-03-20 11:36:14 -06:00
commit 203ffe4e06
5 changed files with 79 additions and 41 deletions

View File

@ -141,7 +141,7 @@ def run(cmd, cwd=None, runas=None, shell=DEFAULT_SHELL, env=()):
'''
out = _run(cmd, runas=runas, shell=shell,
cwd=cwd, stderr=subprocess.STDOUT, env=env)['stdout']
log.debug(out)
log.debug('output: {0}'.format(out))
return out
@ -154,7 +154,7 @@ def run_stdout(cmd, cwd=None, runas=None, shell=DEFAULT_SHELL, env=()):
salt '*' cmd.run_stdout "ls -l | awk '/foo/{print $2}'"
'''
stdout = _run(cmd, runas=runas, cwd=cwd, shell=shell, env=())["stdout"]
log.debug(stdout)
log.debug('stdout: {0}'.format(stdout))
return stdout
@ -167,7 +167,7 @@ def run_stderr(cmd, cwd=None, runas=None, shell=DEFAULT_SHELL, env=()):
salt '*' cmd.run_stderr "ls -l | awk '/foo/{print $2}'"
'''
stderr = _run(cmd, runas=runas, cwd=cwd, shell=shell, env=env)["stderr"]
log.debug(stderr)
log.debug('stderr: {0}'.format(stderr))
return stderr
@ -181,13 +181,20 @@ def run_all(cmd, cwd=None, runas=None, shell=DEFAULT_SHELL, env=()):
'''
ret = _run(cmd, runas=runas, cwd=cwd, shell=shell, env=env)
if ret['retcode'] != 0:
log.error('Command {0} failed'.format(cmd))
log.error('retcode: {0}'.format(ret['retcode']))
log.error('stdout: {0}'.format(ret['stdout']))
log.error('stderr: {0}'.format(ret['stderr']))
rcode = ret['retcode']
msg = 'Command \'{0}\' failed with return code: {1}'
log.error(msg.format(cmd, rcode))
# Don't log a blank line if there is no stderr or stdout
if ret['stdout']:
log.error('stdout: {0}'.format(ret['stdout']))
if ret['stderr']:
log.error('stderr: {0}'.format(ret['stderr']))
else:
log.info('stdout: {0}'.format(ret['stdout']))
log.info('stderr: {0}'.format(ret['stderr']))
# No need to always log output on success to the logs
if ret['stdout']:
log.debug('stdout: {0}'.format(ret['stdout']))
if ret['stderr']:
log.debug('stderr: {0}'.format(ret['stderr']))
return ret
@ -202,16 +209,6 @@ def retcode(cmd, cwd=None, runas=None, shell=DEFAULT_SHELL, env=()):
return _run(cmd, runas=runas, cwd=cwd, shell=shell, env=env)['retcode']
def has_exec(cmd):
'''
Returns true if the executable is available on the minion, false otherwise
CLI Example::
salt '*' cmd.has_exec cat
'''
return bool(salt.utils.which(cmd))
def which(cmd):
'''
Returns the path of an executable available on the minion, None otherwise
@ -222,6 +219,18 @@ def which(cmd):
'''
return salt.utils.which(cmd)
def has_exec(cmd):
'''
Returns true if the executable is available on the minion, false otherwise
CLI Example::
salt '*' cmd.has_exec cat
'''
return bool(which(cmd))
def exec_code(lang, code, cwd=None):
'''
Pass in two strings, the first naming the executable language, aka -

View File

@ -20,18 +20,14 @@ def __virtual__():
'''
Only work on posix-like systems
'''
# Disable on these platforms, specific file modules exist:
disable = [
'Windows',
]
if __grains__['os'] in disable:
# win_file takes care of windows
if __grains__['os'] == 'Windows':
return False
return 'file'
__outputter__ = {
'touch': 'txt',
'touch': 'txt',
'append': 'txt',
}

View File

@ -8,6 +8,7 @@ from salt.exceptions import CommandExecutionError
__outputter__ = {
'assign': 'txt',
'get': 'txt',
}
@ -106,9 +107,21 @@ def persist(name, value, config='/etc/sysctl.conf'):
if '=' not in line:
nlines.append(line)
continue
comps = line.split('=')
comps[0] = comps[0].strip()
comps[1] = comps[1].strip()
# Strip trailing whitespace and split the k,v
comps = [i.strip() for i in line.split('=', 1)]
# On Linux procfs, files such as /proc/sys/net/ipv4/tcp_rmem or any
# other sysctl with whitespace in it consistently uses 1 tab. Lets
# allow our users to put a space or tab between multi-value sysctls
# and have salt not try to set it every single time.
if isinstance(comps[1], basestring) and ' ' in comps[1]:
comps[1] = re.sub('\s+', '\t', comps[1])
# Do the same thing for the value 'just in case'
if isinstance(value, basestring) and ' ' in value:
value = re.sub('\s+', '\t', value)
if len(comps) < 2:
nlines.append(line)
continue

View File

@ -8,14 +8,24 @@ import os
def _refine_enc(enc):
'''
Return the properly formatted ssh value for the authorized encryption key
type. If the type is not found, return ssh-rsa, the ssh default.
type. ecdsa defaults to 256 bits, must give full ecdsa enc schema string if
using higher enc. If the type is not found, return ssh-rsa, the ssh default.
'''
rsa = ['r', 'rsa', 'ssh-rsa']
dss = ['d', 'dsa', 'dss', 'ssh-dss']
rsa = ['r', 'rsa', 'ssh-rsa']
dss = ['d', 'dsa', 'dss', 'ssh-dss']
ecdsa = ['e', 'ecdsa', 'ecdsa-sha2-nistp521', 'ecdsa-sha2-nistp384',
'ecdsa-sha2-nistp256']
if enc in rsa:
return 'ssh-rsa'
elif enc in dss:
return 'ssh-dss'
elif enc in ecdsa:
# ecdsa defaults to ecdsa-sha2-nistp256
# otherwise enc string is actual encoding string
if enc in ['e', 'ecdsa']
return 'ecdsa-sha2-nistp256'
return enc
else:
return 'ssh-rsa'
@ -64,7 +74,7 @@ def _replace_auth_key(
lines.append(line)
continue
key_ind = 1
if not comps[0].startswith('ssh-'):
if comps[0][:4:] not in ['ssh-', 'ecds']:
key_ind = 2
if comps[key_ind] == key:
lines.append(auth_line)
@ -132,7 +142,7 @@ def _validate_keys(key_file):
if len(comps) < 2:
# Not a valid line
continue
if not comps[0].startswith('ssh-'):
if comps[0][:4:] not in ['ssh-', 'ecds']:
# It has options, grab them
options = comps[0].split(',')
else:
@ -180,7 +190,7 @@ def rm_auth_key(user, key, config='.ssh/authorized_keys'):
# Not a valid line
lines.append(line)
continue
if not comps[0].startswith('ssh-'):
if comps[0][:4:] not in ['ssh-', 'ecds']:
# It has options, grab them
options = comps[0].split(',')
else:

View File

@ -761,19 +761,29 @@ def managed(name,
else:
__clean_tmp(sfn)
return _error(ret, 'Parent directory not present')
# Create the file, user-rw-only if mode will be set
# Create the file, user rw-only if mode will be set to prevent
# a small security race problem before the permissions are set
if mode:
cumask = os.umask(384)
current_umask = os.umask(077)
# Create a new file when test is False and source is None
if not __opts__['test']:
if __salt__['file.touch'](name):
ret['changes']['new'] = 'file {0} created'.format(name)
ret['comment'] = 'Empty file'
else:
return _error(ret, 'Empty file {0} not created'.format(name))
if mode:
os.umask(cumask)
ret['changes']['new'] = 'file {0} created'.format(name)
ret['comment'] = 'Empty file'
os.umask(current_umask)
# Now copy the file contents if there is a source file
if sfn:
shutil.copyfile(sfn, name)
__clean_tmp(sfn)
# Check and set the permissions if necessary
ret, perms = _check_perms(name, ret, user, group, mode)
if not ret['comment']: