diff options
author | Seth Vidal <skvidal@fedoraproject.org> | 2007-10-08 16:19:10 -0400 |
---|---|---|
committer | Seth Vidal <skvidal@fedoraproject.org> | 2007-10-08 16:19:10 -0400 |
commit | 5ded2eccc6a6d6c574843139bac8747013326dbd (patch) | |
tree | b1918338edb3831604e834fab2642a37f12cc4dd /func | |
parent | 87644d612c2061c4d8670c1cb046cc4a37a3dbb5 (diff) | |
parent | e09c2a9c1506d254299b3743d3524a5204eceed0 (diff) | |
download | third_party-func-5ded2eccc6a6d6c574843139bac8747013326dbd.tar.gz third_party-func-5ded2eccc6a6d6c574843139bac8747013326dbd.tar.xz third_party-func-5ded2eccc6a6d6c574843139bac8747013326dbd.zip |
Merge branch 'master' of ssh://git.fedoraproject.org/git/hosted/func
* 'master' of ssh://git.fedoraproject.org/git/hosted/func:
er, merge?
add a couple alternatice serializers just for kicks
sort the returns of these methods just to make it purdy
Diffstat (limited to 'func')
-rwxr-xr-x | func/minion/server.py | 8 | ||||
-rwxr-xr-x | func/overlord/client.py | 77 | ||||
-rw-r--r-- | func/overlord/cmd_modules/call.py | 43 | ||||
-rwxr-xr-x | func/utils.py | 4 |
4 files changed, 49 insertions, 83 deletions
diff --git a/func/minion/server.py b/func/minion/server.py index 921aa03..c900a09 100755 --- a/func/minion/server.py +++ b/func/minion/server.py @@ -81,10 +81,14 @@ class XmlRpcInterface(object): self.handlers["system.list_modules"] = self.list_modules def list_modules(self): - return self.modules.keys() + modules = self.modules.keys() + modules.sort() + return modules def list_methods(self): - return self.handlers.keys() + methods = self.handlers.keys() + methods.sort() + return methods def get_dispatch_method(self, method): diff --git a/func/overlord/client.py b/func/overlord/client.py index 3c60148..ec304a5 100755 --- a/func/overlord/client.py +++ b/func/overlord/client.py @@ -22,9 +22,11 @@ import pprint from func.commonconfig import CMConfig from func.config import read_config, CONFIG_FILE + import sslclient import command +import func_command # =================================== # defaults @@ -174,7 +176,8 @@ class Client(object): meth = "%s.%s" % (module, method) retval = getattr(conn, meth)(*args[:]) if self.interactive: - pprint.pprint(retval) + print retval +# pprint.pprint(retval) except Exception, e: retval = e if self.interactive: @@ -220,76 +223,4 @@ class Client(object): max = x return max -# =================================================================== - -class Call(command.Command): - name = "call" - useage = "call nodule method name arg1 arg2..." - def addOptions(self): - self.parser.add_option("-v", "--verbose", dest="verbose", - action="store_true") - self.parser.add_option("-p", "--port", dest="port", - default=DEFAULT_PORT) - - def handleOptions(self, options): - self.options = options - - self.verbose = options.verbose - self.port = options.port - # I'm not really a fan of the "module methodname" approach - # but we'll keep it for now -akl - - def do(self, args): - - # I'm not really a fan of the "module methodname" approach - # but we'll keep it for now -akl - - self.server_spec = args[0] - self.module = args[1] - self.method = args[2] - self.method_args = args[3:] - - client = Client(self.server_spec,port=self.port,interactive=True, - verbose=self.verbose, config=self.config) - results = client.run(self.module, self.method, self.method_args) - - # TO DO: add multiplexer support - # probably as a higher level module. - - return client.cli_return(results) - -class FuncCommandLine(command.Command): - name = "client" - useage = "func is the commandline interface to a func minion" - - subCommandClasses = [Call] - - def __init__(self): - - command.Command.__init__(self) - - def do(self, args): - pass - - def addOptions(self): - self.parser.add_option('', '--version', action="store_true", - help="show version information") - self.parser.add_option("--list-minions", dest="list_minions", - action="store_true", help="list all available minions") - - def handleOptions(self, options): - if options.version: - #FIXME - print "version is NOT IMPLEMENTED YET" - if options.list_minions: - self.list_minions() - - sys.exit(0) # stop execution - def list_minions(self): - print "Minions:" - gloob = "%s/%s.cert" % (self.config.certroot, "*") - certs = glob.glob(gloob) - for cert in certs: - host = cert.replace(self.config.certroot, "")[1:-5] - print " %s" % host diff --git a/func/overlord/cmd_modules/call.py b/func/overlord/cmd_modules/call.py index 644930f..07a3aa2 100644 --- a/func/overlord/cmd_modules/call.py +++ b/func/overlord/cmd_modules/call.py @@ -1,6 +1,8 @@ #!/usr/bin/python import optparse +import pprint +import xmlrpclib from func.overlord import command from func.overlord import client @@ -12,38 +14,62 @@ class Call(client.command.Command): useage = "call nodule method name arg1 arg2..." def addOptions(self): self.parser.add_option("-v", "--verbose", dest="verbose", - action="store_true") + action="store_true") + self.parser.add_option("-x", "--xmlrpc", dest="xmlrpc", + action="store_true") + self.parser.add_option("", "--pprint", dest="pprint", + action="store_true") + self.parser.add_option("-j", "--json", dest="json", + action="store_true") self.parser.add_option("-p", "--port", dest="port", - default=DEFAULT_PORT) + default=DEFAULT_PORT) def handleOptions(self, options): - print "self.parentCommand", self.parentCommand - self.options = options self.verbose = options.verbose self.port = options.port + # I'm not really a fan of the "module methodname" approach # but we'll keep it for now -akl def parse(self, argv): self.argv = argv - print "self.argv,", self.argv - # FIXME? not sure this is good or bad, but it seems # wronky... we try to grab the hostnamegoo from the # args to the parentCommand self.server_spec = self.argv[0] return command.Command.parse(self, argv) + + + def format_return(self, data): + if self.options.xmlrpc: + return xmlrpclib.dumps((data,"")) + + if self.options.pprint: + return pprint.pformat(data) + + if self.options.json: + print "fffffffffffffffffffffffffffffffffffffffffff" + try: + import simplejson + return simplejson.dumps(data) + except ImportError: + print "json support not found" + return data + + return data def do(self, args): # I'm not really a fan of the "module methodname" approach # but we'll keep it for now -akl - print "ARGS", args + # I kind of feel like we shouldn't be parsing args here, but I'm + # not sure what the write place is -al; + self.server_spec = args[0] self.module = args[1] self.method = args[2] self.method_args = args[3:] @@ -55,4 +81,5 @@ class Call(client.command.Command): # TO DO: add multiplexer support # probably as a higher level module. - return client_obj.cli_return(results) + # dump the return code stuff atm till we figure out the right place for it + return self.format_return(results) diff --git a/func/utils.py b/func/utils.py index 8d9d383..de08ba9 100755 --- a/func/utils.py +++ b/func/utils.py @@ -17,6 +17,8 @@ import string import sys import traceback + + # this is kind of handy, so keep it around for now # but we really need to fix out server side logging and error # reporting so we don't need it @@ -45,3 +47,5 @@ def daemonize(pidfile=None): if pidfile is not None: open(pidfile, "w").write(str(pid)) sys.exit(0) + + |