diff options
author | imarom <imarom@cisco.com> | 2016-04-03 18:19:20 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-04-04 09:49:54 +0300 |
commit | 4eacb570cf24927de536d23671f50609f1a9ffa5 (patch) | |
tree | 83b8dcd86994c7668a054413d0ba0449a1cf2816 /scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py | |
parent | 0eb15b2e851b5f50669633678143c5a1d3a7d95b (diff) |
API classes (versions)
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py')
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py index 166fd64e..bd5ba8e7 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_jsonrpc_client.py @@ -26,9 +26,9 @@ class BatchMessage(object): self.rpc_client = rpc_client self.batch_list = [] - def add (self, method_name, params={}): + def add (self, method_name, params = None, api_class = 'core'): - id, msg = self.rpc_client.create_jsonrpc_v2(method_name, params, encode = False) + id, msg = self.rpc_client.create_jsonrpc_v2(method_name, params, api_class, encode = False) self.batch_list.append(msg) def invoke(self, block = False): @@ -46,8 +46,9 @@ class JsonRpcClient(object): MSG_COMPRESS_THRESHOLD = 4096 MSG_COMPRESS_HEADER_MAGIC = 0xABE85CEA - def __init__ (self, default_server, default_port, logger): - self.logger = logger + def __init__ (self, default_server, default_port, client): + self.client = client + self.logger = client.logger self.connected = False # default values @@ -93,14 +94,18 @@ class JsonRpcClient(object): def create_batch (self): return BatchMessage(self) - def create_jsonrpc_v2 (self, method_name, params = {}, encode = True): + def create_jsonrpc_v2 (self, method_name, params = None, api_class = 'core', encode = True): msg = {} msg["jsonrpc"] = "2.0" msg["method"] = method_name + msg["id"] = next(self.id_gen) - msg["params"] = params + msg["params"] = params if params is not None else {} - msg["id"] = next(self.id_gen) + # if this RPC has an API class - add it's handler + if api_class: + msg["params"]["api_h"] = self.client.api_h[api_class] + if encode: return id, json.dumps(msg) @@ -108,11 +113,11 @@ class JsonRpcClient(object): return id, msg - def invoke_rpc_method (self, method_name, params = {}): + def invoke_rpc_method (self, method_name, params = None, api_class = 'core'): if not self.connected: return RC_ERR("Not connected to server") - id, msg = self.create_jsonrpc_v2(method_name, params) + id, msg = self.create_jsonrpc_v2(method_name, params, api_class) return self.send_msg(msg) @@ -273,7 +278,7 @@ class JsonRpcClient(object): self.connected = True - rc = self.invoke_rpc_method('ping') + rc = self.invoke_rpc_method('ping', api_class = None) if not rc: self.connected = False return rc |