diff options
author | imarom <imarom@cisco.com> | 2015-08-20 09:25:33 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2015-08-20 09:25:33 +0300 |
commit | 8384612b8493a4a896e91e3bb9d5d25689a87c12 (patch) | |
tree | 9ea109d208eb2d4ab0632245107b5ab24faafd1b /src | |
parent | 479c4358ce64429a6d5e21b2bfeccd27da710701 (diff) |
added args to the console
Diffstat (limited to 'src')
-rwxr-xr-x | src/console/trex_console.py | 34 | ||||
-rw-r--r-- | src/console/trex_rpc_client.py | 6 |
2 files changed, 36 insertions, 4 deletions
diff --git a/src/console/trex_console.py b/src/console/trex_console.py index 2175fb5c..1cb8194d 100755 --- a/src/console/trex_console.py +++ b/src/console/trex_console.py @@ -1,8 +1,10 @@ -#!/usr/bin/python +#!/usr/bin/env python # -*- coding: utf-8 -*- import cmd import json import ast +import argparse +import sys from trex_rpc_client import RpcClient import trex_status @@ -78,7 +80,17 @@ class TrexConsole(cmd.Cmd): def do_connect (self, line): '''Connects to the server\n''' - rc, msg = self.rpc_client.connect() + + if line == "": + rc, msg = self.rpc_client.connect() + else: + sp = line.split() + if (len(sp) != 2): + print "\n[usage] connect [server] [port] or without parameters\n" + return + + rc, msg = self.rpc_client.connect(sp[0], sp[1]) + if rc: print "[SUCCESS]\n" else: @@ -207,9 +219,25 @@ class TrexConsole(cmd.Cmd): # aliasing do_exit = do_EOF = do_q = do_quit +def setParserOptions (): + parser = argparse.ArgumentParser(prog="trex_console.py") + + parser.add_argument("-s", "--server", help = "T-Rex Server [default is localhost]", + default = "localhost", + type = str) + + parser.add_argument("-p", "--port", help = "T-Rex Server Port [default is 5050]\n", + default = 5050, + type = int) + + return parser + def main (): + parser = setParserOptions() + options = parser.parse_args(sys.argv[1:]) + # RPC client - rpc_client = RpcClient("localhost", 5050) + rpc_client = RpcClient(options.server, options.port) # console try: diff --git a/src/console/trex_rpc_client.py b/src/console/trex_rpc_client.py index 2ce44afb..77d5fe1c 100644 --- a/src/console/trex_rpc_client.py +++ b/src/console/trex_rpc_client.py @@ -143,7 +143,11 @@ class RpcClient(): print "\nConnecting To RPC Server On {0}".format(self.transport)
self.socket = self.context.socket(zmq.REQ)
- self.socket.connect(self.transport)
+ try:
+ self.socket.connect(self.transport)
+ except zmq.error.ZMQError as e:
+ return False, "ZMQ Error: Bad server or port name: " + str(e)
+
self.connected = True
|