summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael DeHaan <mdehaan@redhat.com>2007-11-30 17:45:41 -0500
committerMichael DeHaan <mdehaan@redhat.com>2007-11-30 17:45:41 -0500
commitef6fbe4bcdd5e5493fb46b7b04a4aa84d3d113ec (patch)
tree94a850c8847bfa6e327786e912c2cebba8b989b3
parent63789f4c32fea66ed11eed9a1c9871b93b284f7b (diff)
downloadthird_party-func-ef6fbe4bcdd5e5493fb46b7b04a4aa84d3d113ec.tar.gz
third_party-func-ef6fbe4bcdd5e5493fb46b7b04a4aa84d3d113ec.tar.xz
third_party-func-ef6fbe4bcdd5e5493fb46b7b04a4aa84d3d113ec.zip
Integrating the multiplexer feature (forkbomb.py) with func's Client module. This can be wired up to other modules as well, but I've only added it to "call" for now. To use it, pass in the option --forks=N, ex --forks=3 on the command line as an option to "call". The default is forks==1 which completely bypasses the fork code, just to ensure we don't break anything using the Func API that might not like it. (However I'm pretty sure it would be fine).
-rwxr-xr-xfunc/overlord/client.py15
-rw-r--r--func/overlord/cmd_modules/call.py18
2 files changed, 26 insertions, 7 deletions
diff --git a/func/overlord/client.py b/func/overlord/client.py
index 4e7ed27..a52aefa 100755
--- a/func/overlord/client.py
+++ b/func/overlord/client.py
@@ -134,6 +134,7 @@ class Client(object):
self.interactive = interactive
self.noglobs = noglobs
self.nforks = nforks
+
self.servers = expand_servers(self.server_spec,port=self.port,
noglobs=self.noglobs,verbose=self.verbose)
@@ -215,10 +216,18 @@ class Client(object):
return (server_name, retval)
if not self.noglobs:
- results = forkbomb.batch_run(self.servers, process_server,nforks)
+ if self.nforks > 1:
+ # using forkbomb module to distribute job over multiple threads
+ results = forkbomb.batch_run(self.servers, process_server,nforks)
+ else:
+ # no need to go through the fork code, we can do this directly
+ results = {}
+ for x in self.servers:
+ (nkey,nvalue) = process_server(0, 0, x)
+ results[nkey] = nvalue
else:
- # just call the handler without the forkbomb code in play
- self.process_server(0, 0, None)
+ # no need to go through the fork code, we can do this directly
+ self.process_server(0, 0, self.server)
return results
diff --git a/func/overlord/cmd_modules/call.py b/func/overlord/cmd_modules/call.py
index b3484f6..b62131f 100644
--- a/func/overlord/cmd_modules/call.py
+++ b/func/overlord/cmd_modules/call.py
@@ -23,6 +23,7 @@ from func.overlord import command
from func.overlord import client
DEFAULT_PORT = 51234
+DEFAULT_FORKS = 1
class Call(client.command.Command):
name = "call"
@@ -41,6 +42,9 @@ class Call(client.command.Command):
action="store_true")
self.parser.add_option("-p", "--port", dest="port",
default=DEFAULT_PORT)
+ self.parser.add_option("-f", "--forks", dest="forks",
+ help="how many parallel processes? (default 1)",
+ default=DEFAULT_FORKS)
def handleOptions(self, options):
self.options = options
@@ -85,9 +89,15 @@ class Call(client.command.Command):
# I kind of feel like we shouldn't be parsing args here, but I'm
# not sure what the write place is -al;
- self.module = args[0]
- self.method = args[1]
- self.method_args = args[2:]
+ self.module = args[0]
+ if len(args) > 1:
+ self.method = args[1]
+ else:
+ self.method = None
+ if len(args) > 2:
+ self.method_args = args[2:]
+ else:
+ self.method_args = []
# this could get weird, sub sub classes might be calling this
# this with multiple.parentCommand.parentCommands...
@@ -96,7 +106,7 @@ class Call(client.command.Command):
self.server_spec = self.parentCommand.server_spec
client_obj = client.Client(self.server_spec,port=self.port,interactive=True,
- verbose=self.verbose, config=self.config)
+ verbose=self.verbose, config=self.config, nforks=self.options.forks)
results = client_obj.run(self.module, self.method, self.method_args)
# TO DO: add multiplexer support