added args to the console
authorimarom <[email protected]>
Thu, 20 Aug 2015 06:25:33 +0000 (09:25 +0300)
committerimarom <[email protected]>
Thu, 20 Aug 2015 06:25:33 +0000 (09:25 +0300)
scripts/trex-console [new file with mode: 0755]
scripts/trex_console [deleted file]
src/console/trex_console.py
src/console/trex_rpc_client.py

diff --git a/scripts/trex-console b/scripts/trex-console
new file mode 100755 (executable)
index 0000000..50e097e
--- /dev/null
@@ -0,0 +1,2 @@
+#!/bin/bash
+../src/console/trex_console.py $@
diff --git a/scripts/trex_console b/scripts/trex_console
deleted file mode 100755 (executable)
index 6a79d54..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-#!/bin/bash
-/usr/bin/python ../src/console/trex_console.py
index 2175fb5..1cb8194 100755 (executable)
@@ -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:
index 2ce44af..77d5fe1 100644 (file)
@@ -143,7 +143,11 @@ class RpcClient():
         print "\nConnecting To RPC Server On {0}".format(self.transport)\r
 \r
         self.socket = self.context.socket(zmq.REQ)\r
-        self.socket.connect(self.transport)\r
+        try:\r
+            self.socket.connect(self.transport)\r
+        except zmq.error.ZMQError as e:\r
+            return False, "ZMQ Error: Bad server or port name: " + str(e)\r
+\r
 \r
         self.connected = True\r
 \r