diff options
-rw-r--r-- | func/overlord/cmd_modules/call.py | 24 | ||||
-rw-r--r-- | func/overlord/cmd_modules/check.py | 22 | ||||
-rw-r--r-- | func/overlord/cmd_modules/copyfile.py | 23 | ||||
-rw-r--r-- | func/overlord/cmd_modules/listminions.py | 15 | ||||
-rw-r--r-- | func/overlord/cmd_modules/ping.py | 18 | ||||
-rw-r--r-- | func/overlord/cmd_modules/show.py | 27 | ||||
-rw-r--r-- | func/overlord/command.py | 24 |
7 files changed, 65 insertions, 88 deletions
diff --git a/func/overlord/cmd_modules/call.py b/func/overlord/cmd_modules/call.py index ea16975..dda57eb 100644 --- a/func/overlord/cmd_modules/call.py +++ b/func/overlord/cmd_modules/call.py @@ -20,10 +20,9 @@ import xmlrpclib from func.overlord import command from func.overlord import client -DEFAULT_PORT = 51234 DEFAULT_FORKS = 1 -class Call(client.command.Command): +class Call(client.command.BaseCommand): name = "call" usage = "call module method name arg1 arg2..." def addOptions(self): @@ -38,17 +37,13 @@ class Call(client.command.Command): self.parser.add_option("-j", "--json", dest="json", help="output return data using JSON", 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 - 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 @@ -56,7 +51,7 @@ class Call(client.command.Command): def parse(self, argv): self.argv = argv - return command.Command.parse(self, argv) + return command.BaseCommand.parse(self, argv) def format_return(self, data): @@ -101,15 +96,16 @@ class Call(client.command.Command): # this with multiple.parentCommand.parentCommands... # maybe command.py needs a way to set attrs on subCommands? # or some sort of shared datastruct? - self.server_spec = self.parentCommand.server_spec + # self.getOverlord() + - overlord_obj = client.Overlord(self.server_spec,port=self.port, - interactive=True, - verbose=self.verbose, - config=self.config, - nforks=self.options.forks) - results = overlord_obj.run(self.module, self.method, self.method_args) + self.interactive = True + + self.server_spec = self.parentCommand.server_spec + self.getOverlord() + + results = self.overlord_obj.run(self.module, self.method, self.method_args) # TO DO: add multiplexer support # probably as a higher level module. diff --git a/func/overlord/cmd_modules/check.py b/func/overlord/cmd_modules/check.py index b360df6..93f5523 100644 --- a/func/overlord/cmd_modules/check.py +++ b/func/overlord/cmd_modules/check.py @@ -25,24 +25,22 @@ from func.minion import sub_process from func.config import read_config from certmaster.commonconfig import MinionConfig -# FIXME: don't hardcode this here -DEFAULT_PORT = 51234 -class CheckAction(client.command.Command): +class CheckAction(client.command.BaseCommand): name = "check" usage = "check func for possible setup problems" def addOptions(self): self.parser.add_option("-c", "--certmaster", action="store_true", help="check the certmaster configuration on this box") self.parser.add_option("-m", "--minion", action="store_true", help="check the minion configuration on this box") - + self.parser.add_option("-v", "--verbose", dest="verbose", action="store_true") def handleOptions(self, options): # FIXME: all through the code we have this constant in each # file, need to make this common. - self.port = DEFAULT_PORT self.check_certmaster = options.certmaster - self.check_minion = options.minion + self.check_minion = options.minion + self.verbose = options.verbose def do(self, args): @@ -79,18 +77,10 @@ class CheckAction(client.command.Command): # see if we have signed any certs # FIXME: TODO - # construct a client handle and see if any hosts are reachable self.server_spec = self.parentCommand.server_spec - - overlord_obj = client.Overlord( - self.server_spec, - port=self.port, - interactive=False, - verbose=False, - config=self.config - ) + self.getOverlord() - results = overlord_obj.test.add(1,2) + results = self.overlord_obj.test.add(1,2) hosts = results.keys() if len(hosts) == 0: print "* no systems have signed certs" diff --git a/func/overlord/cmd_modules/copyfile.py b/func/overlord/cmd_modules/copyfile.py index a149d5d..1371b6d 100644 --- a/func/overlord/cmd_modules/copyfile.py +++ b/func/overlord/cmd_modules/copyfile.py @@ -22,9 +22,8 @@ import xmlrpclib from func.overlord import command from func.overlord import client -DEFAULT_PORT = 51234 -class CopyFile(client.command.Command): +class CopyFile(client.command.BaseCommand): name = "copyfile" usage = "copy a file to a client" @@ -38,23 +37,13 @@ class CopyFile(client.command.Command): action="store_true") self.parser.add_option("-v", "--verbose", dest="verbose", action="store_true") - self.parser.add_option("-p", "--port", dest="port") def handleOptions(self, options): - self.port = DEFAULT_PORT - if self.options.port: - self.port = self.options.port - + self.verbose = self.options.verbose def do(self, args): - self.server_spec = self.parentCommand.server_spec - - overlord_obj = client.Overlord(self.server_spec, - port=self.port, - interactive=False, - verbose=self.options.verbose, - config=self.config) - + self.server_spec = self.parentClass.server_spec + self.getOverlord() try: fb = open(self.options.filename, "r").read() @@ -69,5 +58,5 @@ class CopyFile(client.command.Command): data = xmlrpclib.Binary(fb) - results = overlord_obj.run("copyfile", "copyfile", [self.options.remotepath, data, - mode, uid, gid]) + results = self.overlord_obj.run("copyfile", "copyfile", [self.options.remotepath, data, + mode, uid, gid]) diff --git a/func/overlord/cmd_modules/listminions.py b/func/overlord/cmd_modules/listminions.py index fbfc282..f5a62c8 100644 --- a/func/overlord/cmd_modules/listminions.py +++ b/func/overlord/cmd_modules/listminions.py @@ -19,9 +19,8 @@ import os from func.overlord import command from func.overlord import client -DEFAULT_PORT = 51234 -class ListMinions(client.command.Command): +class ListMinions(client.command.BaseCommand): name = "list_minions" usage = "show known minions" @@ -30,20 +29,16 @@ class ListMinions(client.command.Command): action="store_true") def handleOptions(self, options): - self.port = DEFAULT_PORT if options.verbose: self.verbose = self.options.verbose + def do(self, args): - self.server_spec = self.parentCommand.server_spec - overlord_obj = client.Overlord(self.server_spec, - port=self.port, - interactive=False, - verbose=self.options.verbose, - config=self.config) + self.server_spec = self.parentCommand.server_spec + self.getOverlord() - results = overlord_obj.test.add(1,2) + results = self.overlord_obj.test.add(1,2) servers = results.keys() servers.sort() diff --git a/func/overlord/cmd_modules/ping.py b/func/overlord/cmd_modules/ping.py index a94fa70..3a0e6ac 100644 --- a/func/overlord/cmd_modules/ping.py +++ b/func/overlord/cmd_modules/ping.py @@ -22,11 +22,8 @@ import xmlrpclib from func.overlord import command from func.overlord import client -# FIXME: this really should not be in each sub module. -DEFAULT_PORT = 51234 - -class Ping(client.command.Command): +class Ping(client.command.BaseCommand): name = "ping" usage = "see what func minions are up/accessible" @@ -37,14 +34,12 @@ class Ping(client.command.Command): # FIXME: verbose and port should be added globally to all sub modules 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): """ Nothing to do here... """ - pass + self.verbose = self.options.verbose def do(self, args): self.server_spec = self.parentCommand.server_spec @@ -52,15 +47,16 @@ class Ping(client.command.Command): # because this is mainly an interactive command, expand the server list and make seperate connections. # to make things look more speedy. - minion_set = client.Minions(self.server_spec, port=self.options.port) + minion_set = client.Minions(self.server_spec, port=self.port) servers = minion_set.get_all_hosts() for server in servers: - overlord_obj = client.Overlord(server,port=self.options.port, + overlord_obj = client.Overlord(server,port=self.port, interactive=False, - verbose=self.options.verbose, - config=self.config, noglobs=True) + verbose=self.verbose, + config=self.config, + noglobs=True) results = overlord_obj.run("test", "ping", []) print "results", results, type(results) diff --git a/func/overlord/cmd_modules/show.py b/func/overlord/cmd_modules/show.py index 8963082..5c4875f 100644 --- a/func/overlord/cmd_modules/show.py +++ b/func/overlord/cmd_modules/show.py @@ -20,10 +20,8 @@ import xmlrpclib from func.overlord import command from func.overlord import client -DEFAULT_PORT = 51234 - -class ShowHardware(client.command.Command): +class ShowHardware(client.command.BaseCommand): name = "hardware" usage = "show hardware details" @@ -32,14 +30,11 @@ class ShowHardware(client.command.Command): def addOptions(self): self.parser.add_option("-v", "--verbose", dest="verbose", action="store_true") - self.parser.add_option("-p", "--port", dest="port") - + def handleOptions(self, options): - self.port = DEFAULT_PORT - if self.options.port: - self.port = self.options.port - + pass + def parse(self, argv): self.argv = argv return command.Command.parse(self,argv) @@ -47,14 +42,9 @@ class ShowHardware(client.command.Command): def do(self,args): self.server_spec = self.parentCommand.parentCommand.server_spec + self.getOverlord() - overlord_obj = client.Overlord(self.server_spec, - port=self.port, - interactive=False, - verbose=self.options.verbose, - config=self.config) - - results = overlord_obj.run("hardware", "info", []) + results = self.overlord_obj.run("hardware", "info", []) # if the user top_options = ["port","verbose"] @@ -72,21 +62,18 @@ class ShowHardware(client.command.Command): print minion_data[arg] -class Show(client.command.Command): +class Show(client.command.BaseCommand): name = "show" usage = "various simple report stuff" subCommandClasses = [ShowHardware] 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 def parse(self, argv): diff --git a/func/overlord/command.py b/func/overlord/command.py index 7cf3623..0fd0c7a 100644 --- a/func/overlord/command.py +++ b/func/overlord/command.py @@ -15,6 +15,8 @@ import optparse import sys from func.config import read_config, CONFIG_FILE +from func.overlord import client + from certmaster.commonconfig import CMConfig class CommandHelpFormatter(optparse.IndentedHelpFormatter): @@ -252,6 +254,7 @@ class Command: self.stderr.write("Unknown command '%s'.\n" % command) return 1 + def outputHelp(self): """ Output help information. @@ -285,3 +288,24 @@ class Command: while c.parentCommand: c = c.parentCommand return c + +DEFAULT_PORT = 51234 +class BaseCommand(Command): + """ wrapper class for commands with some convience functions, namely + getOverlord() for getting a overlord client api handle""" + + interactive = False + verbose=0 + port=DEFAULT_PORT + def getOverlord(self): + if not getattr(self, "server_spec"): + self.server_spec = self.parentCommand.server_spec + + + self.overlord_obj = client.Overlord(self.server_spec, + port=self.port, + interactive=self.interactive, + verbose=self.verbose, + config=self.config) + + |