diff options
author | 2016-04-13 12:40:21 +0300 | |
---|---|---|
committer | 2016-04-13 12:40:21 +0300 | |
commit | 8076b8111991a790886537a5c1d7b54a01f479e4 (patch) | |
tree | d3615814b3a62a4e19d64fd9cf1269c36ba62ed0 /scripts/automation/trex_control_plane/stl/console | |
parent | 1f450703d3a51ed454af26aa494a7c6e2579686d (diff) | |
parent | 0b39ec305e80999c7dbe36d4b0d3850b04709571 (diff) |
Merge v2.0
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/console')
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/console/trex_console.py | 93 |
1 files changed, 56 insertions, 37 deletions
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py index aade572f..a095541e 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -47,7 +47,7 @@ except: from functools import wraps -__version__ = "1.1" +__version__ = "2.0" # console custom logger class ConsoleLogger(LoggerApi): @@ -267,17 +267,19 @@ class TRexConsole(TRexGeneralCmd): if not self.stateless_client.is_connected(): self.prompt = "trex(offline)>" self.supported_rpc = None - return stop - if self.stateless_client.is_all_ports_acquired(): + elif not self.stateless_client.get_acquired_ports(): self.prompt = "trex(read-only)>" - return stop + elif self.stateless_client.is_all_ports_acquired(): + self.prompt = "trex>" - self.prompt = "trex>" + else: + self.prompt = "trex {0}>".format(self.stateless_client.get_acquired_ports()) return stop + def default(self, line): print("'{0}' is an unrecognized command. type 'help' or '?' for a list\n".format(line)) @@ -416,17 +418,35 @@ class TRexConsole(TRexGeneralCmd): ############### connect def do_connect (self, line): - '''Connects to the server\n''' + '''Connects to the server and acquire ports\n''' self.stateless_client.connect_line(line) + def help_connect (self): + self.do_connect("-h") def do_disconnect (self, line): '''Disconnect from the server\n''' self.stateless_client.disconnect_line(line) + + def do_acquire (self, line): + '''Acquire ports\n''' + + self.stateless_client.acquire_line(line) + def help_acquire (self): + self.do_acquire("-h") + + def do_release (self, line): + '''Release ports\n''' + + self.stateless_client.release_line(line) + + def help_release (self): + self.do_release("-h") + ############### start def complete_start(self, text, line, begidx, endidx): @@ -538,28 +558,7 @@ class TRexConsole(TRexGeneralCmd): def do_events (self, line): '''shows events recieved from server\n''' - - x = parsing_opts.ArgumentPack(['-c','--clear'], - {'action' : "store_true", - 'default': False, - 'help': "clear the events log"}) - - parser = parsing_opts.gen_parser(self, - "events", - self.do_events.__doc__, - x) - - opts = parser.parse_args(line.split()) - if opts is None: - return - - events = self.stateless_client.get_events() - for ev in events: - print(ev) - - if opts.clear: - self.stateless_client.clear_events() - print(format_text("\n\nEvent log was cleared\n\n")) + return self.stateless_client.get_events_line(line) def complete_profile(self, text, line, begidx, endidx): @@ -591,9 +590,10 @@ class TRexConsole(TRexGeneralCmd): info = self.stateless_client.get_connection_info() exe = './trex-console --top -t -q -s {0} -p {1} --async_port {2}'.format(info['server'], info['sync_port'], info['async_port']) - cmd = ['/usr/bin/xterm', '-geometry', '111x47', '-sl', '0', '-title', 'trex_tui', '-e', exe] + cmd = ['/usr/bin/xterm', '-geometry', '111x48', '-sl', '0', '-title', 'trex_tui', '-e', exe] - self.terminal = subprocess.Popen(cmd) + # detach child + self.terminal = subprocess.Popen(cmd, preexec_fn = os.setpgrp) return @@ -750,9 +750,24 @@ def setParserOptions(): default = False) - parser.add_argument("--no_acquire", dest="acquire", - action="store_false", help="Acquire all ports on connect. Default is: ON.", - default = True) + group = parser.add_mutually_exclusive_group() + + group.add_argument("-a", "--acquire", dest="acquire", + nargs = '+', + type = int, + help="Acquire ports on connect. default is all available ports", + default = None) + + group.add_argument("-r", "--readonly", dest="readonly", + action="store_true", + help="Starts console in a read only mode", + default = False) + + + parser.add_argument("-f", "--force", dest="force", + action="store_true", + help="Force acquire the requested ports", + default = False) parser.add_argument("--batch", dest="batch", nargs = 1, @@ -815,15 +830,19 @@ def main(): logger.log("Log:\n" + format_text(e.brief() + "\n", 'bold')) return - if not options.tui and options.acquire: + if not options.tui and not options.readonly: try: # acquire all ports - stateless_client.acquire() + stateless_client.acquire(options.acquire, force = options.force) except STLError as e: logger.log("Log:\n" + format_text(e.brief() + "\n", 'bold')) - logger.log(format_text("\nSwitching to read only mode - only few commands will be available", 'bold')) + + logger.log("\n*** Failed to acquire all required ports ***\n") + return + + if options.readonly: + logger.log(format_text("\nRead only mode - only few commands will be available", 'bold')) - # a script mode if options.batch: cont = run_script_file(options.batch[0], stateless_client) |