Merge pull request #14823 from cachedout/tty_move

Tty move
This commit is contained in:
Colton Myers 2014-08-07 14:24:28 -06:00
commit d99440e6c9
2 changed files with 46 additions and 32 deletions

View File

@ -1228,6 +1228,38 @@ def exec_code(lang, code, cwd=None):
return ret
def tty(device, echo=None):
'''
Echo a string to a specific tty
CLI Example:
.. code-block:: bash
salt '*' cmd.tty tty0 'This is a test'
salt '*' cmd.tty pts3 'This is a test'
'''
if device.startswith('tty'):
teletype = '/dev/{0}'.format(device)
elif device.startswith('pts'):
teletype = '/dev/{0}'.format(device.replace('pts', 'pts/'))
else:
return {'Error': 'The specified device is not a valid TTY'}
cmd = 'echo {0} > {1}'.format(echo, teletype)
ret = run_all(cmd)
if ret['retcode'] == 0:
return {
'Success': 'Message was successfully echoed to {0}'.format(teletype)
}
else:
return {
'Error': 'Echoing to {0} returned error code {1}'.format(
teletype,
ret['retcode'])
}
def run_chroot(root, cmd):
'''
.. versionadded:: 2014.7.0

View File

@ -393,38 +393,6 @@ def opts_pkg():
return ret
def tty(device, echo=None):
'''
Echo a string to a specific tty
CLI Example:
.. code-block:: bash
salt '*' test.tty tty0 'This is a test'
salt '*' test.tty pts3 'This is a test'
'''
if device.startswith('tty'):
teletype = '/dev/{0}'.format(device)
elif device.startswith('pts'):
teletype = '/dev/{0}'.format(device.replace('pts', 'pts/'))
else:
return {'Error': 'The specified device is not a valid TTY'}
cmd = 'echo {0} > {1}'.format(echo, teletype)
ret = __salt__['cmd.run_all'](cmd)
if ret['retcode'] == 0:
return {
'Success': 'Message was successfully echoed to {0}'.format(teletype)
}
else:
return {
'Error': 'Echoing to {0} returned error code {1}'.format(
teletype,
ret['retcode'])
}
def rand_str(size=9999999999):
'''
Return a random string
@ -465,3 +433,17 @@ def stack():
salt '*' test.stack
'''
return ''.join(traceback.format_stack())
def tty(*args, **kwargs): # pylint: disable=W0613
'''
Deprecated! Moved to cmdmod.
CLI Example:
.. code-block:: bash
salt '*' test.tty tty0 'This is a test'
salt '*' test.tty pts3 'This is a test'
'''
return 'ERROR: This function has been moved to cmd.tty'