From ffe60f97c1ec46aae1b62f0867b755095cf659ec Mon Sep 17 00:00:00 2001 From: Magnus Feuer Date: Fri, 10 Apr 2015 18:57:50 -0700 Subject: Temp --- python/rvi_call.py | 48 ++++++++++++++++++++++++---------------------- python/rvi_get_services.py | 10 +++++++--- python/rvi_service.py | 26 +++++++++++++++++++------ python/rvilib.py | 4 ++++ 4 files changed, 56 insertions(+), 32 deletions(-) (limited to 'python') diff --git a/python/rvi_call.py b/python/rvi_call.py index 9c8d1c2..efe54e6 100755 --- a/python/rvi_call.py +++ b/python/rvi_call.py @@ -15,10 +15,11 @@ import sys from rvilib import RVI import threading import time - +import getopt def usage(): - print "Usage:", sys.argv[0], " RVI-node service key=val ..." - print " RVI-node DNS name or IP of host running RVI" + print "Usage:", sys.argv[0], "[-n RVI-node] service key=val ..." + print " RVI-node DNS name or IP of host running RVI. " + print " default: http://localhost:8801" print " service Service to invoke in RVI." print " key=val Named arguments to provide to service." print @@ -32,21 +33,28 @@ def usage(): # # Check that we have the correct arguments # -if len(sys.argv) <3: - usage() +opts, args= getopt.getopt(sys.argv[1:], "n:") + -progname = sys.argv[0] -rvi_node = sys.argv[1] -service = sys.argv[2] -args = [] -i=3 +rvi_node = "http://localhost:8801" +for o, a in opts: + if o == "-n": + rvi_node = a + else: + usage() + +if len(args) < 1: + usage() # Construct a dictionary from the provided paths. -while i < len(sys.argv): - print sys.argv[i] - [k, v] = sys.argv[i].split('=') - args = args + [{ k: v}] - i = i + 1 +i = 0 +service = args[0] +rvi_args = [] +for i in args[1:]: + print i + [k, v] = i.split('=') + rvi_args = rvi_args + [{ k: v}] + @@ -56,17 +64,11 @@ while i < len(sys.argv): # rvi = RVI(rvi_node) - print "RVI Node: ", rvi_node print "Service: ", service -print "args: ", args +print "args: ", rvi_args # # Send the messge. # -rvi.message(service, args) - - - - - +rvi.message(service, rvi_args) diff --git a/python/rvi_get_services.py b/python/rvi_get_services.py index 70d32de..eeadcdc 100755 --- a/python/rvi_get_services.py +++ b/python/rvi_get_services.py @@ -20,7 +20,8 @@ def usage(): print "Return the name of all available services that can be reached" print "through an RVI node." print - print "Usage:", sys.argv[0], " RVI-node" + print "Usage:", sys.argv[0], " [RVI-node]" + print "Default RVI node is http://127.0.0.1:8801" print print "Example: ./callrvi.py http://rvi1.nginfotpdx.net:8801" print @@ -30,12 +31,15 @@ def usage(): # # Check that we have the correct arguments # -if len(sys.argv) <2: +if len(sys.argv) != 1 and len(sys.argv) != 2: usage() progname = sys.argv[0] -rvi_node = sys.argv[1] +if len(sys.argv) == 2: + rvi_node = sys.argv[1] +else: + rvi_node = "http://localhost:8801" # # Setup an outbound JSON-RPC connection to the backend RVI node diff --git a/python/rvi_service.py b/python/rvi_service.py index e1b705c..2c3271f 100755 --- a/python/rvi_service.py +++ b/python/rvi_service.py @@ -13,10 +13,12 @@ # import sys from rvilib import RVI +import getopt def usage(): - print "Usage:", sys.argv[0], " " - print " URL of Service Edge on a local RVI node" + print "Usage:", sys.argv[0], "[-n ] " + print " URL of Service Edge on a local RVI node." + print " Default: http://localhost:8801" print " URL of Service to register" print print "The RVI Service Edge URL can be found in" @@ -26,7 +28,7 @@ def usage(): print "The Service Edge URL is also logged as a notice when the" print "RVI node is started." print - print "Example: ./rvi_service.py http://rvi1.nginfotpdx.net:8801 /test/some_service" + print "Example: ./rvi_service.py /test/some_service http://rvi1.nginfotpdx.net:8801" sys.exit(255) @@ -68,11 +70,23 @@ def services_unavailable(**args): return ['ok'] -if len(sys.argv) != 3: +# +# Check that we have the correct arguments +# +opts, args= getopt.getopt(sys.argv[1:], "n:") + +rvi_node_url = "http://localhost:8801" +for o, a in opts: + if o == "-n": + rvi_node_url = a + else: + usage() + +if len(args) != 1: usage() -# Grab the URL to use -[ progname, rvi_node_url, service_name ] = sys.argv +service_name = args[0] + # Setup a connection to the local RVI node rvi = RVI(rvi_node_url) diff --git a/python/rvilib.py b/python/rvilib.py index f676298..647e333 100644 --- a/python/rvilib.py +++ b/python/rvilib.py @@ -73,6 +73,10 @@ class RVI(SimpleJSONRPCServer): # in an RVI network to access your service. # def register_service(self, service_name, function): + # Add a prefixing slash if necessary + if service_name[0] != '/': + service_name = '/' + service_name + # Register service_name within SimpleJSONRPCServer so that # when it gets invoked with the given URL suffic, it will call 'function'. # -- cgit v1.2.1