From b0cb5b7a380c9ba1a6b2ca328f7f2f5da4a87e80 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Mon, 8 Oct 2007 15:38:21 -0400 Subject: sort the returns of these methods just to make it purdy --- func/minion/server.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'func') diff --git a/func/minion/server.py b/func/minion/server.py index 39a78cb..253c06a 100755 --- a/func/minion/server.py +++ b/func/minion/server.py @@ -80,10 +80,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): -- cgit From 070d1700b915729421595b83993abc31005355c1 Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Mon, 8 Oct 2007 15:43:06 -0400 Subject: add a couple alternatice serializers just for kicks --- func/overlord/cmd_modules/call.py | 43 +++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'func') 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) -- cgit From 4bc503c96cb1d6ac98a9b3aa288102fd539a046b Mon Sep 17 00:00:00 2001 From: Adrian Likins Date: Mon, 8 Oct 2007 15:44:30 -0400 Subject: er, merge? wtf, I already committed and pushed these changes --- func/overlord/client.py | 77 +++---------------------------------------------- func/utils.py | 4 +++ 2 files changed, 8 insertions(+), 73 deletions(-) (limited to 'func') 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/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) + + -- cgit