summaryrefslogtreecommitdiffstats
path: root/overlord/client.py
diff options
context:
space:
mode:
authorAdrian Likins <alikins@redhat.com>2007-10-02 15:36:05 -0400
committerAdrian Likins <alikins@redhat.com>2007-10-02 15:36:05 -0400
commit6e3807081996f5bd82455612f91da66b5dd5f1fa (patch)
treedba8c0153e0d55a578d4f12bf947fc58afb5c3a7 /overlord/client.py
parentc010a077418aeb511cca251f7b2fe0375d00990d (diff)
downloadthird_party-func-6e3807081996f5bd82455612f91da66b5dd5f1fa.tar.gz
third_party-func-6e3807081996f5bd82455612f91da66b5dd5f1fa.tar.xz
third_party-func-6e3807081996f5bd82455612f91da66b5dd5f1fa.zip
add command.py from MOAP http://thomas.apestaart.org/moap/trac
convert client.py to use it Note this changes the current commandline to need a "call" subcommand to call an rpc method directly.
Diffstat (limited to 'overlord/client.py')
-rwxr-xr-xoverlord/client.py128
1 files changed, 52 insertions, 76 deletions
diff --git a/overlord/client.py b/overlord/client.py
index d6ccdc8..a82990c 100755
--- a/overlord/client.py
+++ b/overlord/client.py
@@ -24,6 +24,8 @@ from func.commonconfig import CMConfig
from func.config import read_config
import sslclient
+import command
+
# ===================================
# defaults
# TO DO: some of this may want to come from config later
@@ -60,6 +62,7 @@ class CommandAutomagic():
# ===================================
+
class Client():
def __init__(self, server_spec, port=DEFAULT_PORT, interactive=False,
@@ -217,102 +220,75 @@ class Client():
# ===================================================================
-class FuncCommandLine():
-
- def __init__(self,myname,args):
- """
- Constructor. Takes name of program + arguments.
- """
- self.myname = myname
- self.args = args
- self.verbose = 0
- self.server_spec = None
- self.port = DEFAULT_PORT
-
- # -----------------------------------------------
-
- def usage(self):
- """
- Returns usage string for command line users.
- """
- return FUNC_USAGE % self.myname
-
- # -----------------------------------------------
-
- def run(self):
- """
- Engages the command line.
- """
-
- rc = self.parse_command_line()
- if rc != 0:
- return rc
+class Call(command.Command):
+ name = "call"
+ useage = "call nodule method name arg1 arg2..."
- return self.run_command()
-
- # -----------------------------------------------
-
- def parse_command_line(self):
- """
- Parses the command line and loads up all the variables.
- """
+ 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)
- # parse options
- p = optparse.OptionParser()
- p.add_option("-v","--verbose",dest="verbose",action="store_true")
- p.add_option("-p","--port",dest="port",default=DEFAULT_PORT)
- (options, args) = p.parse_args(self.args)
+ def handleOptions(self, options):
+ self.options = options
- self.args = args
self.verbose = options.verbose
- self.port = options.port
- # self.help = options.help
+ self.port = options.port
+ # I'm not really a fan of the "module methodname" approach
+ # but we'll keep it for now -akl
- # provided for free:
- #
- #if self.help:
- # print self.usage()
- # return -411
+ def do(self, args):
- # process arguments
- # a good Klingon program does not have parameters
- # it has arguments, and it always wins them.
+ # I'm not really a fan of the "module methodname" approach
+ # but we'll keep it for now -akl
- if len(args) < 3:
- print self.usage()
- return -411
+ self.server_spec = args[0]
+ self.module = args[1]
+ self.method = args[2]
+ self.method_args = args[3:]
- self.server_spec = self.args[0]
- self.module = self.args[1]
- self.method = self.args[2]
- self.method_args = self.args[3:]
-
- return 0
-
- # -----------------------------------------------
-
- def run_command(self):
- """
- Runs the actual command.
- """
client = Client(self.server_spec,port=self.port,interactive=True,
- verbose=self.verbose)
+ verbose=self.verbose)
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")
+
+ def handleOptions(self, options):
+ if options.version:
+ #FIXME
+ print "version is NOT IMPLEMENTED YET"
+
if __name__ == "__main__":
# this is what /usr/bin/func will run
myname, argv = sys.argv[0], sys.argv[1:]
- cli = FuncCommandLine(myname,argv)
- rc = cli.run()
+ cli = FuncCommandLine()
+ rc = cli.do()
+ sys.exit(rc)
+# cli = FuncCommandLine(myname,argv)
+
+# rc = cli.run()
sys.exit(rc)