summaryrefslogtreecommitdiffstats
path: root/func
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
parent23c9c26d270ff766133e7aeebffc99a35633ef41 (diff)
parentdc85cea9b1912ad2cbe59224050b8ae38b051167 (diff)
downloadthird_party-func-5d7f93adae47ae2aa137f3f44fb077ed26ed9012.tar.gz
third_party-func-5d7f93adae47ae2aa137f3f44fb077ed26ed9012.tar.xz
third_party-func-5d7f93adae47ae2aa137f3f44fb077ed26ed9012.zip
Merge branch 'master' of ssh+git://git.fedorahosted.org/git/func
Diffstat (limited to 'func')
-rwxr-xr-xfunc/certmaster.py2
-rw-r--r--func/minion/modules/networktest.py64
-rw-r--r--func/minion/modules/process.py26
-rwxr-xr-xfunc/minion/server.py1
-rwxr-xr-xfunc/overlord/inventory.py2
-rw-r--r--func/overlord/jobthing.py13
-rwxr-xr-xfunc/overlord/sslclient.py2
7 files changed, 88 insertions, 22 deletions
diff --git a/func/certmaster.py b/func/certmaster.py
index fa72493..1cde806 100755
--- a/func/certmaster.py
+++ b/func/certmaster.py
@@ -1,5 +1,3 @@
-#!/usr/bin/python
-
# FIXME: more intelligent fault raises
"""
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
diff --git a/func/minion/server.py b/func/minion/server.py
index cd353b9..6e55e70 100755
--- a/func/minion/server.py
+++ b/func/minion/server.py
@@ -1,4 +1,3 @@
-#!/usr/bin/python
"""
func
diff --git a/func/overlord/inventory.py b/func/overlord/inventory.py
index aafc764..e5319ee 100755
--- a/func/overlord/inventory.py
+++ b/func/overlord/inventory.py
@@ -1,4 +1,3 @@
-#!/usr/bin/python
##
## func inventory app.
## use func to collect inventory data on anything, yes, anything
@@ -186,6 +185,5 @@ class FuncInventory(object):
if __name__ == "__main__":
-
inv = FuncInventory()
inv.run(sys.argv)
diff --git a/func/overlord/jobthing.py b/func/overlord/jobthing.py
index cd13253..d28e966 100644
--- a/func/overlord/jobthing.py
+++ b/func/overlord/jobthing.py
@@ -37,6 +37,7 @@ def __get_status(jobid):
return __access_status(jobid=jobid, write=False)
def __access_status(jobid=0, status=0, results=0, clear=False, write=False):
+
dir = os.path.expanduser("~/.func")
if not os.path.exists(dir):
os.makedirs(dir)
@@ -53,19 +54,16 @@ def __access_status(jobid=0, status=0, results=0, clear=False, write=False):
fcntl.flock(handle.fileno(), fcntl.LOCK_UN)
return {}
- if not storage.has_key("data"):
- storage["data"] = {}
-
# FIXME: the jobid is the time of the job, so deleting jobs
# that are older than a set time would be a very good idea.
if write:
- storage["data"][jobid] = (status, results)
+ storage[str(jobid)] = (status, results)
rc = jobid
else:
- if storage["data"].has_key(jobid):
+ if storage.has_key(str(jobid)):
# tuple of (status, results)
- rc = storage["data"][jobid]
+ rc = storage[str(jobid)]
else:
rc = (JOB_ID_LOST_IN_SPACE, 0)
@@ -84,11 +82,14 @@ def batch_run(server, process_server, nforks):
job_id = time.time()
pid = os.fork()
if pid != 0:
+ #print "DEBUG: UPDATE STATUS: r1: %s" % job_id
__update_status(job_id, JOB_ID_RUNNING, -1)
return job_id
else:
+ #print "DEBUG: UPDATE STATUS: r2: %s" % job_id
__update_status(job_id, JOB_ID_RUNNING, -1)
results = forkbomb.batch_run(server, process_server, nforks)
+ #print "DEBUG: UPDATE STATUS: f1: %s" % job_id
__update_status(job_id, JOB_ID_FINISHED, results)
sys.exit(0)
diff --git a/func/overlord/sslclient.py b/func/overlord/sslclient.py
index ccb2c9c..3861bb8 100755
--- a/func/overlord/sslclient.py
+++ b/func/overlord/sslclient.py
@@ -1,5 +1,3 @@
-#!/usr/bin/python
-
import sys
import xmlrpclib
import urllib