summaryrefslogtreecommitdiffstats
path: root/func/minion/modules
diff options
context:
space:
mode:
authorLuke Macken <lmacken@redhat.com>2008-01-15 17:42:18 -0500
committerLuke Macken <lmacken@redhat.com>2008-01-15 17:42:18 -0500
commit5d7f93adae47ae2aa137f3f44fb077ed26ed9012 (patch)
tree605eed9003647afac258f1c3f00e5f1d975f43a0 /func/minion/modules
parent23c9c26d270ff766133e7aeebffc99a35633ef41 (diff)
parentdc85cea9b1912ad2cbe59224050b8ae38b051167 (diff)
downloadfunc-5d7f93adae47ae2aa137f3f44fb077ed26ed9012.tar.gz
func-5d7f93adae47ae2aa137f3f44fb077ed26ed9012.tar.xz
func-5d7f93adae47ae2aa137f3f44fb077ed26ed9012.zip
Merge branch 'master' of ssh+git://git.fedorahosted.org/git/func
Diffstat (limited to 'func/minion/modules')
-rw-r--r--func/minion/modules/networktest.py64
-rw-r--r--func/minion/modules/process.py26
2 files changed, 81 insertions, 9 deletions
diff --git a/func/minion/modules/networktest.py b/func/minion/modules/networktest.py
new file mode 100644
index 0000000..e88c169
--- /dev/null
+++ b/func/minion/modules/networktest.py
@@ -0,0 +1,64 @@
+# Copyright 2008, Red Hat, Inc
+# Steve 'Ashcrow' Milner <smilner@redhat.com>
+#
+# This software may be freely redistributed under the terms of the GNU
+# general public license.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+
+from modules import func_module
+from codes import FuncException
+
+import sub_process
+
+class NetworkTest(func_module.FuncModule):
+
+ def __init__(self):
+ self.methods = {
+ "ping" : self.ping,
+ "netstat" : self.netstat,
+ "traceroute" : self.traceroute,
+ "dig" : self.dig,
+ "isportopen" : self.isportopen,
+ }
+ func_module.FuncModule.__init__(self)
+
+ def ping(self, *args):
+ if '-c' not in args:
+ raise(FuncException("You must define a count with -c!"))
+ return self.__run_command('/bin/ping', self.__args_to_list(args))
+
+ def netstat(self, *args):
+ return self.__run_command('/bin/netstat',
+ self.__args_to_list(args))
+
+ def traceroute(self, *args):
+ return self.__run_command('/bin/traceroute',
+ self.__args_to_list(args))
+
+ def dig(self, *args):
+ return self.__run_command('/usr/bin/dig',
+ self.__args_to_list(args))
+
+ def isportopen(self, host, port):
+ import socket
+ sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ sock.connect((host, int(port)))
+ data = sock.recv(2048)
+ sock.close()
+ return [line for line in data.split('\n')]
+
+ def __args_to_list(self, args):
+ return [arg for arg in args]
+
+ def __run_command(self, command, opts=[]):
+ full_cmd = [command] + opts
+ cmd = sub_process.Popen(full_cmd, stdout=sub_process.PIPE)
+ return [line for line in cmd.communicate()[0].split('\n')]
+
+
+methods = NetworkTest()
+register_rpc = methods.register_rpc
diff --git a/func/minion/modules/process.py b/func/minion/modules/process.py
index 18b5abe..e5b9183 100644
--- a/func/minion/modules/process.py
+++ b/func/minion/modules/process.py
@@ -24,22 +24,27 @@ import func_module
class ProcessModule(func_module.FuncModule):
- def info(self,flags="-auxh"):
+ def info(self, flags="-auxh"):
"""
Returns a struct of hardware information. By default, this pulls down
all of the devices. If you don't care about them, set with_devices to
False.
"""
- flags.replace(";","") # prevent stupidity
+ flags.replace(";", "") # prevent stupidity
+ cmd = sub_process.Popen(["/bin/ps", flags], executable="/bin/ps",
+ stdout=sub_process.PIPE,
+ stderr=sub_process.PIPE,
+ shell=False)
- #FIXME: we need to swallow stdout/stderr as well, right now it spews to the console
- cmd = sub_process.Popen(["/bin/ps", flags] ,executable="/bin/ps", stdout=sub_process.PIPE,shell=False)
- data = cmd.communicate()[0]
+ data, error = cmd.communicate()
- results = []
+ # We can get warnings for odd formatting. warnings != errors.
+ if error and error[:7] != "Warning":
+ raise codes.FuncException(error.split('\n')[0])
+ results = []
for x in data.split("\n"):
tokens = x.split()
results.append(tokens)
@@ -188,15 +193,18 @@ class ProcessModule(func_module.FuncModule):
if pid == "0":
raise codes.FuncException("Killing pid group 0 not permitted")
if signal == "":
- # this is default /bin/kill behaviour, it claims, but enfore it anyway
+ # this is default /bin/kill behaviour,
+ # it claims, but enfore it anyway
signal = "-TERM"
if signal[0] != "-":
signal = "-%s" % signal
- rc = sub_process.call(["/bin/kill",signal, pid], executable="/bin/kill", shell=False)
+ rc = sub_process.call(["/bin/kill",signal, pid],
+ executable="/bin/kill", shell=False)
print rc
return rc
def pkill(self,name,level=""):
# example killall("thunderbird","-9")
- rc = sub_process.call(["/usr/bin/pkill", name, level], executable="/usr/bin/pkill", shell=False)
+ rc = sub_process.call(["/usr/bin/pkill", name, level],
+ executable="/usr/bin/pkill", shell=False)
return rc