diff options
Diffstat (limited to 'src/console')
-rwxr-xr-x | src/console/trex_console.py | 27 | ||||
-rw-r--r-- | src/console/trex_rpc_client.py | 12 |
2 files changed, 30 insertions, 9 deletions
diff --git a/src/console/trex_console.py b/src/console/trex_console.py index be84640c..b4048f5b 100755 --- a/src/console/trex_console.py +++ b/src/console/trex_console.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- import cmd import json +import ast from trex_rpc_client import RpcClient import trex_status @@ -75,10 +76,32 @@ class TrexConsole(cmd.Cmd): def do_rpc (self, line): '''\nLaunches a RPC on the server\n''' if line == "": - print "\nUsage: [method name] [param 1] ...\n" + print "\nUsage: [method name] [param dict as string]\n" return - rc, msg = self.rpc_client.invoke_rpc_method(line) + sp = line.split(' ', 1) + method = sp[0] + + params = None + bad_parse = False + if len(sp) > 1: + + try: + params = ast.literal_eval(sp[1]) + if not isinstance(params, dict): + bad_parse = True + + except ValueError as e1: + bad_parse = True + except SyntaxError as e2: + bad_parse = True + + if bad_parse: + print "\nValue should be a valid dict: '{0}'".format(sp[1]) + print "\nUsage: [method name] [param dict as string]\n" + return + + rc, msg = self.rpc_client.invoke_rpc_method(method, params) if rc: print "[SUCCESS]\n" else: diff --git a/src/console/trex_rpc_client.py b/src/console/trex_rpc_client.py index f3edd252..3ec0e1f6 100644 --- a/src/console/trex_rpc_client.py +++ b/src/console/trex_rpc_client.py @@ -24,7 +24,7 @@ class RpcClient(): return rc
def pretty_json (self, json_str):
- return json.dumps(json.loads(json_str), indent = 4, separators=(',', ': '))
+ return json.dumps(json.loads(json_str), indent = 4, separators=(',', ': '), sort_keys = True)
def verbose_msg (self, msg):
if not self.verbose:
@@ -38,9 +38,7 @@ class RpcClient(): msg["jsonrpc"] = "2.0"
msg["method"] = method_name
- msg["params"] = {}
- for key, value in params.iteritems():
- msg["params"][key] = value
+ msg["params"] = params
msg["id"] = id
@@ -101,13 +99,13 @@ class RpcClient(): def ping_rpc_server (self):
- return self.invoke_rpc_method("rpc_ping", block = False)
+ return self.invoke_rpc_method("ping", block = False)
def get_rpc_server_status (self):
- return self.invoke_rpc_method("rpc_get_status")
+ return self.invoke_rpc_method("get_status")
def query_rpc_server (self):
- return self.invoke_rpc_method("rpc_get_reg_cmds")
+ return self.invoke_rpc_method("get_reg_cmds")
def set_verbose (self, mode):
|