summaryrefslogtreecommitdiff
path: root/python/rvi_call.py
blob: 6fb8b55510b9e428e5697cf9ca8814f69a60d3d5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python

#
# Copyright (C) 2014, Jaguar Land Rover
#
# This program is licensed under the terms and conditions of the
# Mozilla Public License, version 2.0.  The full text of the 
# Mozilla Public License is at https://www.mozilla.org/MPL/2.0/
#
# 
# Simple RVI service caller
#  

import sys
from rvilib import RVI
import threading
import time
import getopt
def usage():
    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:9001"
    print "  service      Service to invoke in RVI."
    print "  key=val      Named arguments to provide to service."
    print
    print "Example: ./callrvi.py -n http://rvi1.nginfotpdx.net:9001 \\"
    print "                      jlr.com/vin/aaron/4711/test/ping \\"
    print "                      arg1=val1 arg2=val2"                    

    sys.exit(255)


# 
# Check that we have the correct arguments
#
opts, args= getopt.getopt(sys.argv[1:], "n:")


rvi_node = "http://localhost:9001"
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.
i = 0
service = args[0]
rvi_args = {}
for i in args[1:]:
    print i
    [k, v] = i.split('=')
    rvi_args[k] = v




#
# Setup an outbound JSON-RPC connection to the backend RVI node
# Service Edge.
#
rvi = RVI(rvi_node)

print "RVI Node:         ", rvi_node
print "Service:          ", service
print "args:             ", rvi_args

#
# Send the messge.
#
rvi.message(service, rvi_args)