mirror of
https://github.com/valitydev/salt.git
synced 2024-11-07 00:55:19 +00:00
Add in the cmd module, this is simple and can be expanded, although the basic
bases are covered
This commit is contained in:
parent
9fe924e89a
commit
5ba8c63dae
47
salt/modules/cmd.py
Normal file
47
salt/modules/cmd.py
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
'''
|
||||||
|
A module for shelling out
|
||||||
|
|
||||||
|
Keep in mind that this module is insecure, in that it can give whomever has
|
||||||
|
access to the master root execution access to all salt minions
|
||||||
|
'''
|
||||||
|
|
||||||
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
def run(cmd):
|
||||||
|
'''
|
||||||
|
Execute the passed command and return the output
|
||||||
|
'''
|
||||||
|
return subprocess.Popen(cmd,
|
||||||
|
shell=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT).communicate()[0]
|
||||||
|
|
||||||
|
def run_stdout(cmd):
|
||||||
|
'''
|
||||||
|
Execute a command, and only return the standard out
|
||||||
|
'''
|
||||||
|
return subprocess.Popen(cmd,
|
||||||
|
shell=True,
|
||||||
|
stdout=subprocess.PIPE).communicate()[0]
|
||||||
|
|
||||||
|
def run_stderr(cmd):
|
||||||
|
'''
|
||||||
|
Executa a command and only return the
|
||||||
|
'''
|
||||||
|
return subprocess.Popen(cmd,
|
||||||
|
shell=True,
|
||||||
|
stderr=subprocess.PIPE).communicate()[0]
|
||||||
|
|
||||||
|
def exec_code(lang, code):
|
||||||
|
'''
|
||||||
|
Pass in two strings, the first naming the executable language, aka -
|
||||||
|
python2, python3, ruby, perl, lua, etc. the second string containing
|
||||||
|
the code you wish to execute. The stdout and stderr will be returned
|
||||||
|
'''
|
||||||
|
cfn = tempfile.mkstemp()
|
||||||
|
open(cfn, 'w+').write(code)
|
||||||
|
return subprocess.Popen(lang + ' ' + cfn,
|
||||||
|
shell=True,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT).communicate()[0]
|
Loading…
Reference in New Issue
Block a user