From 6ec401381b4b3e6facce5c9a749bc08b8c30f1a7 Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 18 Aug 2015 17:00:00 +0300 Subject: draft --- scripts/trex_console | 2 ++ 1 file changed, 2 insertions(+) create mode 100755 scripts/trex_console (limited to 'scripts') diff --git a/scripts/trex_console b/scripts/trex_console new file mode 100755 index 00000000..6a79d54a --- /dev/null +++ b/scripts/trex_console @@ -0,0 +1,2 @@ +#!/bin/bash +/usr/bin/python ../src/console/trex_console.py -- cgit 1.2.3-korg From 8384612b8493a4a896e91e3bb9d5d25689a87c12 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 20 Aug 2015 09:25:33 +0300 Subject: added args to the console --- scripts/trex-console | 2 ++ scripts/trex_console | 2 -- src/console/trex_console.py | 34 +++++++++++++++++++++++++++++++--- src/console/trex_rpc_client.py | 6 +++++- 4 files changed, 38 insertions(+), 6 deletions(-) create mode 100755 scripts/trex-console delete mode 100755 scripts/trex_console (limited to 'scripts') diff --git a/scripts/trex-console b/scripts/trex-console new file mode 100755 index 00000000..50e097e7 --- /dev/null +++ b/scripts/trex-console @@ -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 index 6a79d54a..00000000 --- a/scripts/trex_console +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -/usr/bin/python ../src/console/trex_console.py 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 -- cgit 1.2.3-korg From 84bb24ace632141dd5ece01d5f4985239014f660 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Sun, 23 Aug 2015 18:12:05 +0300 Subject: changed .gitignore files from idea editor files --- .gitignore | 3 +++ .../trex_control_plane/client/outer_packages.py | 30 ++++++++++++---------- 2 files changed, 20 insertions(+), 13 deletions(-) (limited to 'scripts') diff --git a/.gitignore b/.gitignore index 249f61b8..5b956fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -43,3 +43,6 @@ scripts/bp-sim-* ehthumbs.db Thumbs.db +# IDE/ Editors files # +###################### +.idea/ diff --git a/scripts/automation/trex_control_plane/client/outer_packages.py b/scripts/automation/trex_control_plane/client/outer_packages.py index a7c34e48..092cad2c 100755 --- a/scripts/automation/trex_control_plane/client/outer_packages.py +++ b/scripts/automation/trex_control_plane/client/outer_packages.py @@ -1,29 +1,33 @@ #!/router/bin/python -import sys,site -import platform,os +import sys +import site +import platform +import os -CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) + +CURRENT_PATH = os.path.dirname(os.path.realpath(__file__)) ROOT_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir)) # path to trex_control_plane directory -PATH_TO_PYTHON_LIB = os.path.abspath(os.path.join(ROOT_PATH, 'python_lib')) +PATH_TO_PYTHON_LIB = os.path.abspath(os.path.join(ROOT_PATH, 'python_lib')) CLIENT_MODULES = ['enum34-1.0.4', - # 'jsonrpclib-0.1.3', - 'jsonrpclib-pelix-0.2.5', - 'termstyle', - 'rpc_exceptions-0.1' - ] + 'jsonrpclib-pelix-0.2.5', + 'termstyle', + 'rpc_exceptions-0.1' + ] + -def import_client_modules (): +def import_client_modules(): sys.path.append(ROOT_PATH) import_module_list(CLIENT_MODULES) -def import_module_list (modules_list): + +def import_module_list(modules_list): assert(isinstance(modules_list, list)) for p in modules_list: - full_path = os.path.join(PATH_TO_PYTHON_LIB, p) - fix_path = os.path.normcase(full_path) #CURRENT_PATH+p) + full_path = os.path.join(PATH_TO_PYTHON_LIB, p) + fix_path = os.path.normcase(full_path) # (CURRENT_PATH+p) site.addsitedir(full_path) import_client_modules() -- cgit 1.2.3-korg